Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_python_test_versions fixes #707

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
# automatically generated by ci/update_python_test_versions.py
matrix:
python-version:
[
Expand All @@ -200,20 +201,6 @@ jobs:
3.9.0,
3.9.20,
3.10.0,
3.10.1,
3.10.2,
3.10.3,
3.10.4,
3.10.5,
3.10.6,
3.10.7,
3.10.8,
3.10.9,
3.10.10,
3.10.11,
3.10.12,
3.10.13,
3.10.14,
3.10.15,
3.11.0,
3.11.1,
Expand All @@ -227,6 +214,13 @@ jobs:
3.11.9,
3.11.10,
3.12.0,
3.12.1,
3.12.2,
3.12.3,
3.12.4,
3.12.5,
3.12.6,
3.12.7,
]
# TODO: also test windows
os: [ubuntu-20.04, macos-13]
Expand Down Expand Up @@ -256,6 +250,20 @@ jobs:
python-version: 3.11.10
- os: macos-13
python-version: 3.12.0
- os: macos-13
python-version: 3.12.1
- os: macos-13
python-version: 3.12.2
- os: macos-13
python-version: 3.12.3
- os: macos-13
python-version: 3.12.4
- os: macos-13
python-version: 3.12.5
- os: macos-13
python-version: 3.12.6
- os: macos-13
python-version: 3.12.7

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
python-version: 3.9
- name: Install
run: pip install --upgrade requests
run: pip install --upgrade requests yaml
- name: Scan for new python versions
run: python ci/update_python_test_versions.py
- name: Format results
Expand Down
62 changes: 38 additions & 24 deletions ci/update_python_test_versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import defaultdict
import requests
import pathlib
import yaml
import re


Expand Down Expand Up @@ -37,47 +38,60 @@ def get_github_python_versions():

# for older versions of python, don't test all patches
# (just test first and last) to keep the test matrix down
if (major == 2 or minor < 10):
if major == 2 or minor <= 10:
patches = [patches[0], patches[-1]]

if (major == 3 and minor >= 12):
if major == 3 and minor >= 13:
continue

versions.extend(f"{major}.{minor}.{patch}" for patch in patches)

return versions


if __name__ == "__main__":
versions = sorted(
get_github_python_versions(), key=parse_version)
build_yml = (
def update_python_test_versions():
versions = sorted(get_github_python_versions(), key=parse_version)
build_yml_path = (
pathlib.Path(__file__).parent.parent / ".github" / "workflows" / "build.yml"
)

build_yml = yaml.safe_load(open(".github/workflows/build.yml"))
test_matrix = build_yml["jobs"]["test-wheels"]["strategy"]["matrix"]
existing_python_versions = test_matrix["python-version"]
if versions == existing_python_versions:
return

print("Adding new versions")
print("Old:", existing_python_versions)
print("New:", versions)

# we can't use the yaml package to update the GHA script, since
# the data in build_yml is treated as an unordered dictionary.
# instead modify the file in place
lines = list(open(build_yml_path))
first_line = lines.index(
" # automatically generated by ci/update_python_test_versions.py\n"
)

transformed = []
for line in open(build_yml):
if line.startswith(" python-version: ["):
newversions = f" python-version: [{', '.join(v for v in versions)}]\n"
if newversions != line:
print("Adding new versions")
print("Old:", line)
print("New:", newversions)
line = newversions
transformed.append(line)
first_version_line = lines.index(" [\n", first_line)
last_version_line = lines.index(" ]\n", first_version_line)
new_versions = [f" {v},\n" for v in versions]
lines = lines[: first_version_line + 1] + new_versions + lines[last_version_line:]

# also automatically exclude v3.11.* from running on OSX,
# also automatically exclude >= v3.11.* from running on OSX,
# since it currently fails in GHA on SIP errors
exclusions = []
for v in versions:
if v.startswith("3.11"):
if v.startswith("3.11") or v.startswith("3.12"):
exclusions.append(" - os: macos-13\n")
exclusions.append(f" python-version: {v}\n")
test_wheels = transformed.index(" test-wheels:\n")
first_line = transformed.index(" exclude:\n", test_wheels)
last_line = transformed.index("\n", first_line)
transformed = transformed[:first_line+1] + exclusions + transformed[last_line:]
first_exclude_line = lines.index(" exclude:\n", first_line)
last_exclude_line = lines.index("\n", first_exclude_line)
lines = lines[: first_exclude_line + 1] + exclusions + lines[last_exclude_line:]

with open(build_yml_path, "w") as o:
o.write("".join(lines))

with open(build_yml, "w") as o:
o.write("".join(transformed))

if __name__ == "__main__":
update_python_test_versions()
Loading