@@ -61,7 +61,6 @@ def make_tarball(
61
61
base_dir : str | os .PathLike [str ],
62
62
compress : Literal ["gzip" , "bzip2" , "xz" ] | None = "gzip" ,
63
63
verbose : bool = False ,
64
- dry_run : bool = False ,
65
64
owner : str | None = None ,
66
65
group : str | None = None ,
67
66
) -> str :
@@ -96,7 +95,7 @@ def make_tarball(
96
95
archive_name = base_name + '.tar'
97
96
archive_name += compress_ext .get (compress , '' )
98
97
99
- mkpath (os .path .dirname (archive_name ), dry_run = dry_run )
98
+ mkpath (os .path .dirname (archive_name ))
100
99
101
100
# creating the tarball
102
101
import tarfile # late import so Python build itself doesn't break
@@ -115,21 +114,19 @@ def _set_uid_gid(tarinfo):
115
114
tarinfo .uname = owner
116
115
return tarinfo
117
116
118
- if not dry_run :
119
- tar = tarfile .open (archive_name , f'w|{ tar_compression [compress ]} ' )
120
- try :
121
- tar .add (base_dir , filter = _set_uid_gid )
122
- finally :
123
- tar .close ()
117
+ tar = tarfile .open (archive_name , f'w|{ tar_compression [compress ]} ' )
118
+ try :
119
+ tar .add (base_dir , filter = _set_uid_gid )
120
+ finally :
121
+ tar .close ()
124
122
125
123
return archive_name
126
124
127
125
128
- def make_zipfile ( # noqa: C901
126
+ def make_zipfile (
129
127
base_name : str ,
130
128
base_dir : str | os .PathLike [str ],
131
129
verbose : bool = False ,
132
- dry_run : bool = False ,
133
130
) -> str :
134
131
"""Create a zip file from all the files under 'base_dir'.
135
132
@@ -140,7 +137,7 @@ def make_zipfile( # noqa: C901
140
137
file.
141
138
"""
142
139
zip_filename = base_name + ".zip"
143
- mkpath (os .path .dirname (zip_filename ), dry_run = dry_run )
140
+ mkpath (os .path .dirname (zip_filename ))
144
141
145
142
# If zipfile module is not available, try spawning an external
146
143
# 'zip' command.
@@ -151,7 +148,7 @@ def make_zipfile( # noqa: C901
151
148
zipoptions = "-rq"
152
149
153
150
try :
154
- spawn (["zip" , zipoptions , zip_filename , base_dir ], dry_run = dry_run )
151
+ spawn (["zip" , zipoptions , zip_filename , base_dir ])
155
152
except DistutilsExecError :
156
153
# XXX really should distinguish between "couldn't find
157
154
# external 'zip' command" and "zip failed".
@@ -164,29 +161,26 @@ def make_zipfile( # noqa: C901
164
161
else :
165
162
log .info ("creating '%s' and adding '%s' to it" , zip_filename , base_dir )
166
163
167
- if not dry_run :
168
- try :
169
- zip = zipfile .ZipFile (
170
- zip_filename , "w" , compression = zipfile .ZIP_DEFLATED
171
- )
172
- except RuntimeError :
173
- zip = zipfile .ZipFile (zip_filename , "w" , compression = zipfile .ZIP_STORED )
174
-
175
- with zip :
176
- if base_dir != os .curdir :
177
- path = os .path .normpath (os .path .join (base_dir , '' ))
164
+ try :
165
+ zip = zipfile .ZipFile (zip_filename , "w" , compression = zipfile .ZIP_DEFLATED )
166
+ except RuntimeError :
167
+ zip = zipfile .ZipFile (zip_filename , "w" , compression = zipfile .ZIP_STORED )
168
+
169
+ with zip :
170
+ if base_dir != os .curdir :
171
+ path = os .path .normpath (os .path .join (base_dir , '' ))
172
+ zip .write (path , path )
173
+ log .info ("adding '%s'" , path )
174
+ for dirpath , dirnames , filenames in os .walk (base_dir ):
175
+ for name in dirnames :
176
+ path = os .path .normpath (os .path .join (dirpath , name , '' ))
178
177
zip .write (path , path )
179
178
log .info ("adding '%s'" , path )
180
- for dirpath , dirnames , filenames in os . walk ( base_dir ) :
181
- for name in dirnames :
182
- path = os .path .normpath ( os . path . join ( dirpath , name , '' ))
179
+ for name in filenames :
180
+ path = os . path . normpath ( os . path . join ( dirpath , name ))
181
+ if os .path .isfile ( path ):
183
182
zip .write (path , path )
184
183
log .info ("adding '%s'" , path )
185
- for name in filenames :
186
- path = os .path .normpath (os .path .join (dirpath , name ))
187
- if os .path .isfile (path ):
188
- zip .write (path , path )
189
- log .info ("adding '%s'" , path )
190
184
191
185
return zip_filename
192
186
@@ -219,7 +213,6 @@ def make_archive(
219
213
root_dir : str | os .PathLike [str ] | bytes | os .PathLike [bytes ] | None = None ,
220
214
base_dir : str | None = None ,
221
215
verbose : bool = False ,
222
- dry_run : bool = False ,
223
216
owner : str | None = None ,
224
217
group : str | None = None ,
225
218
) -> str : ...
@@ -230,7 +223,6 @@ def make_archive(
230
223
root_dir : str | os .PathLike [str ] | bytes | os .PathLike [bytes ],
231
224
base_dir : str | None = None ,
232
225
verbose : bool = False ,
233
- dry_run : bool = False ,
234
226
owner : str | None = None ,
235
227
group : str | None = None ,
236
228
) -> str : ...
@@ -240,7 +232,6 @@ def make_archive(
240
232
root_dir : str | os .PathLike [str ] | bytes | os .PathLike [bytes ] | None = None ,
241
233
base_dir : str | None = None ,
242
234
verbose : bool = False ,
243
- dry_run : bool = False ,
244
235
owner : str | None = None ,
245
236
group : str | None = None ,
246
237
) -> str :
@@ -264,13 +255,12 @@ def make_archive(
264
255
if root_dir is not None :
265
256
log .debug ("changing into '%s'" , root_dir )
266
257
base_name = os .path .abspath (base_name )
267
- if not dry_run :
268
- os .chdir (root_dir )
258
+ os .chdir (root_dir )
269
259
270
260
if base_dir is None :
271
261
base_dir = os .curdir
272
262
273
- kwargs = {'dry_run' : dry_run }
263
+ kwargs : dict [ str , bool | None ] = {}
274
264
275
265
try :
276
266
format_info = ARCHIVE_FORMATS [format ]
0 commit comments