From fb646cbe0be77ccddc031718ff64bba18415c8c0 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 7 Feb 2019 02:00:44 +0300 Subject: [PATCH 1/2] Fix the output file for pip-compile with an explicit setup.py as source file The command `pip-compile setup.py` generates a `setup.txt`, but it should be a requirements.txt file. --- piptools/scripts/compile.py | 10 +++++----- tests/test_cli_compile.py | 10 +++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index d01a1e887..5c868c3ef 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -21,6 +21,7 @@ from ..writer import OutputWriter DEFAULT_REQUIREMENTS_FILE = 'requirements.in' +DEFAULT_REQUIREMENTS_OUTPUT_FILE = 'requirements.txt' @click.command() @@ -72,15 +73,14 @@ def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_inde src_files = (DEFAULT_REQUIREMENTS_FILE,) elif os.path.exists('setup.py'): src_files = ('setup.py',) - if not output_file: - output_file = 'requirements.txt' else: raise click.BadParameter(("If you do not specify an input file, " "the default is {} or setup.py").format(DEFAULT_REQUIREMENTS_FILE)) - if len(src_files) == 1 and src_files[0] == '-': - if not output_file: - raise click.BadParameter('--output-file is required if input is from stdin') + if src_files == ('-',) and not output_file: + raise click.BadParameter('--output-file is required if input is from stdin') + elif src_files == ('setup.py',): + output_file = DEFAULT_REQUIREMENTS_OUTPUT_FILE if len(src_files) > 1 and not output_file: raise click.BadParameter('--output-file is required if two or more input files are given.') diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 51d66c0e1..56877be9c 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -77,8 +77,11 @@ def test_command_line_overrides_pip_conf(pip_conf): assert 'Using indexes:\n http://override.com' in out.output -def test_command_line_setuptools_read(pip_conf): - +@pytest.mark.parametrize('cli_args', [ + [], + ['setup.py'], +]) +def test_command_line_setuptools_read(pip_conf, cli_args): runner = CliRunner() with runner.isolated_filesystem(): package = open('setup.py', 'w') @@ -87,10 +90,11 @@ def test_command_line_setuptools_read(pip_conf): setup(install_requires=[]) """)) package.close() - out = runner.invoke(cli) + out = runner.invoke(cli, cli_args) # check that pip-compile generated a configuration assert 'This file is autogenerated by pip-compile' in out.output + assert os.path.exists('requirements.txt') def test_find_links_option(pip_conf): From 37ae661330579eea8b929c706f58e5ef2933d296 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Fri, 8 Feb 2019 21:16:51 +0300 Subject: [PATCH 2/2] Test passing stdin to the pip-compile without an output file --- tests/test_cli_compile.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 56877be9c..50b2b964f 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -402,3 +402,15 @@ def test_default_index_url(): ' http://example.com)' + os.linesep ) assert expected in output + + +def test_stdin_without_output_file(): + """ + The --output-file option is required for STDIN. + """ + runner = CliRunner() + with runner.isolated_filesystem(): + out = runner.invoke(cli, ['-n', '-']) + + assert out.exit_code == 2 + assert '--output-file is required if input is from stdin' in out.output