Skip to content

Commit

Permalink
Write relative find-links opts to output file
Browse files Browse the repository at this point in the history
If input file or command line has `--find-links` options that point to
directories which are relative to the destination file (i.e. relative
path from destination directory to find-links directory does not contain
any `../` components), then those should be written to the output file.

Now `--find-links` options in the source file work similarly as e.g.
the `--extra-index-url` options.  This makes it possible to make deploy
scripts to install from `requirements.txt` without knowing about the
find-links options.
  • Loading branch information
suutari-ai committed Feb 13, 2017
1 parent a52b6e3 commit 40676ef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def writer():
generate_hashes=False,
default_index_url=None, index_urls=[],
trusted_hosts=[],
find_links=[],
format_control=FormatControl(set(), set()))


Expand Down

0 comments on commit 40676ef

Please sign in to comment.