-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
[#627] Add option --quiet to pip-compile #720
[#627] Add option --quiet to pip-compile #720
Conversation
Codecov Report
@@ Coverage Diff @@
## master #720 +/- ##
==========================================
+ Coverage 85.26% 85.32% +0.06%
==========================================
Files 31 31
Lines 2076 2085 +9
Branches 309 310 +1
==========================================
+ Hits 1770 1779 +9
Misses 235 235
Partials 71 71
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution. Could you provide a test for this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also consider a question: how the "quiet" flag should be dealt with the "verbose" flag?
I will
They should be mutually exclusive, shouldn't they? |
@atugushev Added tests and a class to handle Mutually exclusive options adopted from pallets/click#257 (comment) |
I'd rather do it in an additive way. Inspired by pip's quiet and verbose, see https://pip.pypa.io/en/stable/reference/pip/?highlight=additive#cmdoption-q. feel free to use this patch diff --git a/piptools/logging.py b/piptools/logging.py
index 98f0528..f0bd178 100644
--- a/piptools/logging.py
+++ b/piptools/logging.py
@@ -8,18 +8,19 @@ from . import click
class LogContext(object):
- def __init__(self, verbose=False):
- self.verbose = verbose
+ def __init__(self, verbosity=0):
+ self.verbosity = verbosity
def log(self, *args, **kwargs):
click.secho(*args, **kwargs)
def debug(self, *args, **kwargs):
- if self.verbose:
+ if self.verbosity >= 1:
self.log(*args, **kwargs)
def info(self, *args, **kwargs):
- self.log(*args, **kwargs)
+ if self.verbosity >= 0:
+ self.log(*args, **kwargs)
def warning(self, *args, **kwargs):
kwargs.setdefault('fg', 'yellow')
diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py
index cd6fe93..d24983c 100755
--- a/piptools/scripts/compile.py
+++ b/piptools/scripts/compile.py
@@ -31,7 +31,8 @@ class PipCommand(Command):
@click.command()
@click.version_option()
-@click.option('-v', '--verbose', is_flag=True, help="Show more output")
+@click.option('-v', '--verbose', count=True, help="Show more output")
+@click.option('-q', '--quiet', count=True, help="Show less output")
@click.option('-n', '--dry-run', is_flag=True, help="Only show what would happen, don't change anything")
@click.option('-p', '--pre', is_flag=True, default=None, help="Allow resolving to prereleases (default is not)")
@click.option('-r', '--rebuild', is_flag=True, help="Clear any caches upfront, rebuild from scratch")
@@ -65,12 +66,12 @@ class PipCommand(Command):
@click.option('--max-rounds', default=10,
help="Maximum number of rounds before resolving the requirements aborts.")
@click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True))
-def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
+def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
cert, client_cert, trusted_host, header, index, emit_trusted_host, annotate,
upgrade, upgrade_packages, output_file, allow_unsafe, generate_hashes,
src_files, max_rounds):
"""Compiles requirements.txt from requirements.in specs."""
- log.verbose = verbose
+ log.verbosity = verbose - quiet
if len(src_files) == 0:
if os.path.exists(DEFAULT_REQUIREMENTS_FILE): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, pressed "approve" button by mistake.
And not be mutually exclusive? |
That's right |
5e40cb9
to
097aab3
Compare
Very well. That enables some strange valid options like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thanks @bendikro! |
|
With
--quiet
, the output file is not logged.Fixes #627.
Changelog-friendly one-liner: Add option --quiet to pip-compile
Contributor checklist