question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation and implementation of disabling pipenv environment variable configuration

See original GitHub issue

Issue description

Pipenv can be configured via environment variables, such as PIPENV_IGNORE_VIRTUALENVS. Many of these configuration options are clearly boolean. The way for users to selectively enable or disable these options is not sufficiently documented and is perhaps buggy.

To activate them, simply create the variable in your shell and pipenv will detect it.

it doesn’t say how to deactivate an option (see Actual Result) below

Check the environment for a variable, returning its truthy or stringified value

For example, setting PIPENV_NO_RESOLVE_VCS=1 would mean that get_from_env(“RESOLVE_VCS”, prefix=“PIPENV”) would return False.

the behavior of get_from_env is much more like how other command line tools process environment variable options, however it appears unused within the codebase (except to check PIP_ environment variables)

Motivation

I had an issue where I was running pipenv inside a virtualenv and had PIPENV_IGNORE_VIRTUALENVS=0, intending to not enable this option. I was surprised when running pipenv --venv it would not detect my virtualenv. I found the reason was that pipenv read PIPENV_IGNORE_VIRTUALENVS from os.environ and determined it was °enabled*: https://github.com/pypa/pipenv/blob/97a49e83e69c26e40f76a8b471435c3d43c1bad3/pipenv/environments.py#L168

$ export PIPENV_IGNORE_VIRTUALENVS=0
$ python -c 'import os;print(bool(os.environ.get("PIPENV_IGNORE_VIRTUALENVS")))'
True

Expected result

If a user provides a falsy value for a boolean configuration option such as PIPENV_IGNORE_VIRTUALENVS, that option should be disabled

export PIPENV_IGNORE_VIRTUALENVS=0
# expect to be disabled (actually enabled)

Actual result

If a user provides any non-empty value for a boolean configuration option, that option is enabled. Based on the implementation in pipenv.environments.Setting, the only way to explicitly disable an option is to unset the variable or set it to the empty string

export PIPENV_IGNORE_VIRTUALENVS=
# disabled
export PIPENV_IGNORE_VIRTUALENVS=1 && unset PIPENV_IGNORE_VIRTUALENVS
# disabled

Suggested resolution

  • option 1 (easiest): add a sentence to the various places in the docs where configuration via environment variables is discussed indicating that falsy values still enable the option and how to disable an option. also recommended: delete get_from_env entirely from the docs so readers are not confused
  • option 2: change pipenv.environments.Setting to use pipenv.environments.get_from_env -> this would not be a breaking change necessarily because the behavior of pipenv when options are set like PIPENV_IGNORE_VIRTUALENVS=0 is not specified, however the behavior of pipenv would change as a result

I prefer 2 because it brings pipenv more in line with user expected behavior and behavior of other command line tools. I am happy to create a PR for either 2 or 1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
matteiuscommented, Oct 13, 2022

I vote for Option 2 and even if we did option 1 (improve docs) I don’t think we should remove that utility, I seem to recall it being used in some places.

0reactions
micahjsmithcommented, Nov 4, 2022

Closed by #5451

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage of Pipenv — pipenv 11.7.2 documentation
To use Pipenv with a Conda–provided Python, you simply provide the path to ... in project/.venv by setting the PIPENV_VENV_IN_PROJECT environment variable.
Read more >
pipenv Documentation - Read the Docs
This shell can be deactivated by using exit. run will run a given command from the virtualenv, with any arguments forwarded (e.g. $...
Read more >
Advanced Usage of Pipenv - Python Packaging Authority
Control various settings of pipenv via environment variables. PIPENV_CACHE_DIR¶. Location for Pipenv to store it's package cache. Default is to use appdir's ...
Read more >
python 3.x - Deactivate a pipenv environment - Stack Overflow
pipenv starts a new shell session with the virtualenv pathing instead of changing the pathing in the current shell session. That is why ......
Read more >
Pipenv & Virtual Environments
This tutorial walks you through installing and using Python packages. It will show you how to install and use the necessary tools and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found