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

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

Closed
jodem1 opened this issue Dec 23, 2022 · 10 comments · Fixed by #5591
Assignees
Labels
Type: Enhancement 💡 This is a feature or enhancement request. Type: Regression This issue is a regression of a previous behavior.

Comments

@jodem1
Copy link

jodem1 commented Dec 23, 2022

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

@matteius
Copy link
Member

@jodem1 You found the intentional refactoring of the said methods -- to us, woodpecker isn't any more truthy than the string false. Is there a real reason you have to se the CI value to woodpecker?

@jodem1
Copy link
Author

jodem1 commented Dec 23, 2022

Thank you for the quick reply.

This value is set as a default built-in environment variable by Woodpecker. We do not rely on this particular value, but we use Codeberg CI for our pipeline, and they use Woodpecker as CI solution. Therefore, we do not have direct access to the server configuration of said variable, for now we have to override and expand the variable in every job that makes a pipenv install call to prevent it from failing.

@matteius matteius added Type: Enhancement 💡 This is a feature or enhancement request. Type: Regression This issue is a regression of a previous behavior. labels Dec 23, 2022
@6543
Copy link

6543 commented Dec 23, 2022

@allanlewis
Copy link
Contributor

allanlewis commented Jan 6, 2023

Pipenv also complains when CI is set to an empty string - surely this could be considered "falsey" too?

I've raised #5564 for the empty string case.

@matteius matteius self-assigned this Jan 15, 2023
@oz123
Copy link
Contributor

oz123 commented Jan 21, 2023

I think we could make an exception for "thruty" values for the CI variable.
I don't think this exception should be extended to empty CI value.
So the following are going to happen:

CI={woodpacker, banjo, jenkins} -> true
CI= -> exception.

@matteius
Copy link
Member

matteius commented Feb 4, 2023

I think the PR I opened handles both this case and the case where CI is set but empty, because it would return its own value which would be empty and not evaluate to true -- if you want to confirm that @allanlewis by reviewing the PR.

@allanlewis
Copy link
Contributor

I think the PR I opened handles both this case and the case where CI is set but empty, because it would return its own value which would be empty and not evaluate to true -- if you want to confirm that @allanlewis by reviewing the PR.

Which PR is that?

@oz123
Copy link
Contributor

oz123 commented Feb 6, 2023

#5591

@allanlewis
Copy link
Contributor

#5591

@oz123 That PR has already been merged...

If it's the case that an empty value for CI will now be treated as false, then that's great. Presumably the documentation will be updated to reflect the current state of affairs?

@matteius
Copy link
Member

pipenv==2023.2.18 has been released with this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement 💡 This is a feature or enhancement request. Type: Regression This issue is a regression of a previous behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants