Files
TheRock/build_tools/github_actions/python_to_cp_version.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

66 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
"""Determines part of the path to the Python interpreter in a manylinux image, along
with being used in populating the wheel names for Linux and Windows
Example usage:
python python_to_cp_version.py --python-version 3.12
The following string is appended to the file specified in the "GITHUB_ENV"
environment variable:
cp_version=cp312-cp312
Writing the output to the "GITHUB_ENV" file can be suppressed by passing
`--no-write-env-file`.
"""
import argparse
import re
import sys
from github_actions_api import *
def is_version(version) -> bool:
return re.match(r"^([1-9])\.((0|([1-9][0-9]*)))(t)?$", version) is not None
def transform_python_version(python_version: str) -> str:
if not is_version(python_version):
raise ValueError(f"Version '{python_version}' did not match accepted regex")
version_without_dot = python_version.replace(".", "")
cp_version = f"cp{version_without_dot}-cp{version_without_dot}"
return cp_version
def main(argv: list[str]):
p = argparse.ArgumentParser(prog="python_to_cp_version.py")
p.add_argument(
"--python-version",
required=True,
type=str,
help="Python version to be transformed (e.g. 3.12)",
)
p.add_argument(
"--write-env-file",
action=argparse.BooleanOptionalAction,
default=True,
help="Write `cp_version` to GITHUB_ENV file",
)
args = p.parse_args(argv)
cp_version = transform_python_version(args.python_version)
print(cp_version)
if args.write_env_file:
gha_set_env({"cp_version": cp_version})
if __name__ == "__main__":
main(sys.argv[1:])