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

False-positive checks for Miniconda base environment (prevents shadowing by other virtual environments) #2562

Open
3 tasks done
Dominik1123 opened this issue Jun 16, 2020 · 1 comment
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@Dominik1123
Copy link

  • 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 (-vvv option).
  • 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"
@Dominik1123 Dominik1123 added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 16, 2020
@stefanoborini
Copy link

I am having the same problem with a simple venv python environment, which is activated, but poetry refuses to use it. I also confirm the same origin of the problem.

@finswimmer finswimmer added the area/venv Related to virtualenv management label Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants