9
9
import re
10
10
import sys
11
11
import hashlib
12
+ import time
13
+ import requests
12
14
from datetime import datetime
13
15
14
16
import import_tests
@@ -20,7 +22,7 @@ def normalize(name):
20
22
# prerequisite: emsdk, pyodide, packages -> pyodide/packages
21
23
22
24
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 + "/"
24
26
github_url = "https://github.com/cloudflare/pyodide-build-scripts/releases/download/" + tag + "/"
25
27
lock_bytes = (dist / "pyodide-lock.json" ).read_bytes ()
26
28
lock_hash = hashlib .sha256 (lock_bytes ).hexdigest ()
@@ -89,14 +91,64 @@ def upload_to_r2(tag, dist = Path("dist")):
89
91
aws_secret_access_key = os .environ .get ("R2_SECRET_ACCESS_KEY" ),
90
92
region_name = "auto" )
91
93
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
93
97
for root , dirs , files in os .walk (dist ):
94
98
for file in files :
99
+ if file in {"all_wheels.zip" , "pyodide_packages.tar.zip" }:
100
+ continue
95
101
path = Path (root ) / file
96
102
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 :
97
109
print (f"uploading { path } to { key } " )
98
110
s3 .upload_file (str (path ), "python-package-bucket" , key )
99
111
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
+
100
152
# converts all the .zip wheels into .tar.gz format (destructively)
101
153
def convert_wheels_to_tar_gz (dist = Path ("dist" )):
102
154
with open (dist / "pyodide-lock.json" , "r" ) as file :
0 commit comments