Skip to content

Commit

Permalink
Allow user to import all components at once (#29)
Browse files Browse the repository at this point in the history
with `from guipy.components import *`
  • Loading branch information
Zjjc123 authored Sep 16, 2022
1 parent 05ec7d4 commit 9e7a8b5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions guipy/components/__init__.py
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)

0 comments on commit 9e7a8b5

Please sign in to comment.