mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Merge pull request #1706 from ColdGrub1384/master
Catch 'PermissionError' for unreadable directories
This commit is contained in:
@@ -366,8 +366,11 @@ class Project:
|
|||||||
|
|
||||||
def _is_potential_project(path):
|
def _is_potential_project(path):
|
||||||
for name in _CONTAINS_POTENTIAL_PROJECT:
|
for name in _CONTAINS_POTENTIAL_PROJECT:
|
||||||
if path.joinpath(name).exists():
|
try:
|
||||||
return True
|
if path.joinpath(name).exists():
|
||||||
|
return True
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -171,8 +171,11 @@ def _get_paths_from_buildout_script(inference_state, buildout_script_path):
|
|||||||
|
|
||||||
def _get_parent_dir_with_file(path: Path, filename):
|
def _get_parent_dir_with_file(path: Path, filename):
|
||||||
for parent in path.parents:
|
for parent in path.parents:
|
||||||
if parent.joinpath(filename).is_file():
|
try:
|
||||||
return parent
|
if parent.joinpath(filename).is_file():
|
||||||
|
return parent
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import pytest
|
|||||||
from ..helpers import get_example_dir, set_cwd, root_dir, test_dir
|
from ..helpers import get_example_dir, set_cwd, root_dir, test_dir
|
||||||
from jedi import Interpreter
|
from jedi import Interpreter
|
||||||
from jedi.api import Project, get_default_project
|
from jedi.api import Project, get_default_project
|
||||||
|
from jedi.api.project import _is_potential_project, _CONTAINS_POTENTIAL_PROJECT
|
||||||
|
|
||||||
|
|
||||||
def test_django_default_project(Script):
|
def test_django_default_project(Script):
|
||||||
@@ -160,3 +161,21 @@ def test_complete_search(Script, string, completions, all_scopes):
|
|||||||
project = Project(test_dir)
|
project = Project(test_dir)
|
||||||
defs = project.complete_search(string, all_scopes=all_scopes)
|
defs = project.complete_search(string, all_scopes=all_scopes)
|
||||||
assert [d.complete for d in defs] == completions
|
assert [d.complete for d in defs] == completions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'path,expected', [
|
||||||
|
(Path(__file__).parents[2], True), # The path of the project
|
||||||
|
(Path(__file__).parents[1], False), # The path of the tests, not a project
|
||||||
|
(Path.home(), None)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_is_potential_project(path, expected):
|
||||||
|
|
||||||
|
if expected is None:
|
||||||
|
try:
|
||||||
|
expected = _CONTAINS_POTENTIAL_PROJECT in os.listdir(path)
|
||||||
|
except OSError:
|
||||||
|
expected = False
|
||||||
|
|
||||||
|
assert _is_potential_project(path) == expected
|
||||||
|
|||||||
Reference in New Issue
Block a user