-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from usepy.plugin import useLogger | ||
|
||
useLogger(packages=["scrapy", "django", "usepy"]) |
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,30 @@ | ||
import functools | ||
import importlib | ||
import os | ||
import sys | ||
from glob import glob | ||
|
||
|
||
def find_plugin_modules(): | ||
plugins = [] | ||
for module in sys.path: | ||
path = os.path.join(os.path.dirname(__file__), module) | ||
for file in glob(os.path.join(path, 'usepy_plugin_*')): | ||
path_name = os.path.basename(file) | ||
try: | ||
plugins.append(importlib.import_module(path_name)) | ||
except ModuleNotFoundError: | ||
pass | ||
return plugins | ||
|
||
|
||
plugin_modules = find_plugin_modules() | ||
|
||
|
||
def __getattr__(name): | ||
for pm in plugin_modules: | ||
if not hasattr(pm, name): | ||
continue | ||
return functools.reduce(getattr, [name], pm) | ||
else: | ||
raise ModuleNotFoundError(f"module `{__name__}` has no function `{name}`") |