diff --git a/src/griffe/loader.py b/src/griffe/loader.py index 982c2e67..17f7c64d 100644 --- a/src/griffe/loader.py +++ b/src/griffe/loader.py @@ -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.""" @@ -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, @@ -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. @@ -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, diff --git a/src/griffe/tests.py b/src/griffe/tests.py index 566fdf0d..e01a8cbc 100644 --- a/src/griffe/tests.py +++ b/src/griffe/tests.py @@ -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. @@ -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]