Skip to content

Check environment variable PIPENV_CUSTOM_VENV_NAME - #5203

Merged
oz123 merged 11 commits into
pypa:mainfrom
otherjake:4974-custom-venv-name
Aug 4, 2022
Merged

oz123 merged 11 commits into
pypa:mainfrom
otherjake:4974-custom-venv-name

Conversation

@otherjake

Copy link
Copy Markdown
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

@oz123 oz123 left a comment

Copy link
Copy Markdown
Contributor

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

oz123 commented Jul 30, 2022

Copy link
Copy Markdown
Contributor

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

matteius commented Aug 2, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

matteius commented Aug 2, 2022

Copy link
Copy Markdown
Member

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

oz123 commented Aug 2, 2022

Copy link
Copy Markdown
Contributor

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

Comment thread docs/advanced.rst Outdated
@oz123

oz123 commented Aug 3, 2022

Copy link
Copy Markdown
Contributor

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

@matteius matteius left a comment

Copy link
Copy Markdown
Member

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

oz123 commented Aug 4, 2022

Copy link
Copy Markdown
Contributor

@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