Skip to content

Commit

Permalink
Merge pull request #793 from atugushev/pip-compile-find-links-output
Browse files Browse the repository at this point in the history
Add support for --find-links in pip-compile output
  • Loading branch information
Asif Saif Uddin authored May 2, 2019
2 parents 3b1b99d + 6646019 commit b14de39
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
25 changes: 13 additions & 12 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,6 @@ def cli(
}
repository = LocalRequirementsRepository(existing_pins, repository)

log.debug("Using indexes:")
# remove duplicate index urls before processing
repository.finder.index_urls = list(dedup(repository.finder.index_urls))
for index_url in repository.finder.index_urls:
log.debug(" {}".format(index_url))

if repository.finder.find_links:
log.debug("")
log.debug("Configuration:")
for find_link in repository.finder.find_links:
log.debug(" -f {}".format(find_link))

###
# Parsing/collecting initial requirements
###
Expand Down Expand Up @@ -338,6 +326,18 @@ def cli(
req for req in constraints if req.markers is None or req.markers.evaluate()
]

log.debug("Using indexes:")
# remove duplicate index urls before processing
repository.finder.index_urls = list(dedup(repository.finder.index_urls))
for index_url in repository.finder.index_urls:
log.debug(" {}".format(index_url))

if repository.finder.find_links:
log.debug("")
log.debug("Configuration:")
for find_link in repository.finder.find_links:
log.debug(" -f {}".format(find_link))

# Check the given base set of constraints first
Resolver.check_constraints(constraints)

Expand Down Expand Up @@ -405,6 +405,7 @@ def cli(
trusted_hosts=pip_options.trusted_hosts,
format_control=repository.finder.format_control,
allow_unsafe=allow_unsafe,
find_links=repository.finder.find_links,
)
writer.write(
results=results,
Expand Down
7 changes: 7 additions & 0 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
trusted_hosts,
format_control,
allow_unsafe,
find_links,
):
self.src_files = src_files
self.dst_file = dst_file
Expand All @@ -37,6 +38,7 @@ def __init__(
self.trusted_hosts = trusted_hosts
self.format_control = format_control
self.allow_unsafe = allow_unsafe
self.find_links = find_links

def _sort_key(self, ireq):
return (not ireq.editable, str(ireq.req).lower())
Expand Down Expand Up @@ -75,10 +77,15 @@ def write_format_controls(self):
for ob in dedup(self.format_control.only_binary):
yield "--only-binary {}".format(ob)

def write_find_links(self):
for find_link in dedup(self.find_links):
yield "--find-links {}".format(find_link)

def write_flags(self):
emitted = False
for line in chain(
self.write_index_options(),
self.write_find_links(),
self.write_trusted_hosts(),
self.write_format_controls(),
):
Expand Down
14 changes: 11 additions & 3 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ def test_command_line_setuptools_output_file(pip_conf, options, expected_output_


def test_find_links_option(pip_conf, runner):
with open("requirements.in", "w"):
pass
with open("requirements.in", "w") as req_in:
req_in.write("-f ./libs3")

out = runner.invoke(cli, ["-v", "-f", "./libs1", "-f", "./libs2"])

# Check that find-links has been passed to pip
assert "Configuration:\n -f ./libs1\n -f ./libs2" in out.output
assert "Configuration:\n -f ./libs1\n -f ./libs2\n -f ./libs3\n" in out.output

# Check that find-links has been written to a requirements.txt
with open("requirements.txt", "r") as req_txt:
assert (
"--find-links ./libs1\n--find-links ./libs2\n--find-links ./libs3\n"
in req_txt.read()
)


def test_extra_index_option(pip_conf, runner):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def writer(tmp_file):
trusted_hosts=[],
format_control=FormatControl(set(), set()),
allow_unsafe=False,
find_links=[],
)


Expand Down Expand Up @@ -259,3 +260,19 @@ def test_write_index_options_no_emit_index(writer):
writer.emit_index = False
with raises(StopIteration):
next(writer.write_index_options())


@mark.parametrize(
"find_links, expected_lines",
(
[[], []],
[["./foo"], ["--find-links ./foo"]],
[["./foo", "./bar"], ["--find-links ./foo", "--find-links ./bar"]],
),
)
def test_write_find_links(writer, find_links, expected_lines):
"""
Test write_find_links method.
"""
writer.find_links = find_links
assert list(writer.write_find_links()) == expected_lines

0 comments on commit b14de39

Please sign in to comment.