Skip to content

Commit

Permalink
Fix the output file for pip-compile with an explicit setup.py as sour…
Browse files Browse the repository at this point in the history
…ce file

The command `pip-compile setup.py` generates a `setup.txt`, but
it should be a requirements.txt file.
  • Loading branch information
atugushev committed Feb 28, 2019
1 parent 1545aa7 commit fb646cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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
10 changes: 7 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

0 comments on commit fb646cb

Please sign in to comment.