File tree Expand file tree Collapse file tree 4 files changed +33
-33
lines changed Expand file tree Collapse file tree 4 files changed +33
-33
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,8 @@ def bootstrap():
47
47
48
48
49
49
def run ():
50
- import zstandard
51
50
from pythonbuild .downloads import DOWNLOADS
52
- from pythonbuild .utils import hash_path
51
+ from pythonbuild .utils import compress_python_archive
53
52
54
53
now = datetime .datetime .utcnow ()
55
54
@@ -66,18 +65,10 @@ def run():
66
65
basename += '.tar'
67
66
68
67
source_path = BUILD / basename
69
- dest_path = DIST / ( 'cpython-%s-linux64%s-%s.tar.zst ' % (
68
+ compress_python_archive ( source_path , DIST , 'cpython-%s-linux64%s-%s' % (
70
69
DOWNLOADS ['cpython-3.7' ]['version' ], extra ,
71
70
now .strftime ('%Y%m%dT%H%M' )))
72
71
73
- print ('compressing Python archive to %s' % dest_path )
74
- with source_path .open ('rb' ) as ifh , dest_path .open ('wb' ) as ofh :
75
- cctx = zstandard .ZstdCompressor (level = 15 )
76
- cctx .copy_stream (ifh , ofh , source_path .stat ().st_size )
77
-
78
- sha256 = hash_path (dest_path )
79
- print ('%s has SHA256 %s' % (dest_path , sha256 ))
80
-
81
72
82
73
if __name__ == '__main__' :
83
74
try :
Original file line number Diff line number Diff line change @@ -37,26 +37,18 @@ def bootstrap():
37
37
38
38
39
39
def run ():
40
- import zstandard
41
40
from pythonbuild .downloads import DOWNLOADS
42
- from pythonbuild .utils import hash_path
41
+ from pythonbuild .utils import compress_python_archive
43
42
44
43
now = datetime .datetime .utcnow ()
45
44
46
45
subprocess .run (['make' ],
47
46
cwd = str (MAKE_DIR ), check = True )
48
47
49
48
source_path = BUILD / 'cpython-macos.tar'
50
- dest_path = DIST / ('cpython-%s-macos-%s.tar.zst' % (
51
- DOWNLOADS ['cpython-3.7' ]['version' ], now .strftime ('%Y%m%dT%H%M' )))
52
-
53
- print ('compressing Python archive to %s' % dest_path )
54
- with source_path .open ('rb' ) as ifh , dest_path .open ('wb' ) as ofh :
55
- cctx = zstandard .ZstdCompressor (level = 15 )
56
- cctx .copy_stream (ifh , ofh , source_path .stat ().st_size )
57
49
58
- sha256 = hash_path ( dest_path )
59
- print ( '%s has SHA256 %s' % ( dest_path , sha256 ))
50
+ compress_python_archive ( source_path , DIST , 'cpython-%s-macos-%s' % (
51
+ DOWNLOADS [ 'cpython-3.7' ][ 'version' ], now . strftime ( '%Y%m%dT%H%M' ) ))
60
52
61
53
62
54
if __name__ == '__main__' :
Original file line number Diff line number Diff line change @@ -37,9 +37,8 @@ def bootstrap():
37
37
38
38
39
39
def run ():
40
- import zstandard
41
40
from pythonbuild .downloads import DOWNLOADS
42
- from pythonbuild .utils import hash_path
41
+ from pythonbuild .utils import compress_python_archive
43
42
44
43
now = datetime .datetime .utcnow ()
45
44
@@ -51,16 +50,9 @@ def run():
51
50
bufsize = 0 )
52
51
53
52
source_path = BUILD / 'cpython-windows.tar'
54
- dest_path = DIST / ('cpython-%s-windows-amd64-%s.tar.zst' % (
55
- DOWNLOADS ['cpython-3.7' ]['version' ], now .strftime ('%Y%m%dT%H%M' )))
56
-
57
- print ('compressing Python archive to %s' % dest_path )
58
- with source_path .open ('rb' ) as ifh , dest_path .open ('wb' ) as ofh :
59
- cctx = zstandard .ZstdCompressor (level = 15 )
60
- cctx .copy_stream (ifh , ofh , source_path .stat ().st_size )
61
53
62
- sha256 = hash_path ( dest_path )
63
- print ( '%s has SHA256 %s' % ( dest_path , sha256 ))
54
+ compress_python_archive ( source_path , DIST , 'cpython-%s-windows-amd64-%s' % (
55
+ DOWNLOADS [ 'cpython-3.7' ][ 'version' ], now . strftime ( '%Y%m%dT%H%M' ) ))
64
56
65
57
66
58
if __name__ == '__main__' :
Original file line number Diff line number Diff line change 9
9
import tarfile
10
10
import urllib .request
11
11
12
+ import zstandard
13
+
12
14
from .downloads import (
13
15
DOWNLOADS ,
14
16
)
@@ -132,3 +134,26 @@ def create_tar_from_directory(fh, base_path: pathlib.Path):
132
134
def extract_tar_to_directory (source : pathlib .Path , dest : pathlib .Path ):
133
135
with tarfile .open (source , 'r' ) as tf :
134
136
tf .extractall (dest )
137
+
138
+
139
+ def compress_python_archive (source_path : pathlib .Path ,
140
+ dist_path : pathlib .Path ,
141
+ basename : str ):
142
+ dest_path = dist_path / ('%s.tar.zst' % basename )
143
+ temp_path = dist_path / ('%s.tar.zst.tmp' % basename )
144
+
145
+ print ('compressing Python archive to %s' % dest_path )
146
+
147
+ try :
148
+ with source_path .open ('rb' ) as ifh , temp_path .open ('wb' ) as ofh :
149
+ cctx = zstandard .ZstdCompressor (level = 15 )
150
+ cctx .copy_stream (ifh , ofh , source_path .stat ().st_size )
151
+
152
+ temp_path .rename (dest_path )
153
+ except Exception :
154
+ temp_path .unlink ()
155
+ raise
156
+
157
+ print ('%s has SHA256 %s' % (dest_path , hash_path (dest_path )))
158
+
159
+ return dest_path
You can’t perform that action at this time.
0 commit comments