2019-03-07, 00:50
This is mostly in the idea stage, and I want to hear thoughts on it from people more experienced in Python, programming, etc.
kodi-plugin-routing is a thing, and I use it. It was made for plugins only, though, and can only be used within the plugin that called it.
Unfortunately, when you get complex systems that have custom context menus, UI, and services to hold persistent data, you will quickly run into a mess of circular dependency. You have
My thought is this:
An addon that can build nice routing urls for addons to call each other, without the extra stuff like the need to import functions and create the object from inside the addon it was made for.
The nice thing about python, and specifically Kodi's python, is that code is transparent. You can read and build a map of other addons' functions and module structures at runtime, without the need to actually run any of their code first, thereby avoiding the dependency issues that arise.
In other languages, this concept is basically dynamically building an interface api class at runtime. It is prone to errors with versions, and therefore should not be used with addons not made by you.
In a better option, you use a decorator, and that identifies the route. When parsing, you use reflection to find the decorator and read the route.
In the worst case situation for parsing, python is whitespace-aware. You can iterate levels of indentation and build a a map of
This concept would allow you to simply put an init call at the top telling the routing addon what addon to look at, then the routing addon pulls the path from kodi, reads the entry point from the addon's info, and checks the file for routing info. From there, you would use
Regardless, I'll be making a version of kodi-plugin-routing that can be run from a script, so you could call
EDIT: After more thought, I figure it would be best to have a global mapping of the functions, then any addon can
Thoughts?
kodi-plugin-routing is a thing, and I use it. It was made for plugins only, though, and can only be used within the plugin that called it.
Unfortunately, when you get complex systems that have custom context menus, UI, and services to hold persistent data, you will quickly run into a mess of circular dependency. You have
something_plugin
that provides a list of items, but those items need to call a script at some point to properly follow team-kodi's advice on plugin vs script usage. You can't say something_plugin
depends on something_script
, then in something_script
say it depends on something_plugin
. They need to call to each other depending on the situation, but it gets really messy.My thought is this:
An addon that can build nice routing urls for addons to call each other, without the extra stuff like the need to import functions and create the object from inside the addon it was made for.
The nice thing about python, and specifically Kodi's python, is that code is transparent. You can read and build a map of other addons' functions and module structures at runtime, without the need to actually run any of their code first, thereby avoiding the dependency issues that arise.
In other languages, this concept is basically dynamically building an interface api class at runtime. It is prone to errors with versions, and therefore should not be used with addons not made by you.
In a better option, you use a decorator, and that identifies the route. When parsing, you use reflection to find the decorator and read the route.
In the worst case situation for parsing, python is whitespace-aware. You can iterate levels of indentation and build a a map of
class
and def
to the @route
. It's dirty, but it works without giving python a chance to barf on dependencies, so it would work even if the code itself errors out.This concept would allow you to simply put an init call at the top telling the routing addon what addon to look at, then the routing addon pulls the path from kodi, reads the entry point from the addon's info, and checks the file for routing info. From there, you would use
and it would translate that into the required URL for you. In the best case, you could somehow hint the func_name, but I don't think it's possible to give an in-code reference to a function without creating an import dependency in python.python:routing.call_script('func_name', *args)
Regardless, I'll be making a version of kodi-plugin-routing that can be run from a script, so you could call
python:xbmc.executebuiltin('RunScript(script://script.module.something_script,play_video/%s)' % str(video_id), wait=False)
EDIT: After more thought, I figure it would be best to have a global mapping of the functions, then any addon can
import addon_routing
and just call the route by name. There would be no need for touching the functions of other addons. The only problem is services that might init before addon_routing can, then try to call an addon that hasn't been registered. It could check to see if the addon being called is in the list, then populate the routing info on demand if not, but that can give undesirable first runs. idk. If the addons give a name (even if it's just function.__name__), then it would work in case the code changes, as long as things aren't redesigned.Thoughts?