Skip to content

Pipenv install throws Value is not a valid boolean-like error for truthy CI environment variables #5554

@jodem1

Description

@jodem1

Issue description

When installing dependencies with pipenv inside a Woodpecker pipeline the job fails with the following error: ValueError: Value is not a valid boolean-like: woodpecker when the following environment variable (default for woodpecker) is set: CI=woodpecker

Expected result

The pipenv installation step should not fail when the environment variable CI is set to a truthy value like "woodpecker".

Actual result

The installation step fails because pipenv treats "woodpecker" not as a truthy environment variable value.

Full output:

installing pipenv...
done! ✨ 🌟 ✨
  installed package pipenv 2022.11.30, installed using Python 3.8.12
  These apps are now globally available
    - pipenv
    - pipenv-resolver
+ pipenv install --dev --skip-lock
Error in sys.excepthook:
Traceback (most recent call last):
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/exceptions.py", line 35, in handle_exception
    if environments.Setting().is_verbose() or not issubclass(exc_type, ClickException):
AttributeError: module 'pipenv.environments' has no attribute 'Setting'

Original exception was:
Traceback (most recent call last):
  File "/root/.local/bin/pipenv", line 5, in <module>
    from pipenv import cli
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/__init__.py", line 58, in <module>
    from .cli import cli
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/cli/__init__.py", line 1, in <module>
    from .command import cli  # noqa
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/cli/command.py", line 4, in <module>
    from pipenv import environments
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/environments.py", line 80, in <module>
    PIPENV_IS_CI = is_env_truthy("CI") or is_env_truthy("TF_BUILD")
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/utils/shell.py", line 419, in is_env_truthy
    return env_to_bool(os.getenv(name, False))
  File "/root/.local/pipx/venvs/pipenv/lib/python3.8/site-packages/pipenv/utils/shell.py", line 414, in env_to_bool
    raise ValueError(f"Value is not a valid boolean-like: {val}")
ValueError: Value is not a valid boolean-like: woodpecker

Steps to replicate

Set the environment value CI to a "truthy" value other than "1", "true", "yes", "on".

Currently, pipenv uses is_env_truthy (https://github.com/pypa/pipenv/blob/main/pipenv/environments.py#L80) which itself calls env_to_bool to decide if the CI env variable is truthy. True values are currently restricted in the constant TRUE_VALUES = ("1", "true", "yes", "on").

In a comment for the method is_env_truthy it says "An environment variable is truthy if it exists and isn't one of (0, false, no, off)" (which would be, imo, the correct and expected behavior) which contradicts the implemented logic.

I found this related Issue: #5128

On nov 2 there was a refactoring of said methods: 38813b9

Metadata

Metadata

Assignees

Labels

Type: Enhancement 💡This is a feature or enhancement request.Type: RegressionThis issue is a regression of a previous behavior.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions