Skip to content

Commit

Permalink
use sys_path method
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclary committed Feb 20, 2024
1 parent 4b405bc commit 0fedcae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions pylsp/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,8 @@ def jedi_script(self, position=None, use_document_path=False):

environment = self.get_enviroment(environment_path, env_vars=env_vars)

sys_path = list(self._extra_sys_path) + environment.get_sys_path()
if prioritize:
sys_path += extra_paths + sys_path
else:
sys_path += sys_path + extra_paths
sys_path = self.sys_path(environment_path, env_vars, prioritize, extra_paths)

project_path = self._workspace.root_path

# Extend sys_path with document's path if requested
Expand Down Expand Up @@ -573,14 +570,18 @@ def get_enviroment(self, environment_path=None, env_vars=None):

return environment

def sys_path(self, environment_path=None, env_vars=None):
# TODO: when safe to break API, remove this method.
def sys_path(self, environment_path=None, env_vars=None, prioritize=False, extra_paths=[]):
# Copy our extra sys path
path = list(self._extra_sys_path)
environment = self.get_enviroment(
environment_path=environment_path, env_vars=env_vars
)
path.extend(environment.get_sys_path())
if prioritize:
path += extra_paths + path
else:
path += path + extra_paths

return path


Expand Down
4 changes: 2 additions & 2 deletions test/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_non_root_project(pylsp, metafiles):
test_uri = uris.from_fs_path(os.path.join(project_root, "hello/test.py"))
pylsp.workspace.put_document(test_uri, "assert True")
test_doc = pylsp.workspace.get_document(test_uri)
assert project_root in test_doc.get_enviroment().get_sys_path()
assert project_root in test_doc.sys_path()


def test_root_project_with_no_setup_py(pylsp):
Expand All @@ -79,7 +79,7 @@ def test_root_project_with_no_setup_py(pylsp):
test_uri = uris.from_fs_path(os.path.join(workspace_root, "hello/test.py"))
pylsp.workspace.put_document(test_uri, "assert True")
test_doc = pylsp.workspace.get_document(test_uri)
assert workspace_root in test_doc.get_enviroment().get_sys_path()
assert workspace_root in test_doc.sys_path()


def test_multiple_workspaces_from_initialize(pylsp_w_workspace_folders):
Expand Down

0 comments on commit 0fedcae

Please sign in to comment.