@@ -50,11 +50,12 @@ def make_bundle(tag, dist = Path("dist")):
50
50
json .dump (lock , file )
51
51
for package in lock ["packages" ].values ():
52
52
name = normalize (package ["name" ])
53
+ print ("untarring " + name )
54
+ os .mkdir (tempdir / name )
53
55
if name .endswith ("-tests" ) or name == "test" :
54
- os .mkdir (tempdir / name )
55
56
continue
56
57
file = dist / package ["file_name" ]
57
- with zipfile . ZipFile (file , "r" ) as zip :
58
+ with tarfile . open (file , "r:gz " ) as zip :
58
59
zip .extractall (tempdir / name )
59
60
# create temp tarfile from tempdir
60
61
with tarfile .open (tempdir / "pyodide_packages.tar" , "w" ) as tar :
@@ -87,17 +88,49 @@ def upload_to_r2(tag, dist = Path("dist")):
87
88
print (f"uploading { path } to { key } " )
88
89
s3 .upload_file (str (path ), "python-package-bucket" , key )
89
90
91
+ # converts all the .zip wheels into .tar.gz format (destructively)
92
+ def convert_wheels_to_tar_gz (dist = Path ("dist" )):
93
+ with open (dist / "pyodide-lock.json" , "r" ) as file :
94
+ lock = json .load (file )
95
+
96
+ for package in lock ["packages" ].values ():
97
+ name = normalize (package ["name" ])
98
+ file = dist / package ["file_name" ]
99
+ # check file ends with .zip or .whl
100
+ if not (file .name .endswith (".zip" ) or file .name .endswith (".whl" )):
101
+ continue
102
+ new_file = file .with_suffix (".tar.gz" )
103
+ print ("Converting zip file " + str (file ) + " to .tar.gz format" )
104
+ with zipfile .ZipFile (file , "r" ) as zip :
105
+ with tempfile .TemporaryDirectory () as t :
106
+ tempdir = Path (t )
107
+ zip .extractall (tempdir )
108
+ # create tar.gz file from tempdir
109
+ with tarfile .open (new_file , "w:gz" ) as tar :
110
+ tar .add (tempdir , arcname = "./" )
111
+ os .remove (file )
112
+ package ["file_name" ] = new_file .name
113
+ # update sha256 hash
114
+ new_file_bytes = new_file .read_bytes ()
115
+ new_file_hash = hashlib .sha256 (new_file_bytes ).hexdigest ()
116
+ package ["sha256" ] = new_file_hash
117
+
118
+ with open (dist / "pyodide-lock.json" , "w" ) as file :
119
+ json .dump (lock , file )
120
+
90
121
if __name__ == "__main__" :
122
+ if len (sys .argv ) != 2 :
123
+ print ("Usage: python script.py <tag>" )
124
+ sys .exit (1 )
125
+ tag = sys .argv [1 ]
126
+
91
127
with open ("required_packages.txt" , "r" ) as file :
92
128
required_packages = file .read ().split ("\n " )
93
129
status = os .system (f"pyodide build-recipes --install { ' ' .join (required_packages )} " )
94
130
if status != 0 :
95
131
raise Exception ("Failed to build recipes" )
96
-
97
- if len (sys .argv ) != 2 :
98
- print ("Usage: python script.py <tag>" )
99
- sys .exit (1 )
100
- tag = sys .argv [1 ]
132
+
133
+ convert_wheels_to_tar_gz ()
101
134
102
135
make_bundle (tag )
103
136
upload_to_r2 (tag )
0 commit comments