-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to import all components at once (#29)
with `from guipy.components import *`
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 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,19 @@ | ||
import importlib | ||
import pkgutil | ||
from inspect import isclass | ||
|
||
__all__ = [] | ||
|
||
# modified from: https://julienharbulot.com/python-dynamical-import.html | ||
# iterate through the modules in the current package | ||
# package_dir = Path(__file__).resolve().parent | ||
for (_, module_name, _) in pkgutil.iter_modules(__path__): | ||
|
||
# import the module and iterate through its attributes | ||
module = importlib.import_module(f"{__name__}.{module_name}") | ||
for attribute_name in dir(module): | ||
attribute = getattr(module, attribute_name) | ||
if isclass(attribute): | ||
# Add the class to this package's variables | ||
globals()[attribute_name] = attribute | ||
__all__.append(attribute_name) |