File tree Expand file tree Collapse file tree 3 files changed +26
-28
lines changed Expand file tree Collapse file tree 3 files changed +26
-28
lines changed Original file line number Diff line number Diff line change 55
66from __future__ import annotations
77
8- import contextlib
9- import sys
108import warnings
11- from collections .abc import Iterator , Sequence
129from typing import TYPE_CHECKING , Any , Final , Literal
1310
1411from astroid .exceptions import InferenceError
@@ -160,26 +157,3 @@ def safe_infer(
160157 return None # there is some kind of ambiguity
161158 except StopIteration :
162159 return value
163-
164-
165- def _augment_sys_path (additional_paths : Sequence [str ]) -> list [str ]:
166- original = list (sys .path )
167- changes = []
168- seen = set ()
169- for additional_path in additional_paths :
170- if additional_path not in seen :
171- changes .append (additional_path )
172- seen .add (additional_path )
173-
174- sys .path [:] = changes + sys .path
175- return original
176-
177-
178- @contextlib .contextmanager
179- def augmented_sys_path (additional_paths : Sequence [str ]) -> Iterator [None ]:
180- """Augment 'sys.path' by adding entries from additional_paths."""
181- original = _augment_sys_path (additional_paths )
182- try :
183- yield
184- finally :
185- sys .path [:] = original
Original file line number Diff line number Diff line change 44
55from __future__ import annotations
66
7+ import contextlib
78import os
89import sys
10+ from collections .abc import Iterator , Sequence
911from pathlib import Path
1012
1113from astroid import builder
@@ -33,3 +35,26 @@ def tearDown(self) -> None:
3335 for key in list (sys .path_importer_cache ):
3436 if key .startswith (datadir ):
3537 del sys .path_importer_cache [key ]
38+
39+
40+ def _augment_sys_path (additional_paths : Sequence [str ]) -> list [str ]:
41+ original = list (sys .path )
42+ changes = []
43+ seen = set ()
44+ for additional_path in additional_paths :
45+ if additional_path not in seen :
46+ changes .append (additional_path )
47+ seen .add (additional_path )
48+
49+ sys .path [:] = changes + sys .path
50+ return original
51+
52+
53+ @contextlib .contextmanager
54+ def augmented_sys_path (additional_paths : Sequence [str ]) -> Iterator [None ]:
55+ """Augment 'sys.path' by adding entries from additional_paths."""
56+ original = _augment_sys_path (additional_paths )
57+ try :
58+ yield
59+ finally :
60+ sys .path [:] = original
Original file line number Diff line number Diff line change 2222from astroid import modutils
2323from astroid .const import PY310_PLUS
2424from astroid .interpreter ._import import spec
25- from astroid .util import augmented_sys_path
2625
2726from . import resources
2827
@@ -185,7 +184,7 @@ def test_modpath_from_file_path_order(self) -> None:
185184 should be relative to the subdirectory since additional directory has
186185 higher precedence."""
187186 with tempfile .TemporaryDirectory () as tmp_dir :
188- with augmented_sys_path ([tmp_dir ]):
187+ with resources . augmented_sys_path ([tmp_dir ]):
189188 mod_name = "module"
190189 sub_dirname = "subdir"
191190 sub_dir = tmp_dir + "/" + sub_dirname
You can’t perform that action at this time.
0 commit comments