Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch 'PermissionError' for unreadable directories #1706

Merged
merged 4 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions jedi/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ def __repr__(self):

def _is_potential_project(path):
for name in _CONTAINS_POTENTIAL_PROJECT:
if path.joinpath(name).exists():
return True
try:
if path.joinpath(name).exists():
return True
except OSError:
continue
return False


Expand Down
7 changes: 5 additions & 2 deletions jedi/inference/sys_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ def _get_paths_from_buildout_script(inference_state, buildout_script_path):

def _get_parent_dir_with_file(path: Path, filename):
for parent in path.parents:
if parent.joinpath(filename).is_file():
return parent
try:
if parent.joinpath(filename).is_file():
return parent
except OSError:
continue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

return None


Expand Down
19 changes: 19 additions & 0 deletions test/test_api/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..helpers import get_example_dir, set_cwd, root_dir, test_dir
from jedi import Interpreter
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):
Expand Down Expand Up @@ -160,3 +161,21 @@ def test_complete_search(Script, string, completions, all_scopes):
project = Project(test_dir)
defs = project.complete_search(string, all_scopes=all_scopes)
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