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

Merged
merged 1 commit into from Jun 11, 2018

Conversation

4 participants
@edoput
Member

edoput commented May 18, 2018

Hi all,

this will solve a problem that I had last summer during GSOC. Using entry_points in the definition
of 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 the entry_points directive

from setuptools import setup, find_packages                                                                                                           
                                                                                                                                                      
setup(                                                                                                                                                
    name='airos',                                                                                                                                  
    version='0.0.0',                                                                                                                                  
    description='AirOS backend for netjsonconfig',                                                                                                                          
    packages=find_packages(),                                                                                                                         
    entry_points={                                                                                                                                    
        'netjsonconfig.backends': [                                                                                                                   
            'airos=netjsonconfig-airos.backend:AirOsBackend',                                                                                                    
        ]                                                                                                                                             
    }                                                                                                                                                 
) 
@coveralls

This comment has been minimized.

coveralls commented May 21, 2018

Coverage Status

Coverage remained the same at 99.931% when pulling 2bf557c on edoput:master into 11cfed1 on openwisp:master.

@coveralls

This comment has been minimized.

coveralls commented May 21, 2018

Coverage Status

Coverage remained the same at 99.931% when pulling 1511fc1 on edoput:master into 11cfed1 on openwisp:master.

@edoput

This comment has been minimized.

Member

edoput commented May 22, 2018

This is an example backend as an external package that when installed along with netjsonconfig will let the user choose the example backend directly when using netjsonconfig

@redhog

This comment has been minimized.

redhog commented May 23, 2018

I greatly support this patch as it's The Right Way To Do it :P Please merge :)

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)

This comment has been minimized.

@redhog

redhog May 31, 2018

Shouldn't this rather use the python logging framework?

This comment has been minimized.

@edoput

edoput May 31, 2018

Member

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,

This comment has been minimized.

@redhog

redhog May 31, 2018

django-netjsonconfig/utils.py:9 uses

import logging
logger = logging.getLogger(__name__)
logger.warning("Grrrrrr")

This comment has been minimized.

@edoput

edoput May 31, 2018

Member

Ok I'll change this to be a logger on the console 👍

@edoput

This comment has been minimized.

Member

edoput commented Jun 1, 2018

Let me know if there's anything else to do or I'll squash everything before merge

@redhog

redhog approved these changes Jun 1, 2018

Looks good :)

@edoput edoput force-pushed the edoput:master branch from 69552c5 to ecfb31c Jun 1, 2018

@edoput edoput changed the title from WIP: query backends from installed packages to query backends from installed packages Jun 1, 2018

@edoput edoput force-pushed the edoput:master branch from 46b67a0 to ded88d2 Jun 10, 2018

added external backend querying at runtime
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

@edoput edoput force-pushed the edoput:master branch from ded88d2 to 2bf557c Jun 10, 2018

@nemesisdesign nemesisdesign added this to To do (general) in OpenWISP Contributor's Board via automation Jun 11, 2018

@nemesisdesign

@edoput great job 👍, thank you!

@nemesisdesign nemesisdesign merged commit ec56134 into openwisp:master Jun 11, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 99.931%
Details

OpenWISP Contributor's Board automation moved this from To do (general) to Done Jun 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment