forked from VimPlug/jedi
Make sure that you can select virtualenvs more precisely, fixes #1407
This commit is contained in:
@@ -261,34 +261,37 @@ def find_virtualenvs(paths=None, **kwargs):
|
|||||||
"""
|
"""
|
||||||
:param paths: A list of paths in your file system to be scanned for
|
:param paths: A list of paths in your file system to be scanned for
|
||||||
Virtualenvs. It will search in these paths and potentially execute the
|
Virtualenvs. It will search in these paths and potentially execute the
|
||||||
Python binaries. Also the VIRTUAL_ENV variable will be checked if it
|
Python binaries.
|
||||||
contains a valid Virtualenv. And CONDA_PREFIX will be checked to see
|
|
||||||
if it contains a valid conda environment.
|
|
||||||
:param safe: Default True. In case this is False, it will allow this
|
:param safe: Default True. In case this is False, it will allow this
|
||||||
function to execute potential `python` environments. An attacker might
|
function to execute potential `python` environments. An attacker might
|
||||||
be able to drop an executable in a path this function is searching by
|
be able to drop an executable in a path this function is searching by
|
||||||
default. If the executable has not been installed by root, it will not
|
default. If the executable has not been installed by root, it will not
|
||||||
be executed.
|
be executed.
|
||||||
|
:param use_environment_vars: Default True. If True, the VIRTUAL_ENV
|
||||||
|
variable will be checked if it contains a valid VirtualEnv.
|
||||||
|
CONDA_PREFIX will be checked to see if it contains a valid conda
|
||||||
|
environment.
|
||||||
|
|
||||||
:yields: :class:`Environment`
|
:yields: :class:`Environment`
|
||||||
"""
|
"""
|
||||||
def py27_comp(paths=None, safe=True):
|
def py27_comp(paths=None, safe=True, use_environment_vars=True):
|
||||||
if paths is None:
|
if paths is None:
|
||||||
paths = []
|
paths = []
|
||||||
|
|
||||||
_used_paths = set()
|
_used_paths = set()
|
||||||
|
|
||||||
# Using this variable should be safe, because attackers might be able
|
if use_environment_vars:
|
||||||
# to drop files (via git) but not environment variables.
|
# Using this variable should be safe, because attackers might be
|
||||||
virtual_env = _get_virtual_env_from_var()
|
# able to drop files (via git) but not environment variables.
|
||||||
if virtual_env is not None:
|
virtual_env = _get_virtual_env_from_var()
|
||||||
yield virtual_env
|
if virtual_env is not None:
|
||||||
_used_paths.add(virtual_env.path)
|
yield virtual_env
|
||||||
|
_used_paths.add(virtual_env.path)
|
||||||
|
|
||||||
conda_env = _get_virtual_env_from_var(_CONDA_VAR)
|
conda_env = _get_virtual_env_from_var(_CONDA_VAR)
|
||||||
if conda_env is not None:
|
if conda_env is not None:
|
||||||
yield conda_env
|
yield conda_env
|
||||||
_used_paths.add(conda_env.path)
|
_used_paths.add(conda_env.path)
|
||||||
|
|
||||||
for directory in paths:
|
for directory in paths:
|
||||||
if not os.path.isdir(directory):
|
if not os.path.isdir(directory):
|
||||||
|
|||||||
Reference in New Issue
Block a user