Skip to content

Commit

Permalink
Merge pull request #5957 from fmssn/enhancement-5939-fix-noisy-output…
Browse files Browse the repository at this point in the history
…-pipenv-check

set regular logging level to ERROR
  • Loading branch information
matteius authored Oct 3, 2023
2 parents 0d91ab1 + 3601005 commit a725b20
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,3 @@ Documentation resides over at [pipenv.pypa.io](https://pipenv.pypa.io/en/latest/
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=pypa/pipenv&type=Date" />
</picture>
</a>

1 change: 1 addition & 0 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def check(
output=output,
key=key,
quiet=quiet,
verbose=state.verbose,
exit_code=exit_code,
policy_file=policy_file,
save_json=save_json,
Expand Down
70 changes: 48 additions & 22 deletions pipenv/routines/check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import json as simplejson
import logging
import os
import sys
import tempfile
Expand All @@ -12,6 +13,40 @@
from pipenv.vendor import click, plette


def build_options(
audit_and_monitor=True,
exit_code=True,
output="screen",
save_json="",
policy_file="",
safety_project=None,
temp_requirements_name="",
):
options = [
"--audit-and-monitor" if audit_and_monitor else "--disable-audit-and-monitor",
"--exit-code" if exit_code else "--continue-on-error",
]
formats = {"full-report": "--full-report", "minimal": "--json"}

if output in formats:
options.append(formats.get(output, ""))
elif output not in ["screen", "default"]:
options.append(f"--output={output}")

if save_json:
options.append(f"--save-json={save_json}")

if policy_file:
options.append(f"--policy-file={policy_file}")

if safety_project:
options.append(f"--project={safety_project}")

options.extend(["--file", temp_requirements_name])

return options


def do_check(
project,
python=False,
Expand All @@ -21,6 +56,7 @@ def do_check(
output="screen",
key=None,
quiet=False,
verbose=False,
exit_code=True,
policy_file="",
save_json="",
Expand All @@ -32,6 +68,9 @@ def do_check(
):
import json

if not verbose:
logging.getLogger("pipenv").setLevel(logging.WARN)

if not system:
# Ensure that virtualenv is available.
ensure_project(
Expand Down Expand Up @@ -120,27 +159,6 @@ def do_check(
else:
ignored = []

options = [
"--audit-and-monitor" if audit_and_monitor else "--disable-audit-and-monitor",
"--exit-code" if exit_code else "--continue-on-error",
]

formats = {"full-report": "--full-report", "minimal": "--json"}
if output in formats:
options.append(formats.get(output, ""))

elif output not in ["screen", "default"]:
options.append(f"--output={output}")

if save_json:
options.append(f"--save-json={save_json}")

if policy_file:
options.append(f"--policy-file={policy_file}")

if safety_project:
options.append(f"--project={safety_project}")

if use_installed:
target_venv_packages = run_command(
_cmd + ["-m", "pip", "list", "--format=freeze"],
Expand All @@ -165,7 +183,15 @@ def do_check(
temp_requirements.write(target_venv_packages.stdout.strip())
temp_requirements.close()

options.extend(["--file", temp_requirements.name])
options = build_options(
audit_and_monitor=audit_and_monitor,
exit_code=exit_code,
output=output,
save_json=save_json,
policy_file=policy_file,
safety_project=safety_project,
temp_requirements_name=temp_requirements.name,
)

cmd = _cmd + [safety_path, "check"] + options

Expand Down

0 comments on commit a725b20

Please sign in to comment.