From 73fbcc9cfab198ce05ef3f4a48d239606e35809a Mon Sep 17 00:00:00 2001 From: Tomasz Wrona Date: Fri, 24 Jan 2020 20:49:40 +0100 Subject: [PATCH] Parse extras_require for additional dependencies coming from environment markers --- piptools/scripts/compile.py | 10 ++++++++++ tests/test_cli_compile.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 590adf89b..5b42fa600 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -323,6 +323,16 @@ def cli( dist = run_setup(src_file) tmpfile.write("\n".join(dist.install_requires)) + + # parse additional dependencies in extras_require + # which might come from parsing environment markers + additional_deps = [] + for extra_name, extra_pkgs in dist.extras_require.items(): + if extra_name.startswith(":"): + marker = extra_name[1:] + for pkg in extra_pkgs: + additional_deps.append("{} ; {}".format(pkg, marker)) + tmpfile.write("\n".join(additional_deps)) else: tmpfile.write(sys.stdin.read()) tmpfile.flush() diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 5014d07bf..7531500b2 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -58,6 +58,36 @@ def test_command_line_setuptools_read(pip_conf, runner): assert os.path.exists("requirements.txt") +def test_command_line_setuptools_with_env_markers_read(pip_conf, runner): + package = open("setup.py", "w") + package.write( + dedent( + """\ + from setuptools import setup + setup( + install_requires=[ + 'small-fake-a==0.1 ; "linux" in sys_platform', + 'small-fake-a==0.2 ; "win32" in sys_platform', + 'small-fake-a==0.3b1 ; "darwin" in sys_platform' + ] + ) + """ + ) + ) + package.close() + out = runner.invoke(cli) + + # check that pip-compile generated a configuration + assert "This file is autogenerated by pip-compile" in out.stderr + assert os.path.exists("requirements.txt") + if "linux" in sys.platform: + assert 'small-fake-a==0.1 ; "linux" in sys_platform' in out.stderr + elif "win32" in sys.platform: + assert 'small-fake-a==0.2 ; "win32" in sys_platform' in out.stderr + elif "darwin" in sys.platform: + assert 'small-fake-a==0.3b1 ; "darwin" in sys_platform' in out.stderr + + @pytest.mark.parametrize( "options, expected_output_file", [