@@ -134,6 +134,7 @@ def temporary_visited_package(
134
134
resolve_aliases : bool = False ,
135
135
resolve_external : bool | None = None ,
136
136
resolve_implicit : bool = False ,
137
+ search_sys_path : bool = False ,
137
138
) -> Iterator [Module ]:
138
139
"""Create and visit a temporary package.
139
140
@@ -160,14 +161,16 @@ def temporary_visited_package(
160
161
Default value (`None`) means to load external modules only if they are the private sibling
161
162
or the origin module (for example when `ast` imports from `_ast`).
162
163
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.
163
165
164
166
Yields:
165
167
A module.
166
168
"""
169
+ search_paths = search_sys_path and sys .path or []
167
170
with temporary_pypackage (package , modules , init = init , inits = inits ) as tmp_package :
168
171
yield load ( # type: ignore[misc]
169
172
tmp_package .name ,
170
- search_paths = [tmp_package .tmpdir ],
173
+ search_paths = [tmp_package .tmpdir ] + search_paths ,
171
174
extensions = extensions ,
172
175
docstring_parser = docstring_parser ,
173
176
docstring_options = docstring_options ,
@@ -199,6 +202,7 @@ def temporary_inspected_package(
199
202
resolve_aliases : bool = False ,
200
203
resolve_external : bool | None = None ,
201
204
resolve_implicit : bool = False ,
205
+ search_sys_path : bool = False ,
202
206
) -> Iterator [Module ]:
203
207
"""Create and inspect a temporary package.
204
208
@@ -225,15 +229,17 @@ def temporary_inspected_package(
225
229
Default value (`None`) means to load external modules only if they are the private sibling
226
230
or the origin module (for example when `ast` imports from `_ast`).
227
231
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.
228
233
229
234
Yields:
230
235
A module.
231
236
"""
237
+ search_paths = search_sys_path and sys .path or []
232
238
with temporary_pypackage (package , modules , init = init , inits = inits ) as tmp_package :
233
239
try :
234
240
yield load ( # type: ignore[misc]
235
241
tmp_package .name ,
236
- search_paths = [tmp_package .tmpdir ],
242
+ search_paths = [tmp_package .tmpdir ] + search_paths ,
237
243
extensions = extensions ,
238
244
docstring_parser = docstring_parser ,
239
245
docstring_options = docstring_options ,
0 commit comments