From 386340bead35e2480cff97c1b79c44a93a2db623 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 25 Jul 2018 15:45:43 +0800 Subject: [PATCH] Unify verbosity flags and environment variable --- pipenv/cli.py | 69 +++++++++++++++++++++++++++----------------------- pipenv/core.py | 15 +++-------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 1b774508..49722dae 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -61,12 +61,12 @@ class PipenvGroup(Group): ) -def setup_verbose(ctx, param, value): - if value: - import logging - - logging.getLogger("pip").setLevel(logging.INFO) - return value +def setup_verbosity(ctx, param, value): + if not value: + return + import logging + logging.getLogger("pip").setLevel(logging.INFO) + environments.PIPENV_VERBOSITY = 1 def validate_python_path(ctx, param, value): @@ -333,9 +333,9 @@ def cli( "--verbose", "-v", is_flag=True, - default=False, + expose_value=False, + callback=setup_verbosity, help="Verbose mode.", - callback=setup_verbose, ) @option( "--ignore-pipfile", @@ -385,7 +385,6 @@ def install( lock=True, ignore_pipfile=False, skip_lock=False, - verbose=False, requirements=False, sequential=False, pre=False, @@ -408,7 +407,7 @@ def install( lock=lock, ignore_pipfile=ignore_pipfile, skip_lock=skip_lock, - verbose=verbose, + verbose=(environments.PIPENV_VERBOSITY > 0), requirements=requirements, sequential=sequential, pre=pre, @@ -440,9 +439,9 @@ def install( "--verbose", "-v", is_flag=True, - default=False, + expose_value=False, help="Verbose mode.", - callback=setup_verbose, + callback=setup_verbosity, ) @option("--lock", is_flag=True, default=True, help="Lock afterwards.") @option( @@ -479,7 +478,6 @@ def uninstall( lock=False, all_dev=False, all=False, - verbose=False, keep_outdated=False, pypi_mirror=None, ): @@ -495,7 +493,7 @@ def uninstall( lock=lock, all_dev=all_dev, all=all, - verbose=verbose, + verbose=(environments.PIPENV_VERBOSITY > 0), keep_outdated=keep_outdated, pypi_mirror=pypi_mirror, ) @@ -526,9 +524,9 @@ def uninstall( "--verbose", "-v", is_flag=True, - default=False, + expose_value=False, help="Verbose mode.", - callback=setup_verbose, + callback=setup_verbosity, ) @option( "--requirements", @@ -556,7 +554,6 @@ def lock( three=None, python=False, pypi_mirror=None, - verbose=False, requirements=False, dev=False, clear=False, @@ -571,7 +568,7 @@ def lock( if requirements: do_init(dev=dev, requirements=requirements, pypi_mirror=pypi_mirror) do_lock( - verbose=verbose, + verbose=(environments.PIPENV_VERBOSITY > 0), clear=clear, pre=pre, keep_outdated=keep_outdated, @@ -783,9 +780,9 @@ def check( "--verbose", "-v", is_flag=True, - default=False, + expose_value=False, help="Verbose mode.", - callback=setup_verbose, + callback=setup_verbosity, ) @option( "--dev", @@ -821,7 +818,6 @@ def update( python=False, pypi_mirror=None, system=False, - verbose=False, clear=False, keep_outdated=False, pre=False, @@ -869,6 +865,8 @@ def update( err=True, ) sys.exit(1) + + verbose = (environments.PIPENV_VERBOSITY > 0) do_lock( verbose=verbose, clear=clear, @@ -954,9 +952,9 @@ def run_open(module, three=None, python=None, pypi_mirror=None): "--verbose", "-v", is_flag=True, - default=False, + expose_value=False, help="Verbose mode.", - callback=setup_verbose, + callback=setup_verbosity, ) @option( "--dev", @@ -1002,7 +1000,6 @@ def sync( bare=False, dont_upgrade=False, user=False, - verbose=False, clear=False, unused=False, package_name=None, @@ -1020,7 +1017,7 @@ def sync( bare=bare, dont_upgrade=dont_upgrade, user=user, - verbose=verbose, + verbose=(environments.PIPENV_VERBOSITY > 0), clear=clear, unused=unused, sequential=sequential, @@ -1033,9 +1030,9 @@ def sync( "--verbose", "-v", is_flag=True, - default=False, + expose_value=False, help="Verbose mode.", - callback=setup_verbose, + callback=setup_verbosity, ) @option( "--three/--two", @@ -1050,15 +1047,23 @@ def sync( callback=validate_python_path, help="Specify which version of Python virtualenv should use.", ) -@option("--dry-run", is_flag=True, default=False, help="Just output unneeded packages.") +@option( + "--dry-run", + is_flag=True, + default=False, + help="Just output unneeded packages.", +) @pass_context -def clean( - ctx, three=None, python=None, dry_run=False, bare=False, user=False, verbose=False -): +def clean(ctx, three=None, python=None, dry_run=False, bare=False, user=False): """Uninstalls all packages not specified in Pipfile.lock.""" from .core import do_clean - do_clean(ctx=ctx, three=three, python=python, dry_run=dry_run, verbose=verbose) + do_clean( + ctx=ctx, + three=three, python=python, + dry_run=dry_run, + verbose=(environments.PIPENV_VERBOSITY > 0), + ) # Install click commands. diff --git a/pipenv/core.py b/pipenv/core.py index f22616ce..57db1325 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -41,7 +41,7 @@ from .utils import ( clean_resolved_dep, ) from ._compat import TemporaryDirectory, Path -from . import pep508checker, progress +from . import environments, pep508checker, progress from .environments import ( PIPENV_COLORBLIND, PIPENV_NOSPIN, @@ -49,7 +49,6 @@ from .environments import ( PIPENV_TIMEOUT, PIPENV_SKIP_VALIDATION, PIPENV_HIDE_EMOJIS, - PIPENV_INSTALL_TIMEOUT, PIPENV_YES, PIPENV_DONT_LOAD_ENV, PIPENV_DEFAULT_PYTHON_VERSION, @@ -1537,18 +1536,10 @@ def format_pip_output(out, r=None): def warn_in_virtualenv(): - from .environments import ( - PIPENV_USE_SYSTEM, - PIPENV_VIRTUALENV, - PIPENV_VERBOSITY, - ) - # Only warn if pipenv isn't already active. pipenv_active = os.environ.get("PIPENV_ACTIVE") - if ( - (PIPENV_USE_SYSTEM or PIPENV_VIRTUALENV) - and not (pipenv_active or PIPENV_VERBOSITY < 0) - ): + if ((environments.PIPENV_USE_SYSTEM or environments.PIPENV_VIRTUALENV) + and not (pipenv_active or environments.PIPENV_VERBOSITY < 0)): click.echo( "{0}: Pipenv found itself running within a virtual environment, " "so it will automatically use that environment, instead of "