diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 590adf89b..6864e432d 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -322,7 +322,19 @@ def cli( from distutils.core import run_setup dist = run_setup(src_file) - tmpfile.write("\n".join(dist.install_requires)) + deps = dist.install_requires + + # parse additional dependencies in extras_require + # which might come from parsing environment markers + extras_deps = [] + for extra_name, extra_pkgs in dist.extras_require.items(): + if extra_name.startswith(":"): + marker = extra_name[1:] + for pkg in extra_pkgs: + extras_deps.append("{} ; {}".format(pkg, marker)) + + deps += extras_deps + tmpfile.write("\n".join(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", [