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

Fix the output file for pip-compile with an explicit setup.py as source file #731

Merged
merged 2 commits into from
Feb 28, 2019
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
10 changes: 5 additions & 5 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..writer import OutputWriter

DEFAULT_REQUIREMENTS_FILE = 'requirements.in'
DEFAULT_REQUIREMENTS_OUTPUT_FILE = 'requirements.txt'


@click.command()
Expand Down Expand Up @@ -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.')
Expand Down
22 changes: 19 additions & 3 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down Expand Up @@ -398,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