Skip to content

Environment path doesn't expand user directory #393

Closed
@odiroot

Description

@odiroot

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions