Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write relative find-links opts to output file #453

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
default_index_url=repository.DEFAULT_INDEX_URL,
index_urls=repository.finder.index_urls,
trusted_hosts=pip_options.trusted_hosts,
find_links=repository.finder.find_links,
format_control=repository.finder.format_control)
writer.write(results=results,
unsafe_requirements=resolver.unsafe_constraints,
Expand Down
17 changes: 16 additions & 1 deletion piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
class OutputWriter(object):
def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index,
emit_trusted_host, annotate, generate_hashes,
default_index_url, index_urls, trusted_hosts, format_control):
default_index_url, index_urls, trusted_hosts,
find_links, format_control):
self.src_files = src_files
self.dst_file = dst_file
self.dry_run = dry_run
Expand All @@ -23,6 +24,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

def _sort_key(self, ireq):
Expand Down Expand Up @@ -65,6 +67,18 @@ def write_trusted_hosts(self):
for trusted_host in dedup(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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's assume that user has /app/stuff/requirements.txt and /app/links/. In that case relative link would be ../links and this link will be omitted. Do you think it's okay?

# 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 dedup(self.format_control.no_binary):
yield '--no-binary {}'.format(nb)
Expand All @@ -75,6 +89,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 @@ -93,10 +93,21 @@ def test_find_links_option(pip_conf):
with runner.isolated_filesystem():
with open('requirements.in', 'w'):
pass
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 @@ -14,6 +14,7 @@ def writer():
generate_hashes=False,
default_index_url=None, index_urls=[],
trusted_hosts=[],
find_links=[],
format_control=FormatControl(set(), set()))


Expand Down