Skip to content

Commit dc117eb

Browse files
committed
refactor: derive package artifact validation paths
1 parent 703267a commit dc117eb

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

‎scripts/validate_package_artifact.py‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343
"docs/",
4444
"examples/",
4545
"compatibility/",
46-
"lib/python/base_cli/",
46+
f"lib/python/{IMPORT_NAME}/",
4747
"scripts/",
4848
"tests/",
4949
"base_cli.egg-info/",
50-
"lib/python/base_cli.egg-info/",
50+
f"lib/python/{IMPORT_NAME}.egg-info/",
5151
)
5252

5353

@@ -64,24 +64,14 @@ def read_expected_version() -> str:
6464
return lines[0].strip()
6565

6666

67-
def expected_package_files() -> set[str]:
67+
def expected_package_hashes() -> dict[str, str]:
6868
package_root = Path(__file__).resolve().parents[1] / "lib" / "python" / IMPORT_NAME
6969
if not package_root.is_dir():
7070
fail(f"package source directory does not exist: {package_root}")
7171
return {
72-
path.relative_to(package_root).as_posix()
73-
for path in package_root.rglob("*")
74-
if path.is_file() and "__pycache__" not in path.parts and path.suffix != ".pyc"
75-
}
76-
77-
78-
def expected_package_hashes() -> dict[str, str]:
79-
package_root = Path(__file__).resolve().parents[1] / "lib" / "python" / IMPORT_NAME
80-
return {
81-
relative.as_posix(): hashlib.sha256(path.read_bytes()).hexdigest()
72+
path.relative_to(package_root).as_posix(): hashlib.sha256(path.read_bytes()).hexdigest()
8273
for path in package_root.rglob("*")
8374
if path.is_file() and "__pycache__" not in path.parts and path.suffix != ".pyc"
84-
for relative in [path.relative_to(package_root)]
8575
}
8676

8777

@@ -234,7 +224,7 @@ def validate_sdist(path: Path, expected_version: str, package_hashes: dict[str,
234224
relative = name[len(root_prefix) :]
235225
if relative not in ALLOWED_SDIST_FILES and not relative.startswith(ALLOWED_SDIST_PREFIXES):
236226
fail(f"{path.name} contains non-allowlisted archive member {relative!r}")
237-
package_prefix = "lib/python/base_cli/"
227+
package_prefix = f"lib/python/{IMPORT_NAME}/"
238228
if relative.startswith(package_prefix):
239229
package_relative = relative[len(package_prefix) :]
240230
payload = archive.extractfile(member)

‎tests/test_validate_package_artifact.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
def _write_valid_wheel(path: Path, *, include_directory: bool = False, include_symlink: bool = False) -> None:
2020
package_init = b"from __future__ import annotations\n"
21-
metadata = """Metadata-Version: 2.1
21+
metadata = b"""Metadata-Version: 2.1
2222
Name: base-cli
2323
Version: 0.5.1
2424
License: Apache-2.0
@@ -29,7 +29,7 @@ def _write_valid_wheel(path: Path, *, include_directory: bool = False, include_s
2929
Project-URL: Documentation, https://basefoundry.github.io/base-cli/
3030
3131
README
32-
""".encode()
32+
"""
3333
with zipfile.ZipFile(path, "w") as archive:
3434
if include_directory:
3535
directory = zipfile.ZipInfo("base_cli/")

0 commit comments

Comments
 (0)