| 738 | |
| 739 | |
| 740 | def package_version(prefix_dir): |
| 741 | patchlevel_glob = f"{prefix_dir}/include/python*/patchlevel.h" |
| 742 | patchlevel_paths = glob(patchlevel_glob) |
| 743 | if len(patchlevel_paths) != 1: |
| 744 | sys.exit(f"{patchlevel_glob} matched {len(patchlevel_paths)} paths.") |
| 745 | |
| 746 | for line in open(patchlevel_paths[0]): |
| 747 | if match := re.fullmatch(r'\s*#define\s+PY_VERSION\s+"(.+)"\s*', line): |
| 748 | version = match[1] |
| 749 | break |
| 750 | else: |
| 751 | sys.exit(f"Failed to find Python version in {patchlevel_paths[0]}.") |
| 752 | |
| 753 | # If not building against a tagged commit, add a timestamp to the version. |
| 754 | # Follow the PyPA version number rules, as this will make it easier to |
| 755 | # process with other tools. |
| 756 | if version.endswith("+"): |
| 757 | version += datetime.now(timezone.utc).strftime("%Y%m%d.%H%M%S") |
| 758 | |
| 759 | return version |
| 760 | |
| 761 | |
| 762 | def package(context): |