diff --git a/news/5003.bugfix.rst b/news/5003.bugfix.rst new file mode 100644 index 00000000..6a5af223 --- /dev/null +++ b/news/5003.bugfix.rst @@ -0,0 +1,2 @@ +The text ``Loading .env environment variables...`` has been switched back to stderr as to not +break requirements.txt generation. Also it only prints now when a ``.env`` file is actually present. diff --git a/pipenv/core.py b/pipenv/core.py index f61e49a4..8ebf8c48 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -115,13 +115,13 @@ def load_dot_env(project, as_dict=False): ) if as_dict: return dotenv.dotenv_values(dotenv_file) - else: + elif os.path.isfile(dotenv_file): click.echo( crayons.normal(fix_utf8("Loading .env environment variables..."), bold=True), - err=False, + err=True, ) dotenv.load_dotenv(dotenv_file, override=True) - project.s.initialize() + project.s.initialize() def cleanup_virtualenv(project, bare=True): diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 2cd6220d..e1235f54 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -457,7 +457,7 @@ def test_outdated_setuptools_with_pep517_legacy_build_meta_is_updated(PipenvInst assert c.returncode == 0 c = p.pipenv("run python -c 'import setuptools; print(setuptools.__version__)'") assert c.returncode == 0 - assert c.stdout.splitlines()[1] == "40.2.0" + assert c.stdout.strip() == "40.2.0" c = p.pipenv("install legacy-backend-package") assert c.returncode == 0 assert "vistir" in p.lockfile["default"] @@ -481,7 +481,7 @@ def test_outdated_setuptools_with_pep517_cython_import_in_setuppy(PipenvInstance assert c.returncode == 0 c = p.pipenv("run python -c 'import setuptools; print(setuptools.__version__)'") assert c.returncode == 0 - assert c.stdout.splitlines()[1] == "40.2.0" + assert c.stdout.strip() == "40.2.0" c = p.pipenv("install cython-import-package") assert c.returncode == 0 assert "vistir" in p.lockfile["default"] diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index f3d63407..1ad60a2a 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -189,7 +189,7 @@ def test_run_in_virtualenv_with_global_context(PipenvInstance, virtualenv): c = p.pipenv("run python -c 'import click;print(click.__file__)'") assert c.returncode == 0, (c.stdout, c.stderr) - assert is_in_path(c.stdout.splitlines()[1], str(virtualenv)), (c.stdout.splitlines()[1], str(virtualenv)) + assert is_in_path(c.stdout.strip(), str(virtualenv)), (c.stdout.strip(), str(virtualenv)) c = p.pipenv("clean --dry-run") assert c.returncode == 0, (c.stdout, c.stderr) @@ -210,7 +210,7 @@ def test_run_in_virtualenv(PipenvInstance): assert c.returncode == 0 c = p.pipenv('run python -c "import click;print(click.__file__)"') assert c.returncode == 0 - assert normalize_path(c.stdout.splitlines()[1]).startswith( + assert normalize_path(c.stdout.strip()).startswith( normalize_path(str(project.virtualenv_location)) ) c = p.pipenv("clean --dry-run") diff --git a/tests/integration/test_run.py b/tests/integration/test_run.py index a665b6a0..b0b8bbc0 100644 --- a/tests/integration/test_run.py +++ b/tests/integration/test_run.py @@ -36,12 +36,12 @@ multicommand = "bash -c \"cd docs && make html\"" assert c.returncode == 0 c = p.pipenv('run printfoo') assert c.returncode == 0 - assert c.stdout.splitlines()[1] == 'foo' + assert c.stdout.strip() == 'foo' assert not c.stderr.strip() c = p.pipenv('run notfoundscript') assert c.returncode != 0 - assert c.stdout == 'Loading .env environment variables...\n' + assert c.stdout == '' if os.name != 'nt': # TODO: Implement this message for Windows. assert 'not found' in c.stderr @@ -60,7 +60,7 @@ multicommand = "bash -c \"cd docs && make html\"" c = p.pipenv("run scriptwithenv") assert c.returncode == 0 if os.name != "nt": # This doesn't work on CI windows. - assert c.stdout.splitlines()[1] == "WORLD" + assert c.stdout.strip() == "WORLD" @pytest.mark.run @@ -80,5 +80,5 @@ def test_run_with_usr_env_shebang(PipenvInstance): c = p.pipenv("run ./test_script") assert c.returncode == 0 project = Project() - lines = [line.strip() for line in c.stdout.splitlines()[1:]] + lines = [line.strip() for line in c.stdout.splitlines()] assert all(line == project.virtualenv_location for line in lines)