Skip to content

Commit

Permalink
Parse extras_require for additional dependencies coming from environm…
Browse files Browse the repository at this point in the history
…ent markers
  • Loading branch information
iamhatesz committed Jan 24, 2020
1 parent 30e90be commit 73fbcc9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions piptools/scripts/compile.py
Expand Up @@ -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()
Expand Down
30 changes: 30 additions & 0 deletions tests/test_cli_compile.py
Expand Up @@ -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",
[
Expand Down

0 comments on commit 73fbcc9

Please sign in to comment.