|
32 | 32 | PATH = os.path.dirname(__file__) |
33 | 33 | MODULES = pkgutil.iter_modules(path=[PATH]) |
34 | 34 |
|
35 | | -# These structures make using the code lighter on the utilisation side |
36 | | -# devs can get the data they want using getattr without having to construct |
37 | | -# there own structures. This is at least true for basic lists and dicts. |
38 | | -APPDATA = {} |
39 | 35 | EXECLIST = [] |
40 | | -DEFMODULES = {} |
41 | | -EXECFLAGS = {} |
| 36 | +PLUGINEXECS = {} |
42 | 37 |
|
43 | | -# Optional param for if the modules are named in a different way to simply |
44 | | -# that the modules are called the same as the software (rare). |
45 | | -MODULEOVERIDES = {} |
46 | 38 | # Loop through all the modules in the plugin. |
47 | 39 | for loader, modulename, ispkg in MODULES: |
48 | 40 |
|
49 | | - # check for double loading in the namespace. |
| 41 | + # Check for double loading in the namespace. |
50 | 42 | if modulename not in sys.modules: |
51 | | - # try to import using the pip package path. |
| 43 | + |
| 44 | + # Try to import from the site-packages path. |
52 | 45 | try: |
53 | | - mod = __import__( |
54 | | - "Longbow.plugins.apps." + modulename, fromlist=[""]) |
| 46 | + |
| 47 | + mod = __import__("Longbow.plugins.apps." + modulename, |
| 48 | + fromlist=[""]) |
55 | 49 |
|
56 | 50 | except ImportError: |
57 | | - # Else try to import using the non packaged path. |
| 51 | + |
| 52 | + # Else try to import from a directory installed path. |
58 | 53 | try: |
59 | | - mod = __import__( |
60 | | - "plugins.apps." + modulename, fromlist=[""]) |
| 54 | + mod = __import__("plugins.apps." + modulename, |
| 55 | + fromlist=[""]) |
| 56 | + |
61 | 57 | except ImportError: |
| 58 | + |
62 | 59 | # Otherwise we've had it! Raise exception. |
63 | 60 | raise |
64 | 61 |
|
65 | 62 | # Now try and pull in attributes. |
66 | 63 | try: |
67 | | - APPDATA[modulename] = getattr(mod, "EXECDATA") |
68 | 64 |
|
69 | | - except AttributeError: |
70 | | - raise |
| 65 | + for executable, _ in getattr(mod, "EXECDATA").items(): |
71 | 66 |
|
72 | | - try: |
73 | | - MODULEOVERIDES[modulename] = getattr(mod, "MODULEOVERIDE") |
| 67 | + # Compile a list of executables across all plugins. |
| 68 | + EXECLIST.append(executable) |
| 69 | + |
| 70 | + # Compile a dictionary associating executable with plugins. |
| 71 | + PLUGINEXECS[executable] = modulename |
74 | 72 |
|
75 | 73 | except AttributeError: |
76 | | - MODULEOVERIDES[modulename] = "" |
77 | | - |
78 | | -# Construct common structures to make programmers lives easier. |
79 | | -for plugin in APPDATA: |
80 | | - for executable, flags in APPDATA[plugin].items(): |
81 | | - # compile a list of executables. |
82 | | - EXECLIST.append(executable) |
83 | | - |
84 | | - # compile dictionary of required input flags. |
85 | | - EXECFLAGS[executable] = flags |
86 | | - |
87 | | - # Compile a list of default modules. |
88 | | - if MODULEOVERIDES[plugin] == "": |
89 | | - DEFMODULES[executable] = plugin |
90 | | - else: |
91 | | - DEFMODULES[executable] = MODULEOVERIDES[plugin] |
| 74 | + |
| 75 | + raise |
0 commit comments