Skip to content

Commit 83c1efe

Browse files
authored
Merge pull request #15 from OpenHCSDev/fix/release-readiness-project-declaration-20261005
Validate declared project metadata during release readiness
2 parents 73d48bf + 0ee030b commit 83c1efe

3 files changed

Lines changed: 51 additions & 19 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dependencies = [
3333
[project.optional-dependencies]
3434
dev = [
3535
"pytest>=7.0",
36+
"tomli>=2.0.1; python_version < '3.11'",
3637
"pytest-cov>=4.0",
3738
"ruff>=0.1.0",
3839
"black>=23.0",

‎scripts/verify_release_ready.py‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
- Dependencies are available
1010
"""
1111

12-
import os
1312
import re
1413
import subprocess
1514
import sys
1615
from pathlib import Path
1716

17+
from packaging.utils import InvalidName, canonicalize_name
18+
19+
if sys.version_info >= (3, 11):
20+
import tomllib
21+
else:
22+
import tomli as tomllib
23+
1824

1925
def check_version():
2026
"""Check that version is valid and follows semantic versioning."""
@@ -48,24 +54,27 @@ def check_pyproject_toml():
4854
print(" ❌ pyproject.toml not found")
4955
return False
5056

51-
content = pyproject_file.read_text()
52-
required_fields = {
53-
'name': r'name\s*=\s*["\']openhcs["\']',
54-
'version': r'version\s*=',
55-
'description': r'description\s*=',
56-
'authors': r'authors\s*=',
57-
'build-backend': r'build-backend\s*=\s*["\']setuptools\.build_meta["\']',
58-
}
59-
60-
all_found = True
61-
for field, pattern in required_fields.items():
62-
if not re.search(pattern, content):
63-
print(f" ❌ Missing or invalid field: {field}")
64-
all_found = False
65-
66-
if all_found:
67-
print(" ✅ All required fields present")
68-
return all_found
57+
with pyproject_file.open("rb") as project_file:
58+
declaration = tomllib.load(project_file)
59+
project = declaration.get("project", {})
60+
name = project.get("name")
61+
if not isinstance(name, str):
62+
print(" ❌ Missing or invalid project.name")
63+
return False
64+
try:
65+
canonicalize_name(name, validate=True)
66+
except InvalidName:
67+
print(" ❌ Invalid project.name")
68+
return False
69+
for field in ("version", "description", "authors"):
70+
if not project.get(field):
71+
print(f" ❌ Missing or invalid project.{field}")
72+
return False
73+
if not declaration.get("build-system", {}).get("build-backend"):
74+
print(" ❌ Missing build-system.build-backend")
75+
return False
76+
print(f" ✅ Declared project metadata present: {name}")
77+
return True
6978

7079

7180
def check_readme():

‎tests/test_release_readiness.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Readiness checks consume the repository's declared project metadata."""
2+
3+
import runpy
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
9+
CHECKS = runpy.run_path(str(Path(__file__).parents[1] / "scripts/verify_release_ready.py"))
10+
PROJECT = (Path(__file__).parents[1] / "pyproject.toml").read_text()
11+
12+
13+
def test_actual_project_declaration_is_release_ready(monkeypatch):
14+
monkeypatch.chdir(Path(__file__).parents[1])
15+
assert CHECKS["check_pyproject_toml"]()
16+
17+
18+
@pytest.mark.parametrize("name", ('name = "invalid name"', ""))
19+
def test_missing_or_invalid_project_name_is_rejected(tmp_path, monkeypatch, name):
20+
(tmp_path / "pyproject.toml").write_text(PROJECT.replace('name = "python-introspect"', name))
21+
monkeypatch.chdir(tmp_path)
22+
assert not CHECKS["check_pyproject_toml"]()

0 commit comments

Comments
 (0)