| 25 | |
| 26 | |
| 27 | def build_expected_version_hex(matches: dict[str, str]) -> str: |
| 28 | patch_level_serial = matches["PATCH"] |
| 29 | serial = None |
| 30 | major = int(matches["MAJOR"]) |
| 31 | minor = int(matches["MINOR"]) |
| 32 | flds = patch_level_serial.split(".") |
| 33 | if flds: |
| 34 | patch = int(flds[0]) |
| 35 | if len(flds) == 1: |
| 36 | level = "0" |
| 37 | serial = 0 |
| 38 | elif len(flds) == 2: |
| 39 | level_serial = flds[1] |
| 40 | for level in ("a", "b", "c", "dev"): |
| 41 | if level_serial.startswith(level): |
| 42 | serial = int(level_serial[len(level) :]) |
| 43 | break |
| 44 | if serial is None: |
| 45 | msg = f'Invalid PYBIND11_VERSION_PATCH: "{patch_level_serial}"' |
| 46 | raise RuntimeError(msg) |
| 47 | version_hex_str = f"{major:02x}{minor:02x}{patch:02x}{level[:1]}{serial:x}" |
| 48 | return f"0x{version_hex_str.upper()}" |
| 49 | |
| 50 | |
| 51 | # PYBIND11_GLOBAL_SDIST will build a different sdist, with the python-headers |