@@ -134,6 +134,7 @@ def temporary_visited_package(
134134 resolve_aliases : bool = False ,
135135 resolve_external : bool | None = None ,
136136 resolve_implicit : bool = False ,
137+ search_sys_path : bool = False ,
137138) -> Iterator [Module ]:
138139 """Create and visit a temporary package.
139140
@@ -160,14 +161,16 @@ def temporary_visited_package(
160161 Default value (`None`) means to load external modules only if they are the private sibling
161162 or the origin module (for example when `ast` imports from `_ast`).
162163 resolve_implicit: When false, only try to resolve an alias if it is explicitly exported.
164+ search_sys_path: Whether to search the system paths for the package.
163165
164166 Yields:
165167 A module.
166168 """
169+ search_paths = search_sys_path and sys .path or []
167170 with temporary_pypackage (package , modules , init = init , inits = inits ) as tmp_package :
168171 yield load ( # type: ignore[misc]
169172 tmp_package .name ,
170- search_paths = [tmp_package .tmpdir ],
173+ search_paths = [tmp_package .tmpdir ] + search_paths ,
171174 extensions = extensions ,
172175 docstring_parser = docstring_parser ,
173176 docstring_options = docstring_options ,
@@ -199,6 +202,7 @@ def temporary_inspected_package(
199202 resolve_aliases : bool = False ,
200203 resolve_external : bool | None = None ,
201204 resolve_implicit : bool = False ,
205+ search_sys_path : bool = False ,
202206) -> Iterator [Module ]:
203207 """Create and inspect a temporary package.
204208
@@ -225,15 +229,17 @@ def temporary_inspected_package(
225229 Default value (`None`) means to load external modules only if they are the private sibling
226230 or the origin module (for example when `ast` imports from `_ast`).
227231 resolve_implicit: When false, only try to resolve an alias if it is explicitly exported.
232+ search_sys_path: Whether to search the system paths for the package.
228233
229234 Yields:
230235 A module.
231236 """
237+ search_paths = search_sys_path and sys .path or []
232238 with temporary_pypackage (package , modules , init = init , inits = inits ) as tmp_package :
233239 try :
234240 yield load ( # type: ignore[misc]
235241 tmp_package .name ,
236- search_paths = [tmp_package .tmpdir ],
242+ search_paths = [tmp_package .tmpdir ] + search_paths ,
237243 extensions = extensions ,
238244 docstring_parser = docstring_parser ,
239245 docstring_options = docstring_options ,
0 commit comments