Skip to content

Commit bd9eab1

Browse files
authored
Add PEP-517 support (jazzband#1356)
1 parent 37946f2 commit bd9eab1

File tree

3 files changed

+127
-2
lines changed

3 files changed

+127
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ build
2020
dist
2121
*.egg-info
2222
.coverage
23+
.coverage.*
24+
coverage.xml
2325
.cache
2426

2527
# IDE

piptools/scripts/compile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
DEFAULT_REQUIREMENTS_FILE = "requirements.in"
2626
DEFAULT_REQUIREMENTS_OUTPUT_FILE = "requirements.txt"
27+
METADATA_FILENAMES = frozenset({"setup.py", "setup.cfg", "pyproject.toml"})
2728

2829

2930
def _get_default_option(option_name: str) -> Any:
@@ -247,7 +248,7 @@ def cli(
247248
if src_files == ("-",):
248249
raise click.BadParameter("--output-file is required if input is from stdin")
249250
# Use default requirements output file if there is a setup.py the source file
250-
elif os.path.basename(src_files[0]) == "setup.py":
251+
elif os.path.basename(src_files[0]) in METADATA_FILENAMES:
251252
file_name = os.path.join(
252253
os.path.dirname(src_files[0]), DEFAULT_REQUIREMENTS_OUTPUT_FILE
253254
)
@@ -335,7 +336,7 @@ def cli(
335336

336337
constraints = []
337338
for src_file in src_files:
338-
is_setup_file = os.path.basename(src_file) == "setup.py"
339+
is_setup_file = os.path.basename(src_file) in METADATA_FILENAMES
339340
if src_file == "-":
340341
# pip requires filenames and not files. Since we want to support
341342
# piping from stdin, we need to briefly save the input from stdin

tests/test_cli_compile.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,3 +1656,125 @@ def test_triple_equal_pinned_dependency_is_used(
16561656
assert out.exit_code == 0, out
16571657
for line in out_expected_content:
16581658
assert line in out.stderr
1659+
1660+
1661+
@pytest.mark.network
1662+
@pytest.mark.parametrize(
1663+
("fname", "content"),
1664+
(
1665+
pytest.param(
1666+
"setup.cfg",
1667+
"""
1668+
[metadata]
1669+
name = sample_lib
1670+
author = Vincent Driessen
1671+
author_email = [email protected]
1672+
1673+
[options]
1674+
packages = find:
1675+
install_requires =
1676+
small-fake-a==0.1
1677+
small-fake-b==0.2
1678+
1679+
[options.extras_require]
1680+
dev =
1681+
small-fake-c==0.3
1682+
small-fake-d==0.4
1683+
test =
1684+
small-fake-e==0.5
1685+
small-fake-f==0.6
1686+
""",
1687+
id="setup.cfg",
1688+
),
1689+
pytest.param(
1690+
"setup.py",
1691+
"""
1692+
from setuptools import setup
1693+
1694+
setup(
1695+
name="sample_lib",
1696+
version=0.1,
1697+
install_requires=["small-fake-a==0.1", "small-fake-b==0.2"],
1698+
extras_require={
1699+
"dev": ["small-fake-c==0.3", "small-fake-d==0.4"],
1700+
"test": ["small-fake-e==0.5", "small-fake-f==0.6"],
1701+
},
1702+
)
1703+
""",
1704+
id="setup.py",
1705+
),
1706+
pytest.param(
1707+
"pyproject.toml",
1708+
"""
1709+
[build-system]
1710+
requires = ["flit_core >=2,<4"]
1711+
build-backend = "flit_core.buildapi"
1712+
1713+
[tool.flit.metadata]
1714+
module = "sample_lib"
1715+
author = "Vincent Driessen"
1716+
author-email = "[email protected]"
1717+
1718+
requires = ["small-fake-a==0.1", "small-fake-b==0.2"]
1719+
1720+
[tool.flit.metadata.requires-extra]
1721+
dev = ["small-fake-c==0.3", "small-fake-d==0.4"]
1722+
test = ["small-fake-e==0.5", "small-fake-f==0.6"]
1723+
""",
1724+
id="flit",
1725+
),
1726+
pytest.param(
1727+
"pyproject.toml",
1728+
"""
1729+
[build-system]
1730+
requires = ["poetry_core>=1.0.0"]
1731+
build-backend = "poetry.core.masonry.api"
1732+
1733+
[tool.poetry]
1734+
name = "sample_lib"
1735+
version = "0.1.0"
1736+
description = ""
1737+
authors = ["Vincent Driessen <[email protected]>"]
1738+
1739+
[tool.poetry.dependencies]
1740+
python = "*"
1741+
small-fake-a = "0.1"
1742+
small-fake-b = "0.2"
1743+
1744+
small-fake-c = "0.3"
1745+
small-fake-d = "0.4"
1746+
small-fake-e = "0.5"
1747+
small-fake-f = "0.6"
1748+
1749+
[tool.poetry.extras]
1750+
dev = ["small-fake-c", "small-fake-d"]
1751+
test = ["small-fake-e", "small-fake-f"]
1752+
""",
1753+
id="poetry",
1754+
),
1755+
),
1756+
)
1757+
def test_input_formats(make_package, make_wheel, runner, tmpdir, fname, content):
1758+
dists_path = os.path.join(tmpdir, "dists")
1759+
pkg = make_package("small-fake-a", version="0.1")
1760+
make_wheel(pkg, dists_path)
1761+
pkg = make_package("small-fake-b", version="0.2")
1762+
make_wheel(pkg, dists_path)
1763+
1764+
path = os.path.join(tmpdir, "sample_lib")
1765+
os.mkdir(path)
1766+
path = os.path.join(tmpdir, "sample_lib", "__init__.py")
1767+
with open(path, "w") as stream:
1768+
stream.write("'example module'\n__version__ = '1.2.3'")
1769+
path = os.path.join(tmpdir, fname)
1770+
with open(path, "w") as stream:
1771+
stream.write(dedent(content))
1772+
1773+
out = runner.invoke(cli, ["-n", "--find-links", dists_path, path])
1774+
assert out.exit_code == 0, out.stderr
1775+
assert "small-fake-a==0.1" in out.stderr
1776+
assert "small-fake-b==0.2" in out.stderr
1777+
assert "small-fake-c" not in out.stderr
1778+
assert "small-fake-d" not in out.stderr
1779+
assert "small-fake-e" not in out.stderr
1780+
assert "small-fake-f" not in out.stderr

0 commit comments

Comments
 (0)