Extract the Python version being built from patchlevel.h.
(prefix_path: Path)
| 447 | |
| 448 | |
| 449 | def package_version(prefix_path: Path) -> str: |
| 450 | """Extract the Python version being built from patchlevel.h.""" |
| 451 | for path in prefix_path.glob("**/patchlevel.h"): |
| 452 | text = path.read_text(encoding="utf-8") |
| 453 | if match := re.search( |
| 454 | r'\n\s*#define\s+PY_VERSION\s+"(.+)"\s*\n', text |
| 455 | ): |
| 456 | version = match[1] |
| 457 | # If not building against a tagged commit, add a timestamp to the |
| 458 | # version. Follow the PyPA version number rules, as this will make |
| 459 | # it easier to process with other tools. The version will have a |
| 460 | # `+` suffix once any official release has been made; a freshly |
| 461 | # forked main branch will have a version of 3.X.0a0. |
| 462 | if version.endswith("a0"): |
| 463 | version += "+" |
| 464 | if version.endswith("+"): |
| 465 | version += datetime.now(timezone.utc).strftime("%Y%m%d.%H%M%S") |
| 466 | |
| 467 | return version |
| 468 | |
| 469 | sys.exit("Unable to determine Python version being packaged.") |
| 470 | |
| 471 | |
| 472 | def lib_platform_files(dirname, names): |
no test coverage detected
searching dependent graphs…