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

Allow quieting the output of pipenv run and .env loading. #5006

Merged
merged 8 commits into from
Mar 23, 2022
2 changes: 2 additions & 0 deletions news/4027.feature.rst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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