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

How can I ignore the 'VIRTUAL_ENV' environment variable? #281

Closed
1 task done
jacebrowning opened this issue Jul 5, 2018 · 9 comments
Closed
1 task done

How can I ignore the 'VIRTUAL_ENV' environment variable? #281

jacebrowning opened this issue Jul 5, 2018 · 9 comments
Labels
area/venv Related to virtualenv management kind/feature Feature requests/implementations

Comments

@jacebrowning
Copy link
Contributor

jacebrowning commented Jul 5, 2018

  • I have searched the issues of this repo and believe that this is not a duplicate.

Issue

In my projects, I create the virtual environment in the project root ($ poetry config settings.virtualenvs.in-project true) so that I can explicitly manage dependencies and cache them between builds.

Travis CI runs builds inside of its own virtual environment (thus sets VIRTUAL_ENV).

The current logic consults VIRTUAL_ENV before any other settings: https://github.com/sdispater/poetry/blob/ae1773d68f341c34d9124353f7a952d5fd3cfefb/poetry/utils/venv.py#L47-L50

How can I tell poetry to ignore VIRTUAL_ENV and always create a virtual environment?

pipenv gets around this by adding another environment variable (PIPENV_IGNORE_VIRTUALENVS). but I think poetry can do better.


Proposal A

The default value of settings.virtualenvs.create is inferred from VIRTUAL_ENV (false if set, true if unset).

If the user runs $ poetry config settings.virtualenvs.create true then poetry will always create a virtual environment irrespective of VIRTUAL_ENV.

Proposal B

Add settings.virtualenvs.ignore-active to ignore VIRTUAL_ENV when creating a virtual environment.

Proposal C

If settings.virtualenvs.in-project is set and ./.venv/ does not exist then VIRTUAL_ENV is ignored.

@digitalresistor
Copy link
Contributor

@jacebrowning, run poetry while unsetting VIRTUAL_ENV:

env -u VIRTUAL_ENV poetry

Now even though you are "Inside" an virtual environment, poetry won't know about it.

@jacebrowning
Copy link
Contributor Author

@bertjwregeer Thanks for the tip. This actually results in the same behavior, but for a different reason.

Given this part of the Travis CI configuration:

cache:
  directories:
    - .venv
  1. Travis CI creates .venv from the (yet to exist) cached virtual environment.
  2. Poetry sees this empty .venv directory and incorreclty assumes the virtual environment has already been created.
  3. It them proceds to install dependencies globaly (also noted on Option to create virtual environments in the project root (.venv) #108), which is actually into Travis CI's existing virtual environment.
  4. The end result is that .venv is still empty, Travis CI caches the empty directory, and the cycle repeats.

@cauebs
Copy link
Contributor

cauebs commented Jul 6, 2018

Poetry sees this empty .venv directory and incorreclty assumes the virtual environment has already been created.

That's most definitely a bug!

@jacebrowning
Copy link
Contributor Author

jacebrowning commented Jul 6, 2018

I filed that here: #286

@stefanfoulis
Copy link

I am running into a related problem. I have poetry installed with pipsi (https://github.com/mitsuhiko/pipsi). Now poetry uses that isolated virtualenv that is only meant for the poetry command itself, instead of creating a new one.

@digitalresistor
Copy link
Contributor

@stefanfoulis #527

@sdispater sdispater added kind/feature Feature requests/implementations area/venv Related to virtualenv management labels Mar 2, 2019
@stale
Copy link

stale bot commented Nov 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 13, 2019
@stale
Copy link

stale bot commented Nov 20, 2019

Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.

Copy link

github-actions bot commented Mar 3, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/venv Related to virtualenv management kind/feature Feature requests/implementations
Projects
None yet
Development

No branches or pull requests

5 participants