-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't raise exception when one of the registered processes cannot be …
…imported (#226)
- Loading branch information
Showing
3 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
import pkg_resources | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def registered_processes(process_name=None): | ||
""" | ||
Return registered process modules. | ||
Parameters | ||
---------- | ||
process_name : str | ||
Python path of process. | ||
Returns | ||
------- | ||
module | ||
""" | ||
def _import(): | ||
# get all registered processes by name | ||
processes = list(pkg_resources.iter_entry_points("mapchete.processes")) | ||
# try to load processes | ||
for v in processes: | ||
logger.debug("try to load %s", v) | ||
try: | ||
loaded = v.load() | ||
if process_name is None or process_name == loaded.__name__: | ||
yield loaded | ||
except Exception as e: | ||
logger.warning("%s could not be imported: %s", str(v), str(e)) | ||
|
||
# sort processes alphabetically | ||
imported = list(_import()) | ||
imported.sort(key=lambda x: x.__name__) | ||
logger.debug("%s processes found", len(imported)) | ||
return imported | ||
|
||
|
||
def process_names_docstrings(process_name): | ||
""" | ||
Return registered process module names and docstrings. | ||
Parameters | ||
---------- | ||
process_name : str | ||
Python path of process | ||
Returns | ||
------- | ||
list of tuples | ||
tuples contain containing process name and process docstring | ||
""" | ||
return [ | ||
(process.__name__, process.execute.__doc__) | ||
for process in registered_processes(process_name=process_name) | ||
] |