From 757fc9a702bb81f210fa52aca4f38e8f44261bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Mee=C3=9Fen?= Date: Sat, 30 Sep 2023 21:44:34 +0200 Subject: [PATCH 1/2] set regular logging level to ERROR --- pipenv/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/utils/__init__.py b/pipenv/utils/__init__.py index 3359402c07..70f95c4fe1 100644 --- a/pipenv/utils/__init__.py +++ b/pipenv/utils/__init__.py @@ -2,7 +2,7 @@ from pipenv.patched.pip._vendor.rich.console import Console -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.ERROR) console = Console() err = Console(stderr=True) From 360100534fe6693ff4651c65a67933826f51b30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Mee=C3=9Fen?= Date: Mon, 2 Oct 2023 17:56:34 +0200 Subject: [PATCH 2/2] change logging level based on verbosity arg - add verbosity arg to check command, if verbosity if None (default), logging level is set to warn - create a build_options function in check.py for handling all arguments used to build the options string for pipenv check. Was needed because otherwise there were too many branches for the linter. --- README.md | 1 - pipenv/cli/command.py | 1 + pipenv/routines/check.py | 70 +++++++++++++++++++++++++++------------- pipenv/utils/__init__.py | 2 +- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 19036d5efa..ce90155097 100644 --- a/README.md +++ b/README.md @@ -337,4 +337,3 @@ Documentation resides over at [pipenv.pypa.io](https://pipenv.pypa.io/en/latest/ Star History Chart - diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 5e7d88a721..fb4ee0589d 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -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, diff --git a/pipenv/routines/check.py b/pipenv/routines/check.py index c2f5d12feb..a067a41e74 100644 --- a/pipenv/routines/check.py +++ b/pipenv/routines/check.py @@ -1,5 +1,6 @@ import io import json as simplejson +import logging import os import sys import tempfile @@ -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, @@ -21,6 +56,7 @@ def do_check( output="screen", key=None, quiet=False, + verbose=False, exit_code=True, policy_file="", save_json="", @@ -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( @@ -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"], @@ -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 diff --git a/pipenv/utils/__init__.py b/pipenv/utils/__init__.py index 70f95c4fe1..3359402c07 100644 --- a/pipenv/utils/__init__.py +++ b/pipenv/utils/__init__.py @@ -2,7 +2,7 @@ from pipenv.patched.pip._vendor.rich.console import Console -logging.basicConfig(level=logging.ERROR) +logging.basicConfig(level=logging.INFO) console = Console() err = Console(stderr=True)