python-poetry / python-poetry/poetry
False-positive checks for Miniconda base environment (prevents shadowing by other virtual environments)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
- I am on the latest Poetry version.
- I have searched the issues of this repo and believe that this is not a duplicate.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption).
- OS version and name: Ubuntu 16.04 LTS (
4.4.0-184-generic #214-Ubuntu SMP Thu Jun 4 10:14:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux) - Poetry version: 1.0.9
- Link of a Gist with the contents of your pyproject.toml file: If needed, you can use this one since it was the one with which I discovered the issue.
Issue
When the Miniconda "base" environment is active then Poetry won't allow shadowing by other environments, e.g. such as created by Nox. In my specific case, I ran a shell with Miniconda "base" active, then I ran tests through Nox where dependencies are installed via Poetry (see this for example; invoke via nox -s tests). Even though the Nox environment was active, Poetry refused to use it because it thought it is inside the Miniconda "base" environment (and hence Poetry created its own environment to install dependencies into). This comes from the following check:
# Check if we are inside a virtualenv or not
# Conda sets CONDA_PREFIX in its envs, see
# https://github.com/conda/conda/issues/2764
env_prefix = os.environ.get("VIRTUAL_ENV", os.environ.get("CONDA_PREFIX"))
conda_env_name = os.environ.get("CONDA_DEFAULT_ENV")
# It's probably not a good idea to pollute Conda's global "base" env, since
# most users have it activated all the time.
in_venv = env_prefix is not None and conda_env_name != "base"
Here in_venv is False no matter if the VIRTUAL_ENV variable is set, in case the Miniconda "base" environment is active too. Instead it should explicitly distinguish between VIRTUAL_ENV set or not when checking the CONDA_DEFAULT_ENV:
try:
env_prefix = os.environ["VIRTUAL_ENV"]
except KeyError:
env_prefix = os.environ.get("CONDA_PREFIX")
conda_env_name = os.environ.get("CONDA_DEFAULT_ENV")
else:
conda_env_name = None # This allows VIRTUAL_ENV to shadow the conda base.
in_venv = env_prefix is not None and conda_env_name != "base"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read poetry/utils/env.py at the linked environment check, then reproduce the report with a Miniconda base shell and the nox -s tests command. Done means the active Nox or virtual environment is not rejected merely because CONDA_DEFAULT_ENV is base; no specific test file is named in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100