From 344fef1e2f97e0a935fa8c60dc71b50b0aa778fd Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 27 Jun 2020 00:43:19 +0200 Subject: [PATCH] Add Project.path, fixes #1622 --- CHANGELOG.rst | 1 + jedi/api/file_name.py | 2 +- jedi/api/project.py | 7 +++++++ jedi/api/refactoring/__init__.py | 4 ++-- jedi/inference/imports.py | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3c26004c..d7b6f388 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,7 @@ Unreleased ++++++++++ - Added an option to pass environment variables to ``Environment`` +- ``Project(...).path`` exists now 0.17.1 (2020-06-20) +++++++++++++++++++ diff --git a/jedi/api/file_name.py b/jedi/api/file_name.py index 0a2161a3..4d472453 100644 --- a/jedi/api/file_name.py +++ b/jedi/api/file_name.py @@ -36,7 +36,7 @@ def complete_file_name(inference_state, module_context, start_leaf, quote, strin is_in_os_path_join = False else: string = to_be_added + string - base_path = os.path.join(inference_state.project._path, string) + base_path = os.path.join(inference_state.project.path, string) try: listed = sorted(scandir(base_path), key=lambda e: e.name) # OSError: [Errno 36] File name too long: '...' diff --git a/jedi/api/project.py b/jedi/api/project.py index a2b7c4c1..d506aae7 100644 --- a/jedi/api/project.py +++ b/jedi/api/project.py @@ -150,6 +150,13 @@ class Project(object): py2_comp(path, **kwargs) + @property + def path(self): + """ + The base path for this project. + """ + return self._path + @inference_state_as_method_param_cache() def _get_base_sys_path(self, inference_state): # The sys path has not been set explicitly. diff --git a/jedi/api/refactoring/__init__.py b/jedi/api/refactoring/__init__.py index f05517d2..d0f7a7b8 100644 --- a/jedi/api/refactoring/__init__.py +++ b/jedi/api/refactoring/__init__.py @@ -39,7 +39,7 @@ class ChangedFile(object): if new_lines[-1] != '': new_lines[-1] += '\n' - project_path = self._inference_state.project._path + project_path = self._inference_state.project.path if self._from_path is None: from_p = '' else: @@ -112,7 +112,7 @@ class Refactoring(object): def get_diff(self): text = '' - project_path = self._inference_state.project._path + project_path = self._inference_state.project.path for from_, to in self.get_renames(): text += 'rename from %s\nrename to %s\n' \ % (relpath(from_, project_path), relpath(to, project_path)) diff --git a/jedi/inference/imports.py b/jedi/inference/imports.py index 926d05ef..8eca36ab 100644 --- a/jedi/inference/imports.py +++ b/jedi/inference/imports.py @@ -192,7 +192,7 @@ class Importer(object): import_path = base + tuple(import_path) else: path = module_context.py__file__() - project_path = self._inference_state.project._path + project_path = self._inference_state.project.path import_path = list(import_path) if path is None: # If no path is defined, our best guess is that the current