Skip to content

Commit 78a8a6f

Browse files
authored
fix: setuptools support (#6)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 40953c7 commit 78a8a6f

File tree

8 files changed

+71
-8
lines changed

8 files changed

+71
-8
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ repos:
4848
rev: "v1.1.1"
4949
hooks:
5050
- id: mypy
51-
files: src
51+
files: src|tests
5252
args: []
53-
additional_dependencies: ["tomli", "pathspec", "importlib-resources"]
53+
additional_dependencies:
54+
["tomli", "pathspec", "importlib-resources", "pytest"]
5455

5556
- repo: https://github.com/henryiii/check-sdist
5657
rev: "v0.1.0"

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,20 @@ testpaths = [
7171

7272

7373
[tool.mypy]
74-
files = "src"
74+
files = ["src", "tests"]
7575
python_version = "3.8"
7676
warn_unused_configs = true
7777
strict = true
7878
show_error_codes = true
7979
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
8080
warn_unreachable = true
81+
disallow_untyped_defs = false
82+
disallow_incomplete_defs = false
83+
84+
[[tool.mypy.overrides]]
85+
module = "check_sdist.*"
86+
disallow_untyped_defs = true
87+
disallow_incomplete_defs = true
8188

8289

8390
[tool.ruff]

src/check_sdist/__main__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .sdist import sdist_files
1414

1515

16-
def compare(source_dir: Path, isolated: bool, verbose: bool = False) -> int:
16+
def compare(source_dir: Path, *, isolated: bool, verbose: bool = False) -> int:
1717
"""
1818
Compare the files in the SDist with the files tracked by git.
1919
@@ -41,6 +41,7 @@ def compare(source_dir: Path, isolated: bool, verbose: bool = False) -> int:
4141
if default_ignore:
4242
with resources.joinpath("default-ignore.txt").open("r", encoding="utf-8") as f:
4343
git_only_patterns.extend(f.read().splitlines())
44+
sdist_only_patterns.extend("*.dist-info")
4445

4546
sdist_spec = pathspec.GitIgnoreSpec.from_lines(sdist_only_patterns)
4647
git_spec = pathspec.GitIgnoreSpec.from_lines(git_only_patterns)
@@ -99,7 +100,9 @@ def main() -> None:
99100
if args.inject_junk:
100101
stack.enter_context(inject_junk_files(args.source_dir))
101102

102-
raise SystemExit(compare(args.source_dir, not args.no_isolation, args.verbose))
103+
raise SystemExit(
104+
compare(args.source_dir, isolated=not args.no_isolation, verbose=args.verbose)
105+
)
103106

104107

105108
if __name__ == "__main__":

src/check_sdist/resources/default-ignore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
noxfile.py
55
.coverage
66
codecov.yml
7+
*.dist-info

src/check_sdist/sdist.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def sdist_files(source_dir: Path, isolated: bool) -> frozenset[str]:
2323
if len(prefixes) != 1:
2424
msg = f"malformted SDist, contains multiple packages {prefixes}"
2525
raise AssertionError(msg)
26-
return frozenset(n.split("/", maxsplit=1)[1] for n in tar.getnames())
26+
return frozenset(
27+
t.name.split("/", maxsplit=1)[1] for t in tar.getmembers() if t.isfile()
28+
)
2729

2830

2931
if __name__ == "__main__":

tests/downstream.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[[packages]]
2+
repo = "pypa/build"
3+
ref = "0.10.0"
4+
fail = 2
5+
6+
[[packages]]
7+
repo = "FriedrichFroebel/pelican-youtube-thumbnails"
8+
ref = "0.3.2"
9+
fail = 2
10+
11+
[[packages]]
12+
repo = "pypa/setuptools"
13+
ref = "v67.6.1"
14+
fail = 2
15+
16+
[[packages]]
17+
repo = "scikit-build/scikit-build-core"
18+
ref = "v0.2.1"
19+
20+
[[packages]]
21+
repo = "pybind/pybind11"
22+
ref = "v2.10.3"
23+
fail = 2

tests/test_downstream.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
import subprocess
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
from check_sdist.__main__ import compare
9+
from check_sdist._compat import tomllib
10+
11+
DIR = Path(__file__).parent.resolve()
12+
13+
with DIR.joinpath("downstream.toml").open("rb") as f:
14+
packages = tomllib.load(f)["packages"]
15+
16+
17+
@pytest.mark.parametrize(
18+
("repo", "ref", "fail"), [(x["repo"], x["ref"], x.get("fail", 0)) for x in packages]
19+
)
20+
def test_packages(repo, ref, fail, tmp_path, monkeypatch):
21+
monkeypatch.chdir(tmp_path)
22+
subprocess.run(
23+
["git", "clone", f"https://github.com/{repo}", "--branch", ref], check=True
24+
)
25+
package_path = tmp_path / repo.split("/")[1]
26+
assert compare(package_path, isolated=True) == fail

tests/test_package.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def get_all_files(path: Path) -> frozenset[str]:
1616

1717
def test_self_dir():
1818
start = get_all_files(DIR.parent)
19-
assert compare(DIR.parent, True) == 0
19+
assert compare(DIR.parent, isolated=True) == 0
2020
end = get_all_files(DIR.parent)
2121
assert start == end
2222

2323

2424
def test_self_dir_injected():
2525
start = get_all_files(DIR.parent)
2626
with inject_junk_files(DIR.parent):
27-
assert compare(DIR.parent, True) == 0
27+
assert compare(DIR.parent, isolated=True) == 0
2828
end = get_all_files(DIR.parent)
2929
assert start == end

0 commit comments

Comments
 (0)