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 compiling input setup file in nested folders #1324

Merged
merged 2 commits into from
Feb 24, 2021
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
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