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

Environment path doesn't expand user directory #393

Closed
odiroot opened this issue Jun 12, 2023 · 2 comments · Fixed by #394
Closed

Environment path doesn't expand user directory #393

odiroot opened this issue Jun 12, 2023 · 2 comments · Fixed by #394
Assignees
Milestone

Comments

@odiroot
Copy link
Contributor

odiroot commented Jun 12, 2023

Previously raised for Jedi project but deemed irrelevant at their level.

When using Virtualenvwrapper, or just for convenience keeping all the virtual Python environments in one directory, it's not possible to
to use user home directory references in pylsp.plugins.jedi.environment. E.g. ~/.virtualenvs/myenv1.

Neither python-lsp-server nor Jedi don't expand ~.

This is a small thing but prevents effective sharing of dev environments between users (because the username would have to be explicitly hardcoded here).

I suggest using os.path.expanduser in this function:

@lock
def jedi_script(self, position=None, use_document_path=False):
extra_paths = []
environment_path = None
env_vars = None
if self._config:
jedi_settings = self._config.plugin_settings('jedi', document_path=self.path)
jedi.settings.auto_import_modules = jedi_settings.get('auto_import_modules',
DEFAULT_AUTO_IMPORT_MODULES)
environment_path = jedi_settings.get('environment')
extra_paths = jedi_settings.get('extra_paths') or []
env_vars = jedi_settings.get('env_vars')
# Drop PYTHONPATH from env_vars before creating the environment because that makes
# Jedi throw an error.
if env_vars is None:
env_vars = os.environ.copy()
env_vars.pop('PYTHONPATH', None)
environment = self.get_enviroment(environment_path, env_vars=env_vars) if environment_path else None

@ccordoba12
Copy link
Member

Hey @odiroot, thanks for reporting. Ok, I'm fine with this suggestion, so please submit a pull request for it.

My only recommendation is to make this work only for non-Windows systems (i.e. if not os.name == 'nt') because I think the tilde (~) doesn't map to HOME there.

@odiroot
Copy link
Contributor Author

odiroot commented Jun 13, 2023

Hi @ccordoba12
Thanks. According to the documentation, it shouldn't be breaking anything on Windows. But as you suggest, this is somewhat an unexpected thing so I can add that check.

@ccordoba12 ccordoba12 added this to the v1.7.4 milestone Jun 13, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jul 5, 2023
## Version 1.7.4 (2023/06/29)

### Issues Closed

* [Issue 393](python-lsp/python-lsp-server#393) - Environment path doesn't expand user directory

In this release 1 issue was closed.

### Pull Requests Merged

* [PR 394](python-lsp/python-lsp-server#394) - Resolve homedir references in Jedi environment path, by [@odiroot](https://github.com/odiroot)
* [PR 381](python-lsp/python-lsp-server#381) - Report progress even when initialization fails, by [@syphar](https://github.com/syphar)
* [PR 380](python-lsp/python-lsp-server#380) - Fix pylint hang on file with many errors, by [@hetmankp](https://github.com/hetmankp)

In this release 3 pull requests were closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants