Skip to content

Commit

Permalink
feat: Allow passing load parameters to the temporary package visit he…
Browse files Browse the repository at this point in the history
…lper
  • Loading branch information
pawamoy committed Nov 13, 2023
1 parent 5becf73 commit 3a7854f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
lines_collection: A collection of source code lines.
modules_collection: A collection of modules.
allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
store_source: Whether to store code source in the lines collection.
"""
self.extensions: Extensions = extensions or Extensions()
"""Loaded Griffe extensions."""
Expand Down Expand Up @@ -692,6 +693,7 @@ def load(
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None,
allow_inspection: bool = True,
store_source: bool = True,
find_stubs_package: bool = False,
# TODO: Remove at some point.
module: str | Path | None = None,
Expand Down Expand Up @@ -728,6 +730,7 @@ def load(
lines_collection: A collection of source code lines.
modules_collection: A collection of modules.
allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
store_source: Whether to store code source in the lines collection.
find_stubs_package: Whether to search for stubs-only package.
If both the package and its stubs are found, they'll be merged together.
If only the stubs are found, they'll be used as the package itself.
Expand All @@ -744,6 +747,7 @@ def load(
lines_collection=lines_collection,
modules_collection=modules_collection,
allow_inspection=allow_inspection,
store_source=store_source,
).load(
objspec,
submodules=submodules,
Expand Down
25 changes: 24 additions & 1 deletion src/griffe/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def temporary_visited_package(
modules: Sequence[str] | Mapping[str, str] | None = None,
*,
init: bool = True,
extensions: Extensions | None = None,
docstring_parser: Parser | None = None,
docstring_options: dict[str, Any] | None = None,
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None,
allow_inspection: bool = False,
store_source: bool = True,
) -> Iterator[Module]:
"""Create and visit a temporary package.
Expand All @@ -119,12 +126,28 @@ def temporary_visited_package(
If a dict, keys are the file names and values their contents:
`{"b.py": "b = 1", "c/d.py": "print('hey from c')"}`.
init: Whether to create an `__init__` module in the leaf package.
extensions: The extensions to use.
docstring_parser: The docstring parser to use. By default, no parsing is done.
docstring_options: Additional docstring parsing options.
lines_collection: A collection of source code lines.
modules_collection: A collection of modules.
allow_inspection: Whether to allow inspecting modules when visiting them is not possible.
store_source: Whether to store code source in the lines collection.
Yields:
A module.
"""
with temporary_pypackage(package, modules, init=init) as tmp_package:
loader = GriffeLoader(search_paths=[tmp_package.tmpdir])
loader = GriffeLoader(
search_paths=[tmp_package.tmpdir],
extensions=extensions,
docstring_parser=docstring_parser,
docstring_options=docstring_options,
lines_collection=lines_collection,
modules_collection=modules_collection,
allow_inspection=allow_inspection,
store_source=store_source,
)
yield loader.load(tmp_package.name) # type: ignore[misc]


Expand Down

0 comments on commit 3a7854f

Please sign in to comment.