From 2b1dcd6e057f69f23f611023b05789ef8623e75c Mon Sep 17 00:00:00 2001 From: Peyman Salehi Date: Sun, 14 Feb 2021 22:23:01 +0330 Subject: [PATCH 1/2] Fix compiling input setup file in nested folders Add unit test [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Fix some issues Co-authored-by: Albert Tugushev [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- piptools/scripts/compile.py | 6 ++++-- tests/test_cli_compile.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index d21f0dec9..482559f08 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -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( diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 12db0f422..bb26a99be 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -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(os.path.join(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") From a92734a83be8ada8e2c5c15ecfcfcc2cb8141df8 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Wed, 24 Feb 2021 12:59:49 +0700 Subject: [PATCH 2/2] Update tests/test_cli_compile.py --- tests/test_cli_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index bb26a99be..603d3f83f 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -113,7 +113,7 @@ def test_command_line_setuptools_nested_output_file(pip_conf, tmpdir, runner): """ proj_dir = tmpdir.mkdir("proj") - with open(os.path.join(str(proj_dir), "setup.py"), "w") as package: + with open(str(proj_dir / "setup.py"), "w") as package: package.write( dedent( """\