Skip to content

Commit 0633a4e

Browse files
committed
feat: add some more backends
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 322cf83 commit 0633a4e

File tree

4 files changed

+174
-33
lines changed

4 files changed

+174
-33
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ you use this.
115115

116116
You can tell check-sdist to look for exclude lists for a specific build backend
117117
with `build-backend`, or `"none"` to only use it's own exclude list. Build
118-
backends supported are `"flit_core.buildapi"`, `"hatchling.build"`, and
119-
`"scikit_build_core.build"`. The default, `"auto"`, will try to detect the build
118+
backends supported are `"flit_core.buildapi"`, `"hatchling.build"`,
119+
`"scikit_build_core.build"`, `"pdm.backend"`, `"maturin"`, and
120+
`"poetry.core.masonry.api"`. The default, `"auto"`, will try to detect the build
120121
backend if `build-system.build-backend` is set to a known value.
121122

122123
### See also

src/check_sdist/backends.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,62 @@ def backend_ignored_patterns(
2828
)
2929

3030
if backend_resolved == "flit_core.buildapi":
31-
flit_core_exclude = (
31+
exclude = (
3232
pyproject.get("tool", {})
3333
.get("flit", {})
3434
.get("sdist", {})
3535
.get("exclude", [])
3636
)
37-
for pattern in flit_core_exclude:
37+
for pattern in exclude:
3838
results = {str(p) for p in Path().glob(pattern)}
3939
files = files - results
4040
return files
4141
if backend_resolved == "hatchling.build":
42-
hatch_exclude = (
42+
exclude = (
4343
pyproject.get("tool", {})
4444
.get("hatch", {})
4545
.get("build", {})
4646
.get("targets", {})
4747
.get("sdist", {})
4848
.get("exclude", [])
4949
)
50-
sdist_spec = pathspec.GitIgnoreSpec.from_lines(hatch_exclude)
50+
sdist_spec = pathspec.GitIgnoreSpec.from_lines(exclude)
5151
return frozenset(p for p in files if not sdist_spec.match_file(p))
5252
if backend_resolved == "scikit_build_core.build":
53-
hatch_exclude = (
53+
exclude = (
5454
pyproject.get("tool", {})
5555
.get("scikit-build", {})
5656
.get("sdist", {})
5757
.get("exclude", [])
5858
)
59-
sdist_spec = pathspec.GitIgnoreSpec.from_lines(hatch_exclude)
59+
sdist_spec = pathspec.GitIgnoreSpec.from_lines(exclude)
6060
return frozenset(p for p in files if not sdist_spec.match_file(p))
61+
if backend_resolved == "pdm.backend":
62+
exclude = (
63+
pyproject.get("tool", {})
64+
.get("pdm", {})
65+
.get("build", {})
66+
.get("excludes", [])
67+
)
68+
for pattern in exclude:
69+
results = {str(p) for p in Path().glob(pattern)}
70+
files = files - results
71+
return files
72+
if backend_resolved == "poetry.core.masonry.api":
73+
exclude = [
74+
x if isinstance(x, str) else x["path"]
75+
for x in pyproject.get("tool", {}).get("poetry", {}).get("exclude", [])
76+
if isinstance(x, str) or "sdist" in x.get("format", ["sdist"])
77+
]
78+
for pattern in exclude:
79+
results = {str(p) for p in Path().glob(pattern)}
80+
files = files - results
81+
if backend_resolved == "maturin":
82+
exclude = pyproject.get("tool", {}).get("maturin", {}).get("exclude", [])
83+
for pattern in exclude:
84+
results = {str(p) for p in Path().glob(pattern)}
85+
files = files - results
86+
return files
6187
if backend != "auto":
6288
msg = f"Unknown backend: {backend} - please add support in check_dist.backends"
6389
raise ValueError(msg)

src/check_sdist/resources/check-sdist.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
"none",
4343
"flit_core.buildapi",
4444
"hatchling.build",
45-
"scikit_build_core.build"
45+
"scikit_build_core.build",
46+
"pdm.backend.api",
47+
"poetry.core.masonry.api",
48+
"maturin"
4649
]
4750
}
4851
}

tests/test_package.py

Lines changed: 135 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ def git_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
3939
subprocess.run(["git", "init"], check=True)
4040
subprocess.run(["git", "config", "user.email", "[email protected]"], check=True)
4141
subprocess.run(["git", "config", "user.name", "CI"], check=True)
42+
Path(".gitignore").write_text(
43+
inspect.cleandoc("""
44+
some-ignored-file.txt
45+
""")
46+
)
47+
Path("example").mkdir()
48+
Path("example/__init__.py").touch()
49+
Path("ignore-me.txt").touch()
50+
Path("not-ignored.txt").touch()
51+
Path("some-file").touch()
52+
Path("some-dir").mkdir()
53+
Path("some-dir/notme.txt").touch()
54+
Path("some-ignored-file.txt").touch()
55+
4256
return tmp_path
4357

4458

@@ -52,7 +66,7 @@ def test_hatchling(backend: str):
5266
build-backend = "hatchling.build"
5367
5468
[project]
55-
name = "hatchling-test"
69+
name = "example"
5670
version = "0.1.0"
5771
5872
[tool.hatch]
@@ -62,19 +76,8 @@ def test_hatchling(backend: str):
6276
build-backend = "{backend}"
6377
""")
6478
)
65-
Path(".gitignore").write_text(
66-
inspect.cleandoc("""
67-
some-ignored-file.txt
68-
""")
69-
)
70-
Path("ignore-me.txt").touch()
71-
Path("not-ignored.txt").touch()
72-
Path("some-file").touch()
73-
Path("some-dir").mkdir()
74-
Path("some-dir/notme.txt").touch()
7579
subprocess.run(["git", "add", "."], check=True)
7680
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True)
77-
Path("some-ignored-file.txt").touch()
7881
assert compare(Path(), isolated=True, verbose=True) == (
7982
0 if backend == "auto" else 2
8083
)
@@ -90,7 +93,7 @@ def test_flit_core(backend: str):
9093
build-backend = "flit_core.buildapi"
9194
9295
[project]
93-
name = "flit-core-test"
96+
name = "example"
9497
version = "0.1.0"
9598
description = "A test package"
9699
@@ -102,21 +105,129 @@ def test_flit_core(backend: str):
102105
build-backend = "{backend}"
103106
""")
104107
)
105-
Path(".gitignore").write_text(
108+
subprocess.run(["git", "add", "."], check=True)
109+
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True)
110+
assert compare(Path(), isolated=True, verbose=True) == (
111+
0 if backend == "auto" else 2
112+
)
113+
114+
115+
@pytest.mark.usefixtures("git_dir")
116+
@pytest.mark.parametrize("backend", ["auto", "none"])
117+
def test_scikit_build_core(backend: str):
118+
Path("pyproject.toml").write_text(
119+
inspect.cleandoc(f"""
120+
[build-system]
121+
requires = ["scikit-build-core"]
122+
build-backend = "scikit_build_core.build"
123+
124+
[project]
125+
name = "example"
126+
version = "0.1.0"
127+
128+
[tool.scikit-build]
129+
sdist.exclude = ["ignore*", "some-file", "**/notme.txt"]
130+
131+
[tool.check-sdist]
132+
build-backend = "{backend}"
133+
""")
134+
)
135+
subprocess.run(["git", "add", "."], check=True)
136+
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True)
137+
assert compare(Path(), isolated=True, verbose=True) == (
138+
0 if backend == "auto" else 2
139+
)
140+
141+
142+
@pytest.mark.usefixtures("git_dir")
143+
@pytest.mark.parametrize("backend", ["auto", "none"])
144+
def test_pdm_backend(backend: str):
145+
Path("pyproject.toml").write_text(
146+
inspect.cleandoc(f"""
147+
[build-system]
148+
requires = ["pdm-backend"]
149+
build-backend = "pdm.backend"
150+
151+
[project]
152+
name = "example"
153+
version = "0.1.0"
154+
155+
[tool.pdm]
156+
build.source-includes = [".gitignore", "not-ignored.txt"]
157+
build.excludes = ["ignore*", "some-file", "**/notme.txt"]
158+
159+
[tool.check-sdist]
160+
build-backend = "{backend}"
161+
""")
162+
)
163+
subprocess.run(["git", "add", "."], check=True)
164+
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True)
165+
assert compare(Path(), isolated=True, verbose=True) == (
166+
0 if backend == "auto" else 2
167+
)
168+
169+
170+
@pytest.mark.skip
171+
@pytest.mark.usefixtures("git_dir")
172+
@pytest.mark.parametrize("backend", ["auto", "none"])
173+
def test_maturin(backend: str):
174+
Path("pyproject.toml").write_text(
175+
inspect.cleandoc(f"""
176+
[build-system]
177+
requires = ["maturin"]
178+
build-backend = "maturin"
179+
180+
[project]
181+
name = "example"
182+
version = "0.1.0"
183+
184+
[tool.maturin]
185+
exclude = ["ignore*", "some-file", "**/notme.txt"]
186+
187+
[tool.check-sdist]
188+
build-backend = "{backend}"
189+
""")
190+
)
191+
Path("Cargo.toml").write_text(
106192
inspect.cleandoc("""
107-
some-ignored-file.txt
108-
""")
193+
[package]
194+
name = "guessing-game"
195+
version = "0.1.0"
196+
edition = "2021"
197+
""")
198+
)
199+
Path("src").mkdir()
200+
Path("src/lib.rs").write_text("")
201+
subprocess.run(["git", "add", "."], check=True)
202+
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True)
203+
assert compare(Path(), isolated=True, verbose=True) == (
204+
0 if backend == "auto" else 2
205+
)
206+
207+
208+
@pytest.mark.usefixtures("git_dir")
209+
@pytest.mark.parametrize("backend", ["auto", "none"])
210+
def test_poetry_core(backend: str):
211+
Path("pyproject.toml").write_text(
212+
inspect.cleandoc(f"""
213+
[build-system]
214+
requires = ["poetry-core"]
215+
build-backend = "poetry.core.masonry.api"
216+
217+
[tool.poetry]
218+
name = "example"
219+
version = "0.1.0"
220+
authors = []
221+
description = "A test package."
222+
include = [".gitignore", "not-ignored.txt"]
223+
exclude = ["ignore*", {{path="some-file", format=["sdist"]}}, "**/notme.txt"]
224+
225+
[tool.check-sdist]
226+
build-backend = "{backend}"
227+
""")
109228
)
110-
Path("ignore-me.txt").touch()
111-
Path("not-ignored.txt").touch()
112-
Path("some-file").touch()
113-
Path("some-dir").mkdir()
114-
Path("some-dir/notme.txt").touch()
115-
Path("flit_core_test").mkdir()
116-
Path("flit_core_test/__init__.py").touch()
117229
subprocess.run(["git", "add", "."], check=True)
118230
subprocess.run(["git", "commit", "-m", "Initial commit"], check=True)
119-
Path("some-ignored-file.txt").touch()
120231
assert compare(Path(), isolated=True, verbose=True) == (
121232
0 if backend == "auto" else 2
122233
)

0 commit comments

Comments
 (0)