Skip to content

Commit

Permalink
Fix compiling input setup file in nested folders (#1324)
Browse files Browse the repository at this point in the history
Co-authored-by: Albert Tugushev <albert@tugushev.ru>
  • Loading branch information
peymanslh and atugushev authored Feb 24, 2021
1 parent 2be5cbf commit 1931e21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ def cli(
if src_files == ("-",):
raise click.BadParameter("--output-file is required if input is from stdin")
# Use default requirements output file if there is a setup.py the source file
elif src_files == ("setup.py",):
file_name = DEFAULT_REQUIREMENTS_OUTPUT_FILE
elif os.path.basename(src_files[0]) == "setup.py":
file_name = os.path.join(
os.path.dirname(src_files[0]), DEFAULT_REQUIREMENTS_OUTPUT_FILE
)
# An output file must be provided if there are multiple source files
elif len(src_files) > 1:
raise click.BadParameter(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ def test_command_line_setuptools_output_file(
assert os.path.exists(expected_output_file)


def test_command_line_setuptools_nested_output_file(pip_conf, tmpdir, runner):
"""
Test the output file for setup.py in nested folder as a requirement file.
"""
proj_dir = tmpdir.mkdir("proj")

with open(str(proj_dir / "setup.py"), "w") as package:
package.write(
dedent(
"""\
from setuptools import setup
setup(install_requires=[])
"""
)
)

out = runner.invoke(cli, [str(proj_dir / "setup.py")])
assert out.exit_code == 0
assert (proj_dir / "requirements.txt").exists()


def test_find_links_option(runner):
with open("requirements.in", "w") as req_in:
req_in.write("-f ./libs3")
Expand Down

0 comments on commit 1931e21

Please sign in to comment.