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 5
5
6
6
from __future__ import annotations
7
7
8
- import contextlib
9
- import sys
10
8
import warnings
11
- from collections .abc import Iterator , Sequence
12
9
from typing import TYPE_CHECKING , Any , Final , Literal
13
10
14
11
from astroid .exceptions import InferenceError
@@ -160,26 +157,3 @@ def safe_infer(
160
157
return None # there is some kind of ambiguity
161
158
except StopIteration :
162
159
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 4
4
5
5
from __future__ import annotations
6
6
7
+ import contextlib
7
8
import os
8
9
import sys
10
+ from collections .abc import Iterator , Sequence
9
11
from pathlib import Path
10
12
11
13
from astroid import builder
@@ -33,3 +35,26 @@ def tearDown(self) -> None:
33
35
for key in list (sys .path_importer_cache ):
34
36
if key .startswith (datadir ):
35
37
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 22
22
from astroid import modutils
23
23
from astroid .const import PY310_PLUS
24
24
from astroid .interpreter ._import import spec
25
- from astroid .util import augmented_sys_path
26
25
27
26
from . import resources
28
27
@@ -185,7 +184,7 @@ def test_modpath_from_file_path_order(self) -> None:
185
184
should be relative to the subdirectory since additional directory has
186
185
higher precedence."""
187
186
with tempfile .TemporaryDirectory () as tmp_dir :
188
- with augmented_sys_path ([tmp_dir ]):
187
+ with resources . augmented_sys_path ([tmp_dir ]):
189
188
mod_name = "module"
190
189
sub_dirname = "subdir"
191
190
sub_dir = tmp_dir + "/" + sub_dirname
You can’t perform that action at this time.
0 commit comments