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

"Loading .env environment variables..." prints to stderr, causing all sorts of havoc #6111

Open
brandonscript opened this issue Mar 12, 2024 · 3 comments
Labels
brainstorm Contributor Candidate The issue has been identified/triaged and contributions are welcomed/encouraged. quiet

Comments

@brandonscript
Copy link

brandonscript commented Mar 12, 2024

Be sure to check the existing issues (both open and closed!), and make sure you are running the latest version of Pipenv.

Check the diagnose documentation for common issues before posting! We may close your issue if it is very similar to one of them. Please be considerate, or be on your way.

Make sure to mention your debugging experience if the documented solution failed.

Issue description

When a .env file is present in a working dir, pipenv prints out

Loading .env environment variables...

to stderr instead of stdout – causing the process to return with an exit code of 1, even if the process actually succeeded. Setting PIPENV_VERBOSITY=-1 suppresses some of the other messages, like the warning about running inside a virtual env (which also writes to stderr), but it does not remove the .env message.

It also does pipes the courtesy notice about running inside a virtualenv to stderr as well (this one I could probably understand and live with, though there doesn't seem to be a way to suppress this either).

Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.

Expected result

pipenv should not write anything to stdout unless it is an actual error or failure.

Actual result

The informational text is piped to stderr.

Steps to replicate

Provide the steps to replicate (which usually at least includes the commands and the Pipfile).


You can reproduce this by creating a simple requirements.txt file in a dir, a Pipfile in a dir, and a .env file in a dir, then running:

import subprocess

subprocess.check_output("PIPENV_VERBOSITY=-1 pipenv run pip install -r requirements.txt", shell=True)

CleanShot 2024-03-12 at 10 51 18@2x

@matteius matteius added the Contributor Candidate The issue has been identified/triaged and contributions are welcomed/encouraged. label Mar 21, 2024
@matteius
Copy link
Member

There are reasons we print some things to standard error over standard out, take generating a requirements file for example, you want to be able to pipe that to standard out without the other logging that pipenv does. However I think I more could be done to tune down logging when requested via these flags and env vars.

@Kroppeb
Copy link

Kroppeb commented Mar 24, 2024

causing the process to return with an exit code of 1

I can't seem to reproduce this. I'm on windows and the return code is 0. Is this a Linux thing?

@opkna
Copy link

opkna commented Jun 15, 2024

I'm guessing this is by design. And I don't think you are getting a non-zero return code, if you did you would get a CalledProcessError exception. I tried the same code and got a 0 return code. If you don't want to see that, add stderr=subprocess.DEVNULL to the check_output. Or use run to save both stdout and stderr.

But perhaps this output should be printed to stdout? (But of course omitted when running pipenv requirements for example). I think in general pipenv can be a bit repetitive when it comes to the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brainstorm Contributor Candidate The issue has been identified/triaged and contributions are welcomed/encouraged. quiet
Projects
None yet
Development

No branches or pull requests

4 participants