Skip to content

Commit 5b860de

Browse files
authored
Merge pull request #3 from cloudflare/ggu/use-proxy-url
Update package bucket url
2 parents 2216ad6 + 6a0f45a commit 5b860de

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

.github/workflows/build-packages.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Set up Python
3232
uses: actions/setup-python@v4
3333
with:
34-
python-version: 3.12
34+
python-version: 3.12.3
3535

3636
- name: Install dependencies
3737
env:

packages/script.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import re
1010
import sys
1111
import hashlib
12+
import time
13+
import requests
1214
from datetime import datetime
1315

1416
import import_tests
@@ -20,7 +22,7 @@ def normalize(name):
2022
# prerequisite: emsdk, pyodide, packages -> pyodide/packages
2123

2224
def gen_bzl_config(tag, dist):
23-
bucket_url = "https://pub-45d734c4145d4285b343833ee450ef38.r2.dev/" + tag + "/"
25+
bucket_url = "https://pyodide.edgeworker.net/python-package-bucket/" + tag + "/"
2426
github_url = "https://github.com/cloudflare/pyodide-build-scripts/releases/download/" + tag + "/"
2527
lock_bytes = (dist / "pyodide-lock.json").read_bytes()
2628
lock_hash = hashlib.sha256(lock_bytes).hexdigest()
@@ -89,14 +91,64 @@ def upload_to_r2(tag, dist = Path("dist")):
8991
aws_secret_access_key = os.environ.get("R2_SECRET_ACCESS_KEY"),
9092
region_name="auto")
9193

92-
# upload entire dist directory to r2
94+
files_remaining = []
95+
96+
# upload entire dist directory to r2, excluding all_wheels.zip and pyodide_packages.tar.zip
9397
for root, dirs, files in os.walk(dist):
9498
for file in files:
99+
if file in {"all_wheels.zip", "pyodide_packages.tar.zip"}:
100+
continue
95101
path = Path(root) / file
96102
key = tag + "/" + str(path.relative_to(dist))
103+
files_remaining.append((path, key))
104+
105+
# attempt to upload each file 5 times. If after 5 attempts the file is still not accessible at pyodide.edgeworker.net then give up
106+
ATTEMPTS = 5
107+
for i in range(ATTEMPTS):
108+
for (path, key) in files_remaining:
97109
print(f"uploading {path} to {key}")
98110
s3.upload_file(str(path), "python-package-bucket", key)
99111

112+
new_files_remaining = []
113+
114+
time.sleep(10)
115+
116+
for (path, key) in files_remaining:
117+
# Construct URL to fetch the uploaded file
118+
url = f"https://pyodide.edgeworker.net/python-package-bucket/{key}"
119+
print(f"Checking {url}")
120+
121+
try:
122+
# Download the file content from the URL
123+
response = requests.get(url)
124+
response.raise_for_status() # Raise an exception if the status is not 200 OK
125+
126+
# Read the local file content
127+
with open(path, 'rb') as f:
128+
local_content = f.read()
129+
130+
# Compare contents
131+
if local_content == response.content:
132+
print(f"{path} uploaded successfully.")
133+
else:
134+
print(f"Content mismatch for {path}. Retrying...")
135+
new_files_remaining.append((path, key))
136+
except requests.exceptions.RequestException as e:
137+
print(f"Failed to verify {path}: {e}. Retrying...")
138+
new_files_remaining.append((path, key))
139+
140+
files_remaining = new_files_remaining
141+
142+
if not files_remaining:
143+
break
144+
145+
if i != ATTEMPTS - 1:
146+
for (path, key) in files_remaining:
147+
s3.delete_object(Bucket="python-package-bucket", Key=key)
148+
149+
if files_remaining:
150+
raise Exception("Failed to upload packages after 5 attempts: ", files_remaining)
151+
100152
# converts all the .zip wheels into .tar.gz format (destructively)
101153
def convert_wheels_to_tar_gz(dist = Path("dist")):
102154
with open(dist / "pyodide-lock.json", "r") as file:

0 commit comments

Comments
 (0)