|
9 | 9 | - Dependencies are available |
10 | 10 | """ |
11 | 11 |
|
12 | | -import os |
13 | 12 | import re |
14 | 13 | import subprocess |
15 | 14 | import sys |
16 | 15 | from pathlib import Path |
17 | 16 |
|
| 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 | + |
18 | 24 |
|
19 | 25 | def check_version(): |
20 | 26 | """Check that version is valid and follows semantic versioning.""" |
@@ -48,24 +54,27 @@ def check_pyproject_toml(): |
48 | 54 | print(" ❌ pyproject.toml not found") |
49 | 55 | return False |
50 | 56 |
|
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 |
69 | 78 |
|
70 | 79 |
|
71 | 80 | def check_readme(): |
|
0 commit comments