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

Check environment variable PIPENV_CUSTOM_VENV_NAME #5203

Merged
merged 11 commits into from
Aug 4, 2022

Conversation

otherjake
Copy link
Contributor

Resolves #1226

Allows user to set a custom venv name

The fix

Check for PIPENV_CUSTOM_VENV_NAME environment variable, accept it as venv name at creation if it is set

Copy link
Contributor

@oz123 oz123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of asking os.getenv directly, we should go through:

self.s.PIPENV_CUSTOM_VENV_NAME

All settings are found in environments.Settings class.
Using this class conventions is also to document the variable, as other variables are documented there.

@oz123
Copy link
Contributor

oz123 commented Jul 30, 2022

Setting PIPENV_CUSTOM_VENV_NAME is going to trick a lot of people if we don't preserve it in Pipefile.

Suppose I did:
export PIPENV_CUSTOM_VENV_NAME=foobar

Now there is:

home/myuser/.virtualenvs/foobar`

If I run pipenv in a new shell it's not going to have PIPENV_CUSTOM_VENV_NAME, hence it will look for an environment
in the hash location, and not in foobar. Hence, I suggest we preserve this in the Pipfile, and read it from there.

@matteius do you have an opinion here?

@matteius
Copy link
Member

matteius commented Aug 2, 2022

Setting PIPENV_CUSTOM_VENV_NAME is going to trick a lot of people if we don't preserve it in Pipefile.

@oz123 I am not sure I agree with that approach when its much easier to have a .env file to store the environment variable you want to use for that project -- I fear that if its in the Pipfile it forces everyone on the project to have the same virtualenv name, and some may want the default generated one whereas others want to customize it -- a local .env solves this. Otherwise I might already have a virtualenv setup and my teammate pushes that change to the Pipfile which forces my machine to generate a new virtualenv under this other name.

@otherjake
Copy link
Contributor Author

I am considering putting self.s.PIPENV_CUSTOM_VENV_NAME into activate in environment.py, that seems like the creating a venv context level that this is appropriate to. Waiting for more consensus around the pipfile bit.

@matteius
Copy link
Member

matteius commented Aug 2, 2022

I am considering putting self.s.PIPENV_CUSTOM_VENV_NAME into activate in environment.py

@otherjake The reading of the environment variable should happen in environments.py where the other environment variables are read from.

@oz123
Copy link
Contributor

oz123 commented Aug 2, 2022

@matteius true. Putting it in .env is the correct way. Totally forgot we support this.

docs/advanced.rst Outdated Show resolved Hide resolved
@oz123
Copy link
Contributor

oz123 commented Aug 3, 2022

This obsoletes, #4974. This is a reminder for us to make sure we close that one too.

Copy link
Member

@matteius matteius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @otherjake !

This is so that PIPENV_CUSTOM_VENV_NAME does not leak to
other tests.
@oz123
Copy link
Contributor

oz123 commented Aug 4, 2022

@otherjake Thank you for your contribution! I added a small change to your test. Didn't want to bother you again with changes.
Please take a look at it.

Besides that, as usual 💯 points and a big thanks!

@oz123 oz123 merged commit ca38db6 into pypa:main Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to set the full name of the virtualenv created
3 participants