Debian Codegraph @

_build_meta/version_provider.py

raw symbols SCIP
1 # FontForge version provider for scikit-build-core
2 # Extracts version from CMakeLists.txt and converts YYYYMMDD to CalVer YYYY.M.D
3
4 from __future__ import annotations
5
6 import re
7 from pathlib import Path
8 from typing import TYPE_CHECKING, Any
9
10 if TYPE_CHECKING:
11 from collections.abc import Mapping
12
13 __all__ = ["dynamic_metadata"]
14
15
16 def dynamic_metadata(
17 field: str,
18 settings: Mapping[str, Any],
19 ) -> str:
20 if field != "version":
21 msg = f"This provider only supports 'version', not {field!r}"
22 raise RuntimeError(msg)
23
24 # Read CMakeLists.txt from project root
25 cmake_file = Path("CMakeLists.txt")
26 if not cmake_file.exists():
27 msg = "CMakeLists.txt not found"
28 raise RuntimeError(msg)
29
30 content = cmake_file.read_text(encoding="utf-8")
31
32 # Extract version from: project(fontforge VERSION 20251009 ...)
33 match = re.search(r"project\s*\(\s*fontforge\s+VERSION\s+(\d{8})", content)
34 if not match:
35 msg = "Could not find project VERSION in CMakeLists.txt"
36 raise RuntimeError(msg)
37
38 version_str = match.group(1)
39
40 # Parse YYYYMMDD format
41 year = version_str[0:4]
42 month = int(version_str[4:6]) # int() strips leading zero
43 day = int(version_str[6:8])
44
45 # Return CalVer format: YYYY.M.D
46 return f"{year}.{month}.{day}"