Skip to content

Commit

Permalink
chore: run update_interpreters_download in update-dependencies workfl…
Browse files Browse the repository at this point in the history
…ow (#1540)
  • Loading branch information
mayeut committed Oct 7, 2023
1 parent 72cdc42 commit 746f50a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/update-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
run: nox --force-color --error-on-missing-interpreters -s update_native_dependencies
env:
GITHUB_API_TOKEN: ${{ steps.generate-token.outputs.token || github.token }}
- name: "Run update downloaded interpreters"
run: nox --force-color --error-on-missing-interpreters -s update_interpreters_download
- name: "Run update python dependencies"
run: nox --force-color --error-on-missing-interpreters -s update_python_dependencies update_python_tools
- name: Create Pull Request
Expand Down
26 changes: 20 additions & 6 deletions tools/update_interpreters_download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import argparse
import json
import subprocess
from hashlib import sha256
from pathlib import Path

Expand All @@ -13,7 +15,7 @@
PYTHON_VERSIONS = PROJECT_ROOT / "docker" / "build_scripts" / "python_versions.json"


def update_pypy_version(releases, py_spec, pp_spec, tag, arch, version_dict):
def update_pypy_version(releases, py_spec, pp_spec, tag, arch, version_dict, updates):
pypy_arch = {"x86_64": "x64"}.get(arch, arch)
current_version = None
if "version" in version_dict:
Expand All @@ -32,7 +34,8 @@ def update_pypy_version(releases, py_spec, pp_spec, tag, arch, version_dict):
)
except StopIteration:
continue
print(f"updating {tag} {arch} to {r['pypy_version']}")
message = f"updating {tag} {arch} to {r['pypy_version']}"
print(message)
response = requests.get(file["download_url"], stream=True)
response.raise_for_status()
sha256sum = sha256()
Expand All @@ -41,10 +44,11 @@ def update_pypy_version(releases, py_spec, pp_spec, tag, arch, version_dict):
version_dict["version"] = str(r["pypy_version"])
version_dict["download_url"] = file["download_url"]
version_dict["sha256"] = sha256sum.hexdigest()
updates.append(message)
break


def update_pypy_versions(versions):
def update_pypy_versions(versions, updates):
response = requests.get("https://downloads.python.org/pypy/versions.json")
response.raise_for_status()
releases = [r for r in response.json() if r["pypy_version"] != "nightly"]
Expand Down Expand Up @@ -74,14 +78,24 @@ def update_pypy_versions(versions):
pp_spec = Specifier(f"=={pp_major}.{pp_minor}.*")
for arch in versions[tag]:
update_pypy_version(
releases, py_spec, pp_spec, tag, arch, versions[tag][arch]
releases, py_spec, pp_spec, tag, arch, versions[tag][arch], updates
)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--dry-run", dest="dry_run", action="store_true", help="dry run")
args = parser.parse_args()
versions = json.loads(PYTHON_VERSIONS.read_text())
update_pypy_versions(versions)
PYTHON_VERSIONS.write_text(json.dumps(versions, indent=2))
updates = []
update_pypy_versions(versions, updates)
if not args.dry_run:
PYTHON_VERSIONS.write_text(json.dumps(versions, indent=2))
if updates:
details = "\n".join(f"- {message}" for message in updates)
subprocess.check_call(
["git", "commit", "-am", "Update downloaded interpreters", "-m", details]
)


if __name__ == "__main__":
Expand Down

0 comments on commit 746f50a

Please sign in to comment.