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

Add option to pin packages considered unsafe in pip-compile #377

Merged
merged 5 commits into from
Jul 9, 2016
Merged
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
7 changes: 5 additions & 2 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ class PipCommand(pip.basecommand.Command):
@click.option('-o', '--output-file', nargs=1, type=str, default=None,
help=('Output file name. Required if more than one input file is given. '
'Will be derived from input file otherwise.'))
@click.option('--allow-unsafe', is_flag=True, default=False,
help="Pin packages considered unsafe: pip, setuptools & distribute")
@click.argument('src_files', nargs=-1, type=click.Path(exists=True, allow_dash=True))
def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
client_cert, trusted_host, header, index, annotate, upgrade,
output_file, src_files):
output_file, allow_unsafe, src_files):
"""Compiles requirements.txt from requirements.in specs."""
log.verbose = verbose

Expand Down Expand Up @@ -200,7 +202,8 @@ 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,
format_control=repository.finder.format_control)
format_control=repository.finder.format_control,
allow_unsafe=allow_unsafe)
writer.write(results=results,
reverse_dependencies=reverse_dependencies,
primary_packages={key_from_req(ireq.req) for ireq in constraints})
Expand Down
18 changes: 12 additions & 6 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@


class OutputWriter(object):
def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index, annotate,
default_index_url, index_urls, trusted_hosts, format_control):
def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index,
annotate, default_index_url, index_urls, trusted_hosts,
format_control, allow_unsafe=False):
self.src_files = src_files
self.dst_file = dst_file
self.dry_run = dry_run
Expand All @@ -21,6 +22,7 @@ def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index, annota
self.index_urls = index_urls
self.trusted_hosts = trusted_hosts
self.format_control = format_control
self.allow_unsafe = allow_unsafe

def _sort_key(self, ireq):
return (not ireq.editable, str(ireq.req).lower())
Expand Down Expand Up @@ -88,12 +90,16 @@ def _iter_lines(self, results, reverse_dependencies, primary_packages):

if unsafe_packages:
yield ''
yield comment('# The following packages are commented out because they are')
yield comment('# considered to be unsafe in a requirements file:')
yield comment('# The following packages are considered to be unsafe in a requirements file:')

for ireq in unsafe_packages:
line = self._format_requirement(ireq, reverse_dependencies, primary_packages, include_specifier=False)
yield comment('# ' + line)
line = self._format_requirement(
ireq, reverse_dependencies, primary_packages,
include_specifier=self.allow_unsafe)
if self.allow_unsafe:
yield line
else:
yield comment('# ' + line)

def write(self, results, reverse_dependencies, primary_packages):
with ExitStack() as stack:
Expand Down