mirror of
				https://github.com/craigerl/aprsd.git
				synced 2025-11-03 21:20:23 -05:00 
			
		
		
		
	Reworked Plugin loading
This patch reworked the loading of plugins. Python2 is dead. Previously was using the imp module to easily load the plugins from a separate directory, which is a bit of a pita. Found a python3 lib that takes care of the difference between py3.3, 3.4 and 3.5+ module loading called "thesmuggler"
This commit is contained in:
		
							parent
							
								
									3ffa4165f0
								
							
						
					
					
						commit
						1385f5ee27
					
				@ -1,7 +1,6 @@
 | 
			
		||||
# The base plugin class
 | 
			
		||||
import abc
 | 
			
		||||
import fnmatch
 | 
			
		||||
import imp
 | 
			
		||||
import inspect
 | 
			
		||||
import json
 | 
			
		||||
import logging
 | 
			
		||||
@ -13,6 +12,7 @@ import time
 | 
			
		||||
import pluggy
 | 
			
		||||
import requests
 | 
			
		||||
import six
 | 
			
		||||
from thesmuggler import smuggle
 | 
			
		||||
 | 
			
		||||
from aprsd.fuzzyclock import fuzzy
 | 
			
		||||
 | 
			
		||||
@ -106,16 +106,10 @@ class PluginManager(object):
 | 
			
		||||
        for path, subdirs, files in os.walk(dir_path):
 | 
			
		||||
            for name in files:
 | 
			
		||||
                if fnmatch.fnmatch(name, pattern):
 | 
			
		||||
                    found_module = imp.find_module(name[:-3], [path])
 | 
			
		||||
                    module = imp.load_module(
 | 
			
		||||
                        name, found_module[0], found_module[1], found_module[2]
 | 
			
		||||
                    )
 | 
			
		||||
                    LOG.debug("MODULE? '{}' '{}'".format(name, path))
 | 
			
		||||
                    module = smuggle("{}/{}".format(path, name))
 | 
			
		||||
                    for mem_name, obj in inspect.getmembers(module):
 | 
			
		||||
                        if (
 | 
			
		||||
                            inspect.isclass(obj)
 | 
			
		||||
                            and inspect.getmodule(obj) is module
 | 
			
		||||
                            and self.is_plugin(obj)
 | 
			
		||||
                        ):
 | 
			
		||||
                        if inspect.isclass(obj) and self.is_plugin(obj):
 | 
			
		||||
                            self.obj_list.append(
 | 
			
		||||
                                {"name": mem_name, "obj": obj(self.config)}
 | 
			
		||||
                            )
 | 
			
		||||
 | 
			
		||||
@ -7,3 +7,4 @@ pep8-naming
 | 
			
		||||
black
 | 
			
		||||
isort
 | 
			
		||||
Sphinx
 | 
			
		||||
thesmuggler
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ babel==2.9.0              # via sphinx
 | 
			
		||||
black==20.8b1             # via -r dev-requirements.in
 | 
			
		||||
certifi==2020.12.5        # via requests
 | 
			
		||||
chardet==3.0.4            # via requests
 | 
			
		||||
click==7.1.2              # via black
 | 
			
		||||
coverage==5.3             # via pytest-cov
 | 
			
		||||
distlib==0.3.1            # via virtualenv
 | 
			
		||||
docutils==0.16            # via sphinx
 | 
			
		||||
@ -26,17 +27,17 @@ markupsafe==1.1.1         # via jinja2
 | 
			
		||||
mccabe==0.6.1             # via flake8
 | 
			
		||||
mypy-extensions==0.4.3    # via black, mypy
 | 
			
		||||
mypy==0.790               # via -r dev-requirements.in
 | 
			
		||||
packaging==20.7           # via pytest, sphinx, tox
 | 
			
		||||
packaging==20.8           # via pytest, sphinx, tox
 | 
			
		||||
pathspec==0.8.1           # via black
 | 
			
		||||
pep8-naming==0.11.1       # via -r dev-requirements.in
 | 
			
		||||
pluggy==0.13.1            # via pytest, tox
 | 
			
		||||
py==1.9.0                 # via pytest, tox
 | 
			
		||||
py==1.10.0                # via pytest, tox
 | 
			
		||||
pycodestyle==2.6.0        # via flake8
 | 
			
		||||
pyflakes==2.2.0           # via flake8
 | 
			
		||||
pygments==2.7.3           # via sphinx
 | 
			
		||||
pyparsing==2.4.7          # via packaging
 | 
			
		||||
pytest-cov==2.10.1        # via -r dev-requirements.in
 | 
			
		||||
pytest==6.1.2             # via -r dev-requirements.in, pytest-cov
 | 
			
		||||
pytest==6.2.0             # via -r dev-requirements.in, pytest-cov
 | 
			
		||||
pytz==2020.4              # via babel
 | 
			
		||||
regex==2020.11.13         # via black
 | 
			
		||||
requests==2.25.0          # via sphinx
 | 
			
		||||
@ -49,6 +50,7 @@ sphinxcontrib-htmlhelp==1.0.3  # via sphinx
 | 
			
		||||
sphinxcontrib-jsmath==1.0.1  # via sphinx
 | 
			
		||||
sphinxcontrib-qthelp==1.0.3  # via sphinx
 | 
			
		||||
sphinxcontrib-serializinghtml==1.1.4  # via sphinx
 | 
			
		||||
thesmuggler==1.0.1        # via -r dev-requirements.in
 | 
			
		||||
toml==0.10.2              # via black, pytest, tox
 | 
			
		||||
tox==3.20.1               # via -r dev-requirements.in
 | 
			
		||||
typed-ast==1.4.1          # via black, mypy
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								requirements.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								requirements.in
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
click
 | 
			
		||||
click-completion
 | 
			
		||||
imapclient
 | 
			
		||||
pluggy
 | 
			
		||||
pbr
 | 
			
		||||
pyyaml
 | 
			
		||||
six
 | 
			
		||||
requests
 | 
			
		||||
thesmuggler
 | 
			
		||||
@ -1,8 +1,22 @@
 | 
			
		||||
click
 | 
			
		||||
click-completion
 | 
			
		||||
imapclient
 | 
			
		||||
pluggy
 | 
			
		||||
pbr
 | 
			
		||||
pyyaml
 | 
			
		||||
six
 | 
			
		||||
requests
 | 
			
		||||
#
 | 
			
		||||
# This file is autogenerated by pip-compile
 | 
			
		||||
# To update, run:
 | 
			
		||||
#
 | 
			
		||||
#    pip-compile
 | 
			
		||||
#
 | 
			
		||||
certifi==2020.12.5        # via requests
 | 
			
		||||
chardet==3.0.4            # via requests
 | 
			
		||||
click-completion==0.5.2   # via -r requirements.in
 | 
			
		||||
click==7.1.2              # via -r requirements.in, click-completion
 | 
			
		||||
idna==2.10                # via requests
 | 
			
		||||
imapclient==2.1.0         # via -r requirements.in
 | 
			
		||||
jinja2==2.11.2            # via click-completion
 | 
			
		||||
markupsafe==1.1.1         # via jinja2
 | 
			
		||||
pbr==5.5.1                # via -r requirements.in
 | 
			
		||||
pluggy==0.13.1            # via -r requirements.in
 | 
			
		||||
pyyaml==5.3.1             # via -r requirements.in
 | 
			
		||||
requests==2.25.0          # via -r requirements.in
 | 
			
		||||
shellingham==1.3.2        # via click-completion
 | 
			
		||||
six==1.15.0               # via -r requirements.in, click-completion, imapclient
 | 
			
		||||
thesmuggler==1.0.1        # via -r requirements.in
 | 
			
		||||
urllib3==1.26.2           # via requests
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user