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

[#627] Add option --quiet to pip-compile #720

Merged
merged 1 commit into from
Jan 29, 2019

Conversation

bendikro
Copy link
Contributor

@bendikro bendikro commented Jan 24, 2019

With --quiet, the output file is not logged.
Fixes #627.

Changelog-friendly one-liner: Add option --quiet to pip-compile

Contributor checklist
  • Provided the tests for the changes
  • Requested (or received) a review from another contributor
  • Gave a clear one-line description in the PR (that the maintainers can add to CHANGELOG.md afterwards).

@codecov
Copy link

codecov bot commented Jan 24, 2019

Codecov Report

Merging #720 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
tests/test_cli.py 97.92% <100%> (+0.06%) ⬆️
piptools/logging.py 100% <100%> (ø) ⬆️
piptools/scripts/compile.py 87.76% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c14bcca...097aab3. Read the comment docs.

Copy link
Member

@atugushev atugushev left a 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?

Copy link
Member

@atugushev atugushev left a 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?

@bendikro
Copy link
Contributor Author

Thank you for the contribution. Could you provide a test for this feature?

I will

I think we should also consider a question: how the "quiet" flag should be dealt with the "verbose" flag?

They should be mutually exclusive, shouldn't they?

@bendikro
Copy link
Contributor Author

@atugushev Added tests and a class to handle Mutually exclusive options adopted from pallets/click#257 (comment)

@atugushev
Copy link
Member

atugushev commented Jan 28, 2019

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):

Copy link
Member

@atugushev atugushev left a 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.

@bendikro
Copy link
Contributor Author

I'd rather do it in an additive way.

And not be mutually exclusive?

@atugushev
Copy link
Member

And not be mutually exclusive?

That's right

@bendikro
Copy link
Contributor Author

And not be mutually exclusive?

That's right

Very well. That enables some strange valid options like -qqq -vv which would be the same as -q.

Copy link
Member

@atugushev atugushev left a 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.

@atugushev atugushev merged commit 9a789ae into jazzband:master Jan 29, 2019
@atugushev
Copy link
Member

Thanks @bendikro!

@vphilippon vphilippon added this to the 3.4.0 milestone Jan 29, 2019
@vphilippon
Copy link
Member

pip-tools v3.4.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants