Skip to content

Commit

Permalink
Merge pull request #749 from atugushev/fix-regression-from-731
Browse files Browse the repository at this point in the history
Fix a regression bug introduced in #731 PR
  • Loading branch information
blueyed authored Feb 28, 2019
2 parents c1a5d3a + 86fbd92 commit 6f99054
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def cli(verbose, quiet, dry_run, pre, rebuild, find_links, index_url, extra_inde

if src_files == ('-',) and not output_file:
raise click.BadParameter('--output-file is required if input is from stdin')
elif src_files == ('setup.py',):
elif src_files == ('setup.py',) and not output_file:
output_file = DEFAULT_REQUIREMENTS_OUTPUT_FILE

if len(src_files) > 1 and not output_file:
Expand Down
38 changes: 32 additions & 6 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ def test_command_line_overrides_pip_conf(pip_conf):
assert 'Using indexes:\n http://override.com' in out.output


@pytest.mark.parametrize('cli_args', [
[],
['setup.py'],
])
def test_command_line_setuptools_read(pip_conf, cli_args):
@pytest.mark.usefixtures('pip_conf')
def test_command_line_setuptools_read():
runner = CliRunner()
with runner.isolated_filesystem():
package = open('setup.py', 'w')
Expand All @@ -90,13 +87,42 @@ def test_command_line_setuptools_read(pip_conf, cli_args):
setup(install_requires=[])
"""))
package.close()
out = runner.invoke(cli, cli_args)
out = runner.invoke(cli)

# check that pip-compile generated a configuration
assert 'This file is autogenerated by pip-compile' in out.output
assert os.path.exists('requirements.txt')


@pytest.mark.usefixtures('pip_conf')
@pytest.mark.parametrize('options, expected_output_file', [
# For the `pip-compile` output file should be "requirements.txt"
([], 'requirements.txt'),
# For the `pip-compile --output-file=output.txt` output file should be "output.txt"
(['--output-file', 'output.txt'], 'output.txt'),
# For the `pip-compile setup.py` output file should be "requirements.txt"
(['setup.py'], 'requirements.txt'),
# For the `pip-compile setup.py --output-file=output.txt` output file should be "output.txt"
(['setup.py', '--output-file', 'output.txt'], 'output.txt'),
])
def test_command_line_setuptools_output_file(options, expected_output_file):
"""
Test the output files for setup.py as a requirement file.
"""
runner = CliRunner()
with runner.isolated_filesystem():
package = open('setup.py', 'w')
package.write(dedent("""\
from setuptools import setup
setup(install_requires=[])
"""))
package.close()

out = runner.invoke(cli, options)
assert out.exit_code == 0
assert os.path.exists(expected_output_file)


def test_find_links_option(pip_conf):

assert os.path.exists(pip_conf)
Expand Down

0 comments on commit 6f99054

Please sign in to comment.