diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 9ea215d81..f800de757 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -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 @@ -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}) diff --git a/piptools/writer.py b/piptools/writer.py index 9868e72c3..fe02f82a4 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -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 @@ -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()) @@ -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: