From 441c3e7675e9d4b9ec129bb2c38a19122da77f79 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 23 Mar 2022 13:50:26 -0400 Subject: [PATCH] Allow quieting the output of pipenv run and .env loading. (#5006) * 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. --- news/4027.feature.rst | 2 ++ pipenv/cli/command.py | 13 +++++++------ pipenv/cli/options.py | 1 + pipenv/core.py | 8 ++++---- 4 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 news/4027.feature.rst diff --git a/news/4027.feature.rst b/news/4027.feature.rst new file mode 100644 index 00000000..1145c8a0 --- /dev/null +++ b/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. diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 71ce5820..c6470a6c 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -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 ) @@ -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 diff --git a/pipenv/cli/options.py b/pipenv/cli/options.py index e050746b..0ac9c2e5 100644 --- a/pipenv/cli/options.py +++ b/pipenv/cli/options.py @@ -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) diff --git a/pipenv/core.py b/pipenv/core.py index 8ebf8c48..b1e8d01e 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -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 @@ -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, @@ -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. @@ -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)