-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[backends] Add a way to easily extend Backends #112
Comments
A simple solution would be to extend converters as we did wiht the backend class # myconverter/__init__.py
from netjsonconfig import BaseConverter
class MyConverter(BaseConverter):
...
# setup.py
...
setup(
name='my_converter',
...,
entry_points={
'netjsonconfig.openwrt.converter': [
'my_converter=my_converter.__init__:MyConverter',
]
},
...,
) With this approach we could have a backend probe for converters at runtime. I can propose a patch somewhere in the next two week if needed otherwise I'm here to help |
Another problem is that we would have to merge their json schema with the backend one; this may be a problem we previously encountered. Otherwise we could push the schema validation to converters instead |
@edoput not everyone that wants to slightly extend from netjsonconfig import OpenWrt
from .mycoolproject import MyCoolRenderer, schema
OpenWrt.add(renderers=[MyCoolRenderer],
schema=schema) Or maybe we could even allow renderers to declare a schema which could be automatically merged by This would be very interesting because it would also allow us to have some additional renderers that are used often enough to be published in the main repo and documented in our official docs but not so much to be activated by default, so we may provide clear documentation on how to activate these and we may even enable That way we can provide some additional default renderers for things like DDNS (#111), OLSRd, OLSRd2, Bmx7, etc.. Do you start seeing the possibilities I see? |
this is not true. making a python package is as simple as adding a
I'm not against extending the library but logic here is the wrong word. logic implies that there is control (inside netjsonconfig) on what gets loaded but in a library this is unfortunately bad thing, when Maybe we need another layer between netjsonconfig and django but this may be too much work
this is not nice, it implies that now I have to track the new backend instance or that netjsonconfig store b = OpenWrt(...)
b.converters.append(MyConverter)
b.render()
I support the idea to split the schema in smaller modules but again we should fix schema merging before
python packages namespace are what you would use to solve this problem, we can declare the namespace netjsonconfig and make additional packages declare they are part of a namespace.
yeah but the burden of deciding which extensions should be loaded should be placed in the openwisp django settings file. I figure that an |
A very common scenario to create a custom backend is to add support for a new OpenWRT package.
Contributors may then want to include this package in the main code, but we cannot add all of these to the master branch for several reasons: negatively affecting performance in the OpenWISP web UI (schemas are loaded with HTTP requests and rendered with javascript, the more complex a schema is the more time it will be needed to download it and render the UI for it), increasing complexity.
We should start thinking about a way to dynamically and declaratively extend a backend so that a new package can be supported, or something along these lines.
The text was updated successfully, but these errors were encountered: