From d3eaefb30cc7727282fa483167477ebbe30c5900 Mon Sep 17 00:00:00 2001 From: Jacob Tolar Date: Tue, 13 Aug 2019 17:17:19 -0500 Subject: [PATCH 1/2] Add --no-emit-find-links option (fixes #848) --- piptools/scripts/compile.py | 8 ++++++++ piptools/writer.py | 7 +++++-- tests/test_cli_compile.py | 9 +++++++++ tests/test_writer.py | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index b1dcbf388..24d50b662 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -163,6 +163,12 @@ "Build dependencies specified by PEP 518 must be already installed " "if build isolation is disabled.", ) +@click.option( + "--emit-find-links/--no-emit-find-links", + is_flag=True, + default=True, + help="Add the find-links option to generated file", +) def cli( ctx, verbose, @@ -188,6 +194,7 @@ def cli( src_files, max_rounds, build_isolation, + emit_find_links, ): """Compiles requirements.txt from requirements.in specs.""" log.verbosity = verbose - quiet @@ -400,6 +407,7 @@ def cli( format_control=repository.finder.format_control, allow_unsafe=allow_unsafe, find_links=repository.finder.find_links, + emit_find_links=emit_find_links, ) writer.write( results=results, diff --git a/piptools/writer.py b/piptools/writer.py index a20e11b69..f318e9667 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -54,6 +54,7 @@ def __init__( format_control, allow_unsafe, find_links, + emit_find_links, ): self.src_files = src_files self.dst_file = dst_file @@ -70,6 +71,7 @@ def __init__( self.format_control = format_control self.allow_unsafe = allow_unsafe self.find_links = find_links + self.emit_find_links = emit_find_links def _sort_key(self, ireq): return (not ireq.editable, str(ireq.req).lower()) @@ -106,8 +108,9 @@ def write_format_controls(self): yield "--only-binary {}".format(ob) def write_find_links(self): - for find_link in dedup(self.find_links): - yield "--find-links {}".format(find_link) + if self.emit_find_links: + for find_link in dedup(self.find_links): + yield "--find-links {}".format(find_link) def write_flags(self): emitted = False diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index cb20ae953..3389ae02a 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -183,6 +183,15 @@ def test_trusted_host_no_emit(pip_conf, runner): assert "--trusted-host example.com" not in out.stderr +def test_find_links_no_emit(pip_conf, runner): + with open("requirements.in", "w"): + pass + out = runner.invoke( + cli, ["-v", "--no-emit-find-links"] + ) + assert "--find-links" not in out.stderr + + def test_realistic_complex_sub_dependencies(runner): wheels_dir = "wheels" diff --git a/tests/test_writer.py b/tests/test_writer.py index 40aac8177..4e531898a 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -41,6 +41,7 @@ def writer(tmpdir_cwd): format_control=FormatControl(set(), set()), allow_unsafe=False, find_links=[], + emit_find_links=True, ) yield writer From d43445fcfa498eb53dcdb7d054e666f0fdca54f6 Mon Sep 17 00:00:00 2001 From: Jacob Tolar Date: Tue, 13 Aug 2019 17:41:42 -0500 Subject: [PATCH 2/2] code style fix --- tests/test_cli_compile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 3389ae02a..0dce21b73 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -186,9 +186,7 @@ def test_trusted_host_no_emit(pip_conf, runner): def test_find_links_no_emit(pip_conf, runner): with open("requirements.in", "w"): pass - out = runner.invoke( - cli, ["-v", "--no-emit-find-links"] - ) + out = runner.invoke(cli, ["-v", "--no-emit-find-links"]) assert "--find-links" not in out.stderr