-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
query backends from installed packages #106
Conversation
This is an example backend as an external package that when installed along with netjsonconfig will let the user choose the |
I greatly support this patch as it's The Right Way To Do it :P Please merge :) |
netjsonconfig/__init__.py
Outdated
try: | ||
default.update({entry_point.name.lower(): entry_point.load()}) | ||
except ImportError as e: | ||
print("Error loading backend {}".format(entry_point.name.lower()), file=sys.stderr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this rather use the python logging framework?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the grand scheme of integrating with openwisp-contoller it should use whatever openwisp-config is using? I don't really know what is the correct way to log this but I didn't want crash to propagate to netjsonconfig when loading. Moreover loggin requires to choose a target (console, file, syslog, ...) and a level and I'm not sure which should they be,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
django-netjsonconfig/utils.py:9 uses
import logging
logger = logging.getLogger(__name__)
logger.warning("Grrrrrr")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll change this to be a logger on the console 👍
Let me know if there's anything else to do or I'll squash everything before merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :)
this will use the entry_points feature of pkg_resources to query other installed packages for additional backends. - [doc] added page create_your_backend - prevent import errors from crashing the cli during load the module will be imported but if an ImportError is raised the cli crash. This will prevent the cli from crashing but will not expose the backend to the user. An error message will be logger to console - exclude except form from flake qa this form is the only one compatible between python2 and python3 but flake is also worried about the e variable which is not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edoput great job 👍, thank you!
Hi all,
this will solve a problem that I had last summer during GSOC. Using
entry_points
in the definitionof
setup.py
we can query possible backends for use in netjsonconfig in other packages instead of having long-lived branches.This is an example for a
setup.py
using theentry_points
directive