Skip to content

Releases: hiroki0525/autoload_module

2.0.0

16 Jun 07:19
2b217fa
Compare
Choose a tag to compare
  • Drop Support Python v3.7
  • Add support Python v3.10 and 3.11

1.7.2

07 Jul 05:41
f3e10dc
Compare
Choose a tag to compare

This is minor fix release.

  • 【Remove】deprecated parameter pkg_name.
  • 【Minor Fix】add validations.

1.7.1

12 Jun 02:51
8b45dc7
Compare
Choose a tag to compare

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

# 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

10 Jun 13:27
4f498ce
Compare
Choose a tag to compare

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

# 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

06 Jun 02:35
aa8c563
Compare
Choose a tag to compare

You can add global setting to ModuleLoader.

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

30 May 01:25
f0c1482
Compare
Choose a tag to compare
  • 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

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

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")

1.4.0

27 May 01:31
ab8e0b8
Compare
Choose a tag to compare

New parameter is added to ModuleLoader constructor.

ModuleLoader(
  base_path: Optional[str] = None,
  strict: bool = False # New!!
)

If you decorate some classes or functions with @load_config, the loader will load them. However, initialized strict=True, the loader denies multiple loading as below.

  • pkg/validator_a.py
from autoload import load_config

# This will be loaded because of name's rule.
class ValidatorA:
  def validate(self):
      print("validateA!!")

# Anything goes.
@load_config(order=2)
class Foo:
  pass
  • main.py
from autoload import ModuleLoader
from autoload.exception import LoaderStrictModeError

loader = ModuleLoader()
# return ValidatorA and Foo class objects.
classes = loader.load_classes("pkg")

# ModuleLoader strictly try to load a class or function object
# per a Python module on a basis of its name.
strict_loader = ModuleLoader(strict=True)
try:
  classes = strict_loader.load_classes("pkg")
except LoaderStrictModeError as e:
  print(e)
# -> Loader can only load a 'ValidatorA' class in validator_a module.
# -> Please check 'Foo' in validator_a module.

1.3.3

23 May 08:38
df5d304
Compare
Choose a tag to compare

This is minor release.

  • Fix how to import ModuleLoader and load_config.
from autoload.module_loader import ModuleLoader, load_config
# You can also import as below
from autoload import ModuleLoader, load_config

1.3.2

21 May 11:43
42265c3
Compare
Choose a tag to compare

Formally support Python >= 3.7

1.3.1

15 May 02:32
3699f32
Compare
Choose a tag to compare
  • load_config parameter load 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.