Documentation and implementation of disabling pipenv environment variable configuration
See original GitHub issueIssue 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.
- underspecified: https://pipenv.pypa.io/en/latest/advanced/#configuration-with-environment-variables says
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
- confusing/possibly buggy https://pipenv.pypa.io/en/latest/advanced/#pipenv.environments.get_from_env describes a different behavior, implying truthiness is determined from string values and has a kwarg for
check_for_negation
implying thatPIPENV_NO_X=1
would disable a variable
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 usepipenv.environments.get_from_env
-> this would not be a breaking change necessarily because the behavior of pipenv when options are set likePIPENV_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:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
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.
Closed by #5451