Releases: hiroki0525/autoload_module
Releases · hiroki0525/autoload_module
1.3.2
Formally support Python >= 3.7
1.3.1
load_config
parameterload
default is True.
from autoload.decorator import load_config
# @load_config(load=True)
@load_config()
class CustomValidator:
def validate(self):
print("validateA!!")
- Fix
load=False
not working problem.
1.3.0
autoload_module
supports to import multiple classes or functions like below.
- pkg/test1.py
@load_config(load=True, order=2)
class Module2:
pass
@load_config(load=True, order=1)
class Module1:
pass
@load_config(load=True, order=3)
class Module3:
pass
- pkg/test2.py
@load_config(load=True, order=4)
class Module4:
pass
class NotImport:
pass
- main.py
from autoload.module_loader import ModuleLoader
loader = ModuleLoader()
# Import Module1, Module2, Module3, and Module1
classes = loader.load_classes("pkg")
1.2.0
This library came to be able to check directories recursively.
The example is below.
- Directory structure
pkg/
├ example.py
└ main/
├ validator_a.py
├ validator_b.py
├ validator_c.py
└ sub/
├ validator_d.py
└ validator_e.py
- validator_a.py
class ValidatorA:
def validate(self):
print("validateA!!")
- example.py
from autoload.module_loader import ModuleLoader
loader = ModuleLoader()
# The loader will also check 'pkg/main/sub/'.
validator_classes = loader.load_classes("main", recursive=True)
[clazz().validate() for clazz in validator_classes]
# -> validateA!!
# -> validateB!!
# -> validateC!!
# -> validateD!!
# -> validateE!!
You can use the parameter recursive
for not only load_classes
but also load_functions
.
1.1.1
This is minor bugfix version.
1.1.0
This library can import functions like the below.
- Directory
/usr/local/src/project/
├ example.py
└ validator/
├ validator_a.py
├ validator_b.py
└ validator_c.py
- validator_a.py
def validator_a():
print("validateA!!")
- example.py
loader = ModuleLoader()
# return the tuple of validate_a, validate_b, and validate_c function objects
validator_functions = loader.load_functions("validator")
# initialize and execute method
[validate() for func in validator_functions]
# -> validateA!!
# -> validateB!!
# -> validateC!!