Skip to content
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
Merged

Conversation

edoput
Copy link
Contributor

@edoput 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
Copy link

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
Copy link

Coverage Status

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

@edoput
Copy link
Contributor Author

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
Copy link

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)
Copy link

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?

Copy link
Contributor Author

@edoput edoput May 31, 2018

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,

Copy link

@redhog redhog May 31, 2018

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")

Copy link
Contributor Author

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 👍

@edoput
Copy link
Contributor Author

edoput commented Jun 1, 2018

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

Copy link

@redhog redhog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)

@edoput edoput changed the title WIP: query backends from installed packages query backends from installed packages Jun 1, 2018
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
Copy link
Member

@nemesifier nemesifier left a 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!

@nemesifier nemesifier merged commit ec56134 into openwisp:master Jun 11, 2018
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
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants