Skip to content

Commit

Permalink
Allow quieting the output of pipenv run and .env loading. (#5006)
Browse files Browse the repository at this point in the history
* Restore this message as stderr because it affects requirements.txt generation.

* Only load the dotenv file when its a real file and thus only print the message when its present.

* Add news fragment.

* Allow quieting the output of install and .env loading.

* Missed this spot in th test to convert back.

* Add news fragment for quiet run option.
  • Loading branch information
matteius committed Mar 23, 2022
1 parent 7f05d65 commit 441c3e7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions news/4027.feature.rst
@@ -0,0 +1,2 @@
It is now possible to silence the ``Loading .env environment variables`` message on ``pipenv run``
with the ``--quiet`` flag or the `PIPENV_QUIET` environment variable.
13 changes: 7 additions & 6 deletions pipenv/cli/command.py
Expand Up @@ -410,7 +410,13 @@ def run(state, command, args):
"""Spawns a command installed into the virtualenv."""
from ..core import do_run
do_run(
state.project, command=command, args=args, three=state.three, python=state.python, pypi_mirror=state.pypi_mirror
state.project,
command=command,
args=args,
three=state.three,
python=state.python,
pypi_mirror=state.pypi_mirror,
quiet=state.quiet
)


Expand Down Expand Up @@ -444,11 +450,6 @@ def run(state, command, args):
" vulnerabilities database. Leave blank for scanning against a"
" database that only updates once a month.",
)
@option(
"--quiet",
is_flag=True,
help="Quiet standard output, except vulnerability report."
)
@common_options
@system_option
@pass_state
Expand Down
1 change: 1 addition & 0 deletions pipenv/cli/options.py
Expand Up @@ -408,6 +408,7 @@ def validate_pypi_mirror(ctx, param, value):
def common_options(f):
f = pypi_mirror_option(f)
f = verbose_option(f)
f = quiet_option(f)
f = clear_option(f)
f = three_option(f)
f = python_option(f)
Expand Down
8 changes: 4 additions & 4 deletions pipenv/core.py
Expand Up @@ -94,7 +94,7 @@ def do_clear(project):
raise


def load_dot_env(project, as_dict=False):
def load_dot_env(project, as_dict=False, quiet=False):
"""Loads .env file into sys.environ."""
if not project.s.PIPENV_DONT_LOAD_ENV:
# If the project doesn't exist yet, check current directory for a .env file
Expand All @@ -115,7 +115,7 @@ def load_dot_env(project, as_dict=False):
)
if as_dict:
return dotenv.dotenv_values(dotenv_file)
elif os.path.isfile(dotenv_file):
elif os.path.isfile(dotenv_file) and not quiet:
click.echo(
crayons.normal(fix_utf8("Loading .env environment variables..."), bold=True),
err=True,
Expand Down Expand Up @@ -2442,7 +2442,7 @@ def do_run_posix(project, script, command, env):
)


def do_run(project, command, args, three=None, python=False, pypi_mirror=None):
def do_run(project, command, args, three=None, python=False, pypi_mirror=None, quiet=False):
"""Attempt to run command either pulling from project or interpreting as executable.
Args are appended to the command in [scripts] section of project if found.
Expand All @@ -2454,7 +2454,7 @@ def do_run(project, command, args, three=None, python=False, pypi_mirror=None):
project, three=three, python=python, validate=False, pypi_mirror=pypi_mirror,
)

load_dot_env(project)
load_dot_env(project, quiet=quiet)
env = os.environ.copy()
env.pop("PIP_SHIMS_BASE_MODULE", None)

Expand Down

0 comments on commit 441c3e7

Please sign in to comment.