Skip to content

Releases: hiroki0525/autoload_module

1.3.0

11 May 12:05
Compare
Choose a tag to compare

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

19 Jan 12:30
Compare
Choose a tag to compare

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

07 Dec 14:28
3cf8b6b
Compare
Choose a tag to compare

This is minor bugfix version.

1.1.0

03 Nov 10:44
034a0af
Compare
Choose a tag to compare

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!!