Skip to content

Commit

Permalink
Add --emit-options/--no-emit-options flag
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed May 2, 2020
1 parent a40414a commit 14b6fd5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@
type=click.Path(file_okay=False, writable=True),
)
@click.option("--pip-args", help="Arguments to pass directly to the pip command.")
@click.option(
"--emit-options/--no-emit-options",
is_flag=True,
default=True,
help="Add options to generated file",
)
def cli(
ctx,
verbose,
Expand Down Expand Up @@ -207,6 +213,7 @@ def cli(
emit_find_links,
cache_dir,
pip_args,
emit_options,
):
"""Compiles requirements.txt from requirements.in specs."""
log.verbosity = verbose - quiet
Expand Down Expand Up @@ -421,6 +428,7 @@ def cli(
allow_unsafe=allow_unsafe,
find_links=repository.finder.find_links,
emit_find_links=emit_find_links,
emit_options=emit_options,
)
writer.write(
results=results,
Expand Down
5 changes: 5 additions & 0 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
allow_unsafe,
find_links,
emit_find_links,
emit_options,
):
self.src_files = src_files
self.dst_file = dst_file
Expand All @@ -84,6 +85,7 @@ def __init__(
self.allow_unsafe = allow_unsafe
self.find_links = find_links
self.emit_find_links = emit_find_links
self.emit_options = emit_options

def _sort_key(self, ireq):
return (not ireq.editable, str(ireq.req).lower())
Expand Down Expand Up @@ -125,6 +127,9 @@ def write_find_links(self):
yield "--find-links {}".format(find_link)

def write_flags(self):
if not self.emit_options:
return

emitted = False
for line in chain(
self.write_index_options(),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ def test_force_text(value, expected_text):
(["--no-index"], "pip-compile --no-index"),
(["--no-emit-trusted-host"], "pip-compile --no-emit-trusted-host"),
(["--no-annotate"], "pip-compile --no-annotate"),
(["--no-emit-options"], "pip-compile --no-emit-options"),
# Check that default values will be removed from the command
(["--emit-trusted-host"], "pip-compile"),
(["--emit-options"], "pip-compile"),
(["--annotate"], "pip-compile"),
(["--index"], "pip-compile"),
(["--max-rounds=10"], "pip-compile"),
Expand Down
35 changes: 35 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def writer(tmpdir_cwd):
allow_unsafe=False,
find_links=[],
emit_find_links=True,
emit_options=True,
)
yield writer

Expand Down Expand Up @@ -224,6 +225,40 @@ def test_write_header_no_emit_header(writer):
next(writer.write_header())


def test_write_flags_emit_options(writer):
"""
There should be options if emit_options is True
"""
writer.emit_options = True
writer.index_urls = ["https://index-server"]
writer.find_links = ["links"]
writer.trusted_hosts = ["index-server"]
writer.format_control = FormatControl(no_binary=["flask"], only_binary=["django"])

assert tuple(writer.write_flags()) == (
"--index-url https://index-server",
"--find-links links",
"--trusted-host index-server",
"--no-binary flask",
"--only-binary django",
"",
)


def test_write_flags_no_emit_options(writer):
"""
There should not be options if emit_options is False
"""
writer.emit_options = False
writer.index_urls = ["https://index-server"]
writer.find_links = ["links"]
writer.trusted_hosts = ["index-server"]
writer.format_control = FormatControl(no_binary=["flask"], only_binary=["django"])

with raises(StopIteration):
next(writer.write_flags())


def test_write_format_controls(writer):
"""
Tests --no-binary/--only-binary options.
Expand Down

0 comments on commit 14b6fd5

Please sign in to comment.