diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index a10a6bb95..310a54491 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -230,6 +230,7 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url, index_urls=repository.finder.index_urls, trusted_hosts=pip_options.trusted_hosts, format_control=repository.finder.format_control, + find_links=repository.finder.find_links, allow_unsafe=allow_unsafe) writer.write(results=results, reverse_dependencies=reverse_dependencies, diff --git a/piptools/writer.py b/piptools/writer.py index 545c239e2..adc645cea 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -11,7 +11,7 @@ class OutputWriter(object): def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index, annotate, generate_hashes, default_index_url, index_urls, - trusted_hosts, format_control, allow_unsafe=False): + trusted_hosts, find_links, format_control, allow_unsafe=False): self.src_files = src_files self.dst_file = dst_file self.dry_run = dry_run @@ -22,6 +22,7 @@ def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index, self.default_index_url = default_index_url self.index_urls = index_urls self.trusted_hosts = trusted_hosts + self.find_links = find_links self.format_control = format_control self.allow_unsafe = allow_unsafe @@ -58,6 +59,18 @@ def write_trusted_hosts(self): for trusted_host in self.trusted_hosts: yield '--trusted-host {}'.format(trusted_host) + def write_find_links(self): + yielded = set() + dst_dir = os.path.dirname(self.dst_file) + for abs_link in self.find_links: + rel_link = os.path.relpath(abs_link, start=dst_dir) + if not rel_link.startswith(os.path.pardir + os.path.sep): + # Only yield links which are relative to dst_file, since + # absolute paths shouldn't be stored to requirements.txt + if rel_link not in yielded: + yield '--find-links {}'.format(rel_link) + yielded.add(rel_link) + def write_format_controls(self): for nb in self.format_control.no_binary: yield '--no-binary {}'.format(nb) @@ -68,6 +81,7 @@ def write_flags(self): emitted = False for line in chain(self.write_index_options(), self.write_trusted_hosts(), + self.write_find_links(), self.write_format_controls()): emitted = True yield line diff --git a/tests/test_cli.py b/tests/test_cli.py index 5951bdbd0..98467788b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,10 +69,21 @@ def test_find_links_option(pip_conf): runner = CliRunner() with runner.isolated_filesystem(): open('requirements.in', 'w').close() - out = runner.invoke(cli, ['-v', '-f', './libs1', '-f', './libs2']) + find_link_options = [ + '-f', './libs1', + '-f', '/global-libs', + '-f', './libs2', + ] + out = runner.invoke(cli, ['-v'] + find_link_options) # 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 /global-libs\n' + ' -f ./libs2\n') in out.output + + assert ('--find-links libs1\n' + '--find-links libs2\n') in out.output def test_extra_index_option(pip_conf): diff --git a/tests/test_writer.py b/tests/test_writer.py index ef3aaea0b..a03735d56 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -12,6 +12,7 @@ def writer(): generate_hashes=False, default_index_url=None, index_urls=[], trusted_hosts=[], + find_links=[], format_control=FormatControl(set(), set()))