From 7f82dc382f1f20ee9e5f58a9ef7a775563894056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sat, 17 Aug 2024 17:47:31 +0200 Subject: [PATCH] feat: Pass `loader` to `on_package_loaded` hooks --- src/_griffe/extensions/base.py | 4 +++- src/_griffe/loader.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/_griffe/extensions/base.py b/src/_griffe/extensions/base.py index 573f4407..ebdcdb56 100644 --- a/src/_griffe/extensions/base.py +++ b/src/_griffe/extensions/base.py @@ -21,6 +21,7 @@ from _griffe.agents.inspector import Inspector from _griffe.agents.nodes.runtime import ObjectNode from _griffe.agents.visitor import Visitor + from _griffe.loader import GriffeLoader from _griffe.models import Attribute, Class, Function, Module, Object @@ -234,11 +235,12 @@ def on_attribute_instance( **kwargs: For forward-compatibility. """ - def on_package_loaded(self, *, pkg: Module, **kwargs: Any) -> None: + def on_package_loaded(self, *, pkg: Module, loader: GriffeLoader, **kwargs: Any) -> None: """Run when a package has been completely loaded. Parameters: pkg: The package (Module) instance. + loader: The loader currently in use. **kwargs: For forward-compatibility. """ diff --git a/src/_griffe/loader.py b/src/_griffe/loader.py index d7ac480a..069e39c4 100644 --- a/src/_griffe/loader.py +++ b/src/_griffe/loader.py @@ -165,7 +165,7 @@ def load( top_module = self._inspect_module(top_module_name) self.modules_collection.set_member(top_module.path, top_module) obj = self.modules_collection.get_member(obj_path) - self.extensions.call("on_package_loaded", pkg=obj) + self.extensions.call("on_package_loaded", pkg=obj, loader=self) return obj # We found paths, and use them to build our intermediate Package or NamespacePackage struct. @@ -186,7 +186,7 @@ def load( # Package is loaded, we now retrieve the initially requested object and return it. obj = self.modules_collection.get_member(obj_path) - self.extensions.call("on_package_loaded", pkg=top_module) + self.extensions.call("on_package_loaded", pkg=top_module, loader=self) return obj def resolve_aliases(