mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix some Windows related issues with absolute paths
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path
|
||||||
from importlib.machinery import all_suffixes
|
from importlib.machinery import all_suffixes
|
||||||
|
|
||||||
from jedi.inference.cache import inference_state_method_cache
|
from jedi.inference.cache import inference_state_method_cache
|
||||||
@@ -15,7 +15,7 @@ _BUILDOUT_PATH_INSERTION_LIMIT = 10
|
|||||||
|
|
||||||
|
|
||||||
def _abs_path(module_context, path: str):
|
def _abs_path(module_context, path: str):
|
||||||
path = PurePath(path)
|
path = Path(path)
|
||||||
if path.is_absolute():
|
if path.is_absolute():
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ def transform_path_to_dotted(sys_path, module_path):
|
|||||||
"""
|
"""
|
||||||
Returns the dotted path inside a sys.path as a list of names. e.g.
|
Returns the dotted path inside a sys.path as a list of names. e.g.
|
||||||
|
|
||||||
>>> transform_path_to_dotted(["/foo"], Path('/foo/bar/baz.py'))
|
>>> transform_path_to_dotted([str(Path("/foo").absolute())], Path('/foo/bar/baz.py').absolute())
|
||||||
(('bar', 'baz'), False)
|
(('bar', 'baz'), False)
|
||||||
|
|
||||||
Returns (None, False) if the path doesn't really resolve to anything.
|
Returns (None, False) if the path doesn't really resolve to anything.
|
||||||
|
|||||||
@@ -58,17 +58,17 @@ def test_sys_path_with_modifications(Script):
|
|||||||
""")
|
""")
|
||||||
|
|
||||||
paths = Script(code, path=path)._inference_state.get_sys_path()
|
paths = Script(code, path=path)._inference_state.get_sys_path()
|
||||||
assert '/tmp/.buildout/eggs/important_package.egg' in paths
|
assert os.path.abspath('/tmp/.buildout/eggs/important_package.egg') in paths
|
||||||
|
|
||||||
|
|
||||||
def test_path_from_sys_path_assignment(Script):
|
def test_path_from_sys_path_assignment(Script):
|
||||||
code = dedent("""
|
code = dedent(f"""
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.path[0:0] = [
|
sys.path[0:0] = [
|
||||||
'/usr/lib/python3.8/site-packages',
|
{os.path.abspath('/usr/lib/python3.8/site-packages')!r},
|
||||||
'/home/test/.buildout/eggs/important_package.egg'
|
{os.path.abspath('/home/test/.buildout/eggs/important_package.egg')!r},
|
||||||
]
|
]
|
||||||
|
|
||||||
path[0:0] = [1]
|
path[0:0] = [1]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import os
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -18,9 +18,9 @@ def test_paths_from_assignment(Script):
|
|||||||
return set(sys_path._paths_from_assignment(script._get_module_context(), expr_stmt))
|
return set(sys_path._paths_from_assignment(script._get_module_context(), expr_stmt))
|
||||||
|
|
||||||
# Normalize paths for Windows.
|
# Normalize paths for Windows.
|
||||||
path_a = PurePath('/foo/a')
|
path_a = Path('/foo/a').absolute()
|
||||||
path_b = PurePath('/foo/b')
|
path_b = Path('/foo/b').absolute()
|
||||||
path_c = PurePath('/foo/c')
|
path_c = Path('/foo/c').absolute()
|
||||||
|
|
||||||
assert paths('sys.path[0:0] = ["a"]') == {path_a}
|
assert paths('sys.path[0:0] = ["a"]') == {path_a}
|
||||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == {path_b, path_c}
|
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == {path_b, path_c}
|
||||||
|
|||||||
Reference in New Issue
Block a user