Skip to content

Commit

Permalink
feat: Pass loader to on_package_loaded hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Aug 17, 2024
1 parent b72eae8 commit 7f82dc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/_griffe/extensions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
"""

Expand Down
4 changes: 2 additions & 2 deletions src/_griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down

0 comments on commit 7f82dc3

Please sign in to comment.