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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions piptools/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@


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')
Expand Down
7 changes: 4 additions & 3 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="Give 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")
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ def test_upgrade_packages_version_option(tmpdir):
assert 'small-fake-b==0.2' in out.output


def test_quiet_option(tmpdir):
runner = CliRunner()
with runner.isolated_filesystem():
with open('requirements', 'w'):
pass
out = runner.invoke(cli, ['--quiet', '-n', 'requirements'])
# Pinned requirements result has not been written to output
assert 'Dry-run, so nothing updated.' == out.output.strip()


def test_generate_hashes_with_editable():
small_fake_package_dir = os.path.join(
os.path.split(__file__)[0], 'test_data', 'small_fake_package')
Expand Down