From 7bdcc33edaea6e8a2cbfdca84ac703e00f2e0faa Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Fri, 6 Aug 2021 15:56:24 -0400 Subject: [PATCH 1/2] Update wiring to support modules provided as packages --- src/dependency_injector/wiring.py | 2 ++ tests/unit/wiring/test_wiring_py36.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index 6f54c993..4dd77c09 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -552,6 +552,8 @@ def _unbind_injections(fn: Callable[..., Any]) -> None: def _fetch_modules(package): modules = [package] + if not hasattr(package, '__path__') or not hasattr(package, '__name__'): + return modules for module_info in pkgutil.walk_packages( path=package.__path__, prefix=package.__name__ + '.', diff --git a/tests/unit/wiring/test_wiring_py36.py b/tests/unit/wiring/test_wiring_py36.py index 64ff7fc7..7c503782 100644 --- a/tests/unit/wiring/test_wiring_py36.py +++ b/tests/unit/wiring/test_wiring_py36.py @@ -310,6 +310,18 @@ class WiringTest(unittest.TestCase): self.assertIsInstance(service, Service) +class ModuleAsPackagingTest(unittest.TestCase): + + def setUp(self): + self.container = Container(config={'a': {'b': {'c': 10}}}) + self.addCleanup(self.container.unwire) + + def test_module_as_package_wiring(self): + # See: https://github.com/ets-labs/python-dependency-injector/issues/481 + self.container.wire(packages=[module]) + self.assertIsInstance(module.service, Service) + + class WiringAndQueue(unittest.TestCase): def test_wire_queue(self) -> None: From 5acde87a6e3de87f8f587dc0a10e844c120b55c6 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Fri, 6 Aug 2021 16:50:42 -0400 Subject: [PATCH 2/2] Bump version to 4.35.2 --- docs/main/changelog.rst | 6 ++++++ src/dependency_injector/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 4cb0a6c9..09014871 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,12 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ +4.35.2 +------ +- Update wiring to support modules provided as packages. + See issue `#481 `_. + Thanks to `@Sadbot `_ for demonstrating the issue. + 4.35.1 ------ - Fix a container issue with supporting custom string types. diff --git a/src/dependency_injector/__init__.py b/src/dependency_injector/__init__.py index e265332b..5122015c 100644 --- a/src/dependency_injector/__init__.py +++ b/src/dependency_injector/__init__.py @@ -1,6 +1,6 @@ """Top-level package.""" -__version__ = '4.35.1' +__version__ = '4.35.2' """Version number. :type: str