message-van 2.0.0__tar.gz → 2.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {message_van-2.0.0 → message_van-2.0.1}/.github/workflows/publish.yml +2 -2
  2. {message_van-2.0.0 → message_van-2.0.1}/PKG-INFO +1 -1
  3. {message_van-2.0.0 → message_van-2.0.1}/pyproject.toml +2 -2
  4. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/message_van.py +1 -0
  5. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/message_van_meta.py +7 -9
  6. {message_van-2.0.0/src/message_van/signatures → message_van-2.0.1/src/message_van/signature_lister}/__init__.py +3 -0
  7. message_van-2.0.0/src/message_van/signatures/module_lister.py → message_van-2.0.1/src/message_van/signature_lister/module_importer.py +20 -33
  8. message_van-2.0.1/src/message_van/signature_lister/module_lister.py +22 -0
  9. {message_van-2.0.0/src/message_van/signatures → message_van-2.0.1/src/message_van/signature_lister}/signature_lister.py +2 -2
  10. message_van-2.0.1/src/message_van/util/__init__.py +6 -0
  11. message_van-2.0.1/src/message_van/util/package_dir.py +31 -0
  12. message_van-2.0.0/src/message_van/util/__init__.py +0 -6
  13. message_van-2.0.0/src/message_van/util/src_dir.py +0 -13
  14. {message_van-2.0.0 → message_van-2.0.1}/.gitignore +0 -0
  15. {message_van-2.0.0 → message_van-2.0.1}/.python-version +0 -0
  16. {message_van-2.0.0 → message_van-2.0.1}/LICENSE.txt +0 -0
  17. {message_van-2.0.0 → message_van-2.0.1}/README.md +0 -0
  18. {message_van-2.0.0 → message_van-2.0.1}/docs/img/icon.png +0 -0
  19. {message_van-2.0.0 → message_van-2.0.1}/docs/img/logo.png +0 -0
  20. {message_van-2.0.0 → message_van-2.0.1}/requirements-dev.lock +0 -0
  21. {message_van-2.0.0 → message_van-2.0.1}/requirements.lock +0 -0
  22. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/__init__.py +0 -0
  23. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/exceptions/__init__.py +0 -0
  24. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/exceptions/already_registered_handler_error.py +0 -0
  25. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/exceptions/unknown_handler_error.py +0 -0
  26. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/__init__.py +0 -0
  27. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/__init__.py +0 -0
  28. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/command.py +0 -0
  29. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/command_handler.py +0 -0
  30. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/event.py +0 -0
  31. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/event_handler.py +0 -0
  32. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/message.py +0 -0
  33. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/base/message_handler.py +0 -0
  34. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/handler_signature.py +0 -0
  35. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/message_handler_type.py +0 -0
  36. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/message_handlers.py +0 -0
  37. {message_van-2.0.0 → message_van-2.0.1}/src/message_van/models/unit_of_work.py +0 -0
  38. {message_van-2.0.0/src/message_van/signatures → message_van-2.0.1/src/message_van/signature_lister}/function_lister.py +0 -0
  39. {message_van-2.0.0/src/message_van/signatures → message_van-2.0.1/src/message_van/signature_lister}/signature_getter.py +0 -0
@@ -84,12 +84,12 @@ jobs:
84
84
  "$GITHUB_REF_NAME"
85
85
  --repo "$GITHUB_REPOSITORY"
86
86
  --notes ""
87
- - name: Upload artifact signatures to GitHub Release
87
+ - name: Upload artifact signature_lister to GitHub Release
88
88
  env:
89
89
  GITHUB_TOKEN: ${{ github.token }}
90
90
  # Upload to GitHub Release using the `gh` CLI.
91
91
  # `dist/` contains the built packages, and the
92
- # sigstore-produced signatures and certificates.
92
+ # sigstore-produced signature_lister and certificates.
93
93
  run: >-
94
94
  gh release upload
95
95
  "$GITHUB_REF_NAME" dist/**
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: message-van
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: Python Event-Driven Architecture without the Administration.
5
5
  Author-email: Thomas Vanhelden <thomas.vanhelden@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "message-van"
3
- version = "2.0.0"
3
+ version = "2.0.1"
4
4
  description = "Python Event-Driven Architecture without the Administration."
5
5
  authors = [
6
6
  { name = "Thomas Vanhelden", email = "thomas.vanhelden@gmail.com" }
@@ -37,7 +37,7 @@ packages = ["src/message_van"]
37
37
 
38
38
 
39
39
  [tool.bumpversion]
40
- current_version = "2.0.0"
40
+ current_version = "2.0.1"
41
41
  parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
42
42
  serialize = ["{major}.{minor}.{patch}"]
43
43
  search = "{current_version}"
@@ -55,3 +55,4 @@ class MessageVan(metaclass=MessageVanMeta):
55
55
 
56
56
  def _get_handlers_for_event(self, event: Event) -> list[EventHandler]:
57
57
  return self._message_handlers.get_handlers_for_event(event)
58
+
@@ -1,10 +1,8 @@
1
1
  from abc import ABCMeta
2
- from inspect import getfile
3
- from pathlib import Path
4
2
 
5
3
  from message_van.models import MessageHandlers
6
- from message_van.signatures import list_signatures
7
- from message_van.util import get_src_dir
4
+ from message_van.signature_lister import list_signatures
5
+ from message_van.util import get_package_dir
8
6
 
9
7
 
10
8
  class MessageVanMeta(ABCMeta):
@@ -18,14 +16,14 @@ class MessageVanMeta(ABCMeta):
18
16
  return cls
19
17
 
20
18
  async def register_handlers(cls) -> None:
21
- if cls._message_handlers is None:
19
+ if cls._no_handlers_registered():
22
20
  await cls._register_handlers()
23
21
 
24
22
  async def _register_handlers(cls) -> None:
25
- cls_file = Path(getfile(cls))
26
- src_dir = get_src_dir(cls_file)
27
-
28
23
  cls._message_handlers = MessageHandlers()
29
24
 
30
- for signature in list_signatures(src_dir):
25
+ for signature in list_signatures(get_package_dir(cls)):
31
26
  cls._message_handlers.register(signature)
27
+
28
+ def _no_handlers_registered(cls) -> bool:
29
+ return cls._message_handlers is None
@@ -1,3 +1,5 @@
1
+ from .module_importer import import_module
2
+
1
3
  from .function_lister import list_public_functions
2
4
  from .module_lister import list_modules
3
5
  from .signature_getter import get_signature
@@ -10,4 +12,5 @@ __all__ = [
10
12
  "list_modules",
11
13
  "list_public_functions",
12
14
  "list_signatures",
15
+ "module_importer",
13
16
  ]
@@ -1,34 +1,10 @@
1
1
  import importlib
2
- import os
3
2
  import sys
4
- from collections.abc import Generator
5
3
  from pathlib import Path
6
4
  from types import ModuleType
7
5
 
8
6
 
9
- def list_modules(root_package_path: Path) -> Generator[ModuleType]:
10
- for module_path in list_module_paths(root_package_path):
11
- yield import_module(root_package_path, module_path)
12
-
13
-
14
- def list_module_paths(root_package_path: Path) -> Generator[Path]:
15
- for file_path in list_file_paths(root_package_path):
16
- if _is_module(file_path):
17
- yield file_path
18
-
19
-
20
- def list_file_paths(root_package_path: Path) -> Generator[Path]:
21
- for directory, _, file_names in os.walk(root_package_path):
22
- directory_path = Path(directory)
23
-
24
- for file_name in file_names:
25
- yield directory_path / Path(file_name)
26
-
27
-
28
- def _is_module(path: Path) -> bool:
29
- file_name = path.name
30
-
31
- return file_name.endswith(".py")
7
+ _import_cache = {}
32
8
 
33
9
 
34
10
  def import_module(root_package_path: Path, module_path: Path) -> ModuleType:
@@ -41,7 +17,18 @@ def import_module(root_package_path: Path, module_path: Path) -> ModuleType:
41
17
  def _import_module(root_package_path: Path, module_path: Path) -> ModuleType:
42
18
  module_name = get_module_name(module_path, root_package_path)
43
19
 
44
- return importlib.import_module(module_name)
20
+ return safe_import_module(module_name)
21
+
22
+
23
+ def safe_import_module(module_name: str) -> ModuleType:
24
+ if module_name not in _import_cache:
25
+ if module_name in sys.modules:
26
+ module = sys.modules[module_name]
27
+ else:
28
+ module = importlib.import_module(module_name)
29
+ _import_cache[module_name] = module
30
+
31
+ return _import_cache[module_name]
45
32
 
46
33
 
47
34
  def _root_package_in_path(root_package_path: Path) -> bool:
@@ -54,7 +41,13 @@ def _get_package_parent_string(package_path: Path) -> str:
54
41
  return str(parent_path)
55
42
 
56
43
 
57
- def _add_root_package_to_path(root_package_path: Path):
44
+ def get_module_name(module_path: Path, package_root_path: Path) -> str:
45
+ relative = module_path.relative_to(package_root_path.parent)
46
+
47
+ return ".".join(relative.with_suffix("").parts)
48
+
49
+
50
+ def _add_root_package_to_path(root_package_path: Path) -> None:
58
51
  parent_path = root_package_path.parent
59
52
  parent_path_string = str(parent_path)
60
53
 
@@ -63,9 +56,3 @@ def _add_root_package_to_path(root_package_path: Path):
63
56
 
64
57
  def _add_to_path(path_string: str) -> None:
65
58
  sys.path.insert(0, path_string)
66
-
67
-
68
- def get_module_name(module_path: Path, package_root_path: Path):
69
- relative = module_path.relative_to(package_root_path.parent)
70
-
71
- return ".".join(relative.with_suffix("").parts)
@@ -0,0 +1,22 @@
1
+ from collections.abc import Generator
2
+ from pathlib import Path
3
+ from types import ModuleType
4
+
5
+ from . import import_module
6
+
7
+
8
+ def list_modules(package_path: Path) -> Generator[ModuleType]:
9
+ for module_path in _list_module_paths(package_path):
10
+ yield import_module(package_path, module_path)
11
+
12
+
13
+ def _list_module_paths(package_path: Path) -> Generator[Path]:
14
+ for file_path in package_path.rglob("*"):
15
+ if _is_module(file_path):
16
+ yield file_path
17
+
18
+
19
+ def _is_module(path: Path) -> bool:
20
+ file_name = path.name
21
+
22
+ return file_name.endswith(".py")
@@ -5,8 +5,8 @@ from pathlib import Path
5
5
  from types import ModuleType
6
6
  from typing import Callable
7
7
 
8
- from message_van.signatures.function_lister import list_public_functions
9
- from message_van.signatures.module_lister import list_modules
8
+ from message_van.signature_lister.function_lister import list_public_functions
9
+ from message_van.signature_lister.module_lister import list_modules
10
10
  from message_van.models import (
11
11
  Command,
12
12
  Event,
@@ -0,0 +1,6 @@
1
+ from .package_dir import get_package_dir
2
+
3
+
4
+ __all__ = [
5
+ "get_package_dir",
6
+ ]
@@ -0,0 +1,31 @@
1
+ import inspect
2
+ from pathlib import Path
3
+
4
+
5
+ def get_package_dir(cls: type) -> Path:
6
+ file = _get_file(cls)
7
+
8
+ return _get_package_dir(file)
9
+
10
+
11
+ def _get_package_dir(path: Path) -> Path:
12
+ if _is_package_dir(path):
13
+ return path
14
+
15
+ return _get_package_dir(path.parent)
16
+
17
+
18
+ def _is_package_dir(path: Path) -> bool:
19
+ parent_path = path.parent
20
+
21
+ return _is_src_dir(parent_path)
22
+
23
+
24
+ def _is_src_dir(path: Path) -> bool:
25
+ return path.name == "src" or path.name == "site-packages"
26
+
27
+
28
+ def _get_file(cls: type) -> Path:
29
+ file_name = inspect.getfile(cls)
30
+
31
+ return Path(file_name)
@@ -1,6 +0,0 @@
1
- from .src_dir import get_src_dir
2
-
3
-
4
- __all__ = [
5
- "get_src_dir",
6
- ]
@@ -1,13 +0,0 @@
1
- from pathlib import Path
2
-
3
-
4
- def get_src_dir(start_path: Path) -> Path:
5
- start_path = start_path.resolve()
6
-
7
- for parent in [start_path, *start_path.parents]:
8
- if _is_src_dir(parent):
9
- return parent
10
-
11
-
12
- def _is_src_dir(path: Path) -> bool:
13
- return path.name == "src" or path.parent.name == "site-packages"
File without changes
File without changes
File without changes
File without changes