Autoload-module

Latest version: v2.0.0

Safety actively analyzes 681790 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 3

2.0.0

* Drop Support Python v3.7
* Add support Python v3.10 and 3.11

1.7.2

This is minor fix release.
* 【Remove】deprecated parameter `pkg_name`.
* 【Minor Fix】add validations.

1.7.1

By setting `singleton=True` and `strict=True` in ModuleLoader config , you can know unexpected initializing ModuleLoader instance.

python
Strict mode
ModuleLoader.set_setting(singleton=True, strict=True)

Initialize as singleton object
loader_a = ModuleLoader()
loader_b = ModuleLoader()
assert loader_a is loader_b

Raise exception
loader_c = ModuleLoader('/tmp')
-> autoload.exception.LoaderStrictModeError: Now singleton setting. You have already initialized object that has some attributes. Please check constructor variables.

1.7.0

You can now create singleton object by setting global config like below.

python
singleton setting
ModuleLoader.set_setting(singleton=True)

loader_a = ModuleLoader()
loader_b = ModuleLoader()
loader_c = ModuleLoader('/test')

assert loader_a is loader_b OK
assert loader_a is loader_c OK

print(loader_a.base_path)
-> '/Users/user1/abc'

loader_c also has '/Users/user1/abc'.
assert loader_a.base_path is loader_c.base_path OK

1.6.0

You can add global setting to `ModuleLoader`.
python
import os
from autoload import ModuleLoader

global setting
ModuleLoader.set_setting(base_path=os.getcwd(), strict=True)

loader_a = ModuleLoader()
loader_b = ModuleLoader()

print(loader_a.base_path)
-> /Users/user1/abc
print(loader_a.strict)
-> True
print(loader_b.base_path)
-> /Users/user1/abc
print(loader_b.strict)
-> True

1.5.0

* `load_classes` and `load_functions` support to import not only Python package but also Python module.
* `pkg_name` is duplicated. Please change parameter `pkg_name` to `src` if you use keyword argument.

module.py
python
from autoload import load_config

load_config(order=1)
class Foo:
pass

load_config(order=2)
class Bar:
pass

load_config(order=3)
class Baz:
pass


main.py
python
from autoload import ModuleLoader

loader = ModuleLoader()
Return Foo, Bar and Baz classes.
classes = loader.load_classes("module")

Duplicated
classes = loader.load_classes(pkg_name="module")
If you want to use keyword argument, please change it like below.
classes = loader.load_classes(src="module")

Page 1 of 3

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.