Skip to content

Commit 99b3a91

Browse files
committed
Remove 'dry run' functionality throughout.
1 parent b53777a commit 99b3a91

24 files changed

+150
-270
lines changed

distutils/archive_util.py

+27-37
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def make_tarball(
6161
base_dir: str | os.PathLike[str],
6262
compress: Literal["gzip", "bzip2", "xz"] | None = "gzip",
6363
verbose: bool = False,
64-
dry_run: bool = False,
6564
owner: str | None = None,
6665
group: str | None = None,
6766
) -> str:
@@ -96,7 +95,7 @@ def make_tarball(
9695
archive_name = base_name + '.tar'
9796
archive_name += compress_ext.get(compress, '')
9897

99-
mkpath(os.path.dirname(archive_name), dry_run=dry_run)
98+
mkpath(os.path.dirname(archive_name))
10099

101100
# creating the tarball
102101
import tarfile # late import so Python build itself doesn't break
@@ -115,21 +114,19 @@ def _set_uid_gid(tarinfo):
115114
tarinfo.uname = owner
116115
return tarinfo
117116

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()
124122

125123
return archive_name
126124

127125

128-
def make_zipfile( # noqa: C901
126+
def make_zipfile(
129127
base_name: str,
130128
base_dir: str | os.PathLike[str],
131129
verbose: bool = False,
132-
dry_run: bool = False,
133130
) -> str:
134131
"""Create a zip file from all the files under 'base_dir'.
135132
@@ -140,7 +137,7 @@ def make_zipfile( # noqa: C901
140137
file.
141138
"""
142139
zip_filename = base_name + ".zip"
143-
mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
140+
mkpath(os.path.dirname(zip_filename))
144141

145142
# If zipfile module is not available, try spawning an external
146143
# 'zip' command.
@@ -151,7 +148,7 @@ def make_zipfile( # noqa: C901
151148
zipoptions = "-rq"
152149

153150
try:
154-
spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
151+
spawn(["zip", zipoptions, zip_filename, base_dir])
155152
except DistutilsExecError:
156153
# XXX really should distinguish between "couldn't find
157154
# external 'zip' command" and "zip failed".
@@ -164,29 +161,26 @@ def make_zipfile( # noqa: C901
164161
else:
165162
log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir)
166163

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, ''))
178177
zip.write(path, path)
179178
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):
183182
zip.write(path, path)
184183
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)
190184

191185
return zip_filename
192186

@@ -219,7 +213,6 @@ def make_archive(
219213
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
220214
base_dir: str | None = None,
221215
verbose: bool = False,
222-
dry_run: bool = False,
223216
owner: str | None = None,
224217
group: str | None = None,
225218
) -> str: ...
@@ -230,7 +223,6 @@ def make_archive(
230223
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes],
231224
base_dir: str | None = None,
232225
verbose: bool = False,
233-
dry_run: bool = False,
234226
owner: str | None = None,
235227
group: str | None = None,
236228
) -> str: ...
@@ -240,7 +232,6 @@ def make_archive(
240232
root_dir: str | os.PathLike[str] | bytes | os.PathLike[bytes] | None = None,
241233
base_dir: str | None = None,
242234
verbose: bool = False,
243-
dry_run: bool = False,
244235
owner: str | None = None,
245236
group: str | None = None,
246237
) -> str:
@@ -264,13 +255,12 @@ def make_archive(
264255
if root_dir is not None:
265256
log.debug("changing into '%s'", root_dir)
266257
base_name = os.path.abspath(base_name)
267-
if not dry_run:
268-
os.chdir(root_dir)
258+
os.chdir(root_dir)
269259

270260
if base_dir is None:
271261
base_dir = os.curdir
272262

273-
kwargs = {'dry_run': dry_run}
263+
kwargs: dict[str, bool | None] = {}
274264

275265
try:
276266
format_info = ARCHIVE_FORMATS[format]

distutils/cmd.py

+6-25
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,8 @@ def __init__(self, dist: Distribution) -> None:
9191

9292
# Per-command versions of the global flags, so that the user can
9393
# customize Distutils' behaviour command-by-command and let some
94-
# commands fall back on the Distribution's behaviour. None means
95-
# "not defined, check self.distribution's copy", while 0 or 1 mean
96-
# false and true (duh). Note that this means figuring out the real
97-
# value of each flag is a touch complicated -- hence "self._dry_run"
98-
# will be handled by __getattr__, below.
99-
# XXX This needs to be fixed.
100-
self._dry_run = None
94+
# commands fall back on the Distribution's behaviour. None means
95+
# "not defined, check self.distribution's copy".
10196

10297
# verbose is largely ignored, but needs to be set for
10398
# backwards compatibility (I think)?
@@ -119,17 +114,6 @@ def __init__(self, dist: Distribution) -> None:
119114
# always calls 'finalize_options()', to respect/update it.
120115
self.finalized = False
121116

122-
# XXX A more explicit way to customize dry_run would be better.
123-
def __getattr__(self, attr):
124-
if attr == 'dry_run':
125-
myval = getattr(self, "_" + attr)
126-
if myval is None:
127-
return getattr(self.distribution, attr)
128-
else:
129-
return myval
130-
else:
131-
raise AttributeError(attr)
132-
133117
def ensure_finalized(self) -> None:
134118
if not self.finalized:
135119
self.finalize_options()
@@ -381,10 +365,10 @@ def execute(
381365
msg: object = None,
382366
level: int = 1,
383367
) -> None:
384-
util.execute(func, args, msg, dry_run=self.dry_run)
368+
util.execute(func, args, msg)
385369

386370
def mkpath(self, name: str, mode: int = 0o777) -> None:
387-
dir_util.mkpath(name, mode, dry_run=self.dry_run)
371+
dir_util.mkpath(name, mode)
388372

389373
@overload
390374
def copy_file(
@@ -425,7 +409,6 @@ def copy_file(
425409
preserve_times,
426410
not self.force,
427411
link,
428-
dry_run=self.dry_run,
429412
)
430413

431414
def copy_tree(
@@ -447,7 +430,6 @@ def copy_tree(
447430
preserve_times,
448431
preserve_symlinks,
449432
not self.force,
450-
dry_run=self.dry_run,
451433
)
452434

453435
@overload
@@ -465,15 +447,15 @@ def move_file(
465447
level: int = 1,
466448
) -> str | os.PathLike[str] | bytes | os.PathLike[bytes]:
467449
"""Move a file respecting dry-run flag."""
468-
return file_util.move_file(src, dst, dry_run=self.dry_run)
450+
return file_util.move_file(src, dst)
469451

470452
def spawn(
471453
self, cmd: MutableSequence[str], search_path: bool = True, level: int = 1
472454
) -> None:
473455
"""Spawn an external command respecting dry-run flag."""
474456
from distutils.spawn import spawn
475457

476-
spawn(cmd, search_path, dry_run=self.dry_run)
458+
spawn(cmd, search_path)
477459

478460
@overload
479461
def make_archive(
@@ -509,7 +491,6 @@ def make_archive(
509491
format,
510492
root_dir,
511493
base_dir,
512-
dry_run=self.dry_run,
513494
owner=owner,
514495
group=group,
515496
)

distutils/command/bdist_dumb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ def run(self):
138138
self.distribution.dist_files.append(('bdist_dumb', pyversion, filename))
139139

140140
if not self.keep_temp:
141-
remove_tree(self.bdist_dir, dry_run=self.dry_run)
141+
remove_tree(self.bdist_dir)

distutils/command/bdist_rpm.py

+23-24
Original file line numberDiff line numberDiff line change
@@ -378,30 +378,29 @@ def run(self) -> None: # noqa: C901
378378

379379
self.spawn(rpm_cmd)
380380

381-
if not self.dry_run:
382-
if self.distribution.has_ext_modules():
383-
pyversion = get_python_version()
384-
else:
385-
pyversion = 'any'
386-
387-
if not self.binary_only:
388-
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
389-
assert os.path.exists(srpm)
390-
self.move_file(srpm, self.dist_dir)
391-
filename = os.path.join(self.dist_dir, source_rpm)
392-
self.distribution.dist_files.append(('bdist_rpm', pyversion, filename))
393-
394-
if not self.source_only:
395-
for rpm in binary_rpms:
396-
rpm = os.path.join(rpm_dir['RPMS'], rpm)
397-
if os.path.exists(rpm):
398-
self.move_file(rpm, self.dist_dir)
399-
filename = os.path.join(self.dist_dir, os.path.basename(rpm))
400-
self.distribution.dist_files.append((
401-
'bdist_rpm',
402-
pyversion,
403-
filename,
404-
))
381+
if self.distribution.has_ext_modules():
382+
pyversion = get_python_version()
383+
else:
384+
pyversion = 'any'
385+
386+
if not self.binary_only:
387+
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
388+
assert os.path.exists(srpm)
389+
self.move_file(srpm, self.dist_dir)
390+
filename = os.path.join(self.dist_dir, source_rpm)
391+
self.distribution.dist_files.append(('bdist_rpm', pyversion, filename))
392+
393+
if not self.source_only:
394+
for rpm in binary_rpms:
395+
rpm = os.path.join(rpm_dir['RPMS'], rpm)
396+
if os.path.exists(rpm):
397+
self.move_file(rpm, self.dist_dir)
398+
filename = os.path.join(self.dist_dir, os.path.basename(rpm))
399+
self.distribution.dist_files.append((
400+
'bdist_rpm',
401+
pyversion,
402+
filename,
403+
))
405404

406405
def _dist_path(self, path):
407406
return os.path.join(self.dist_dir, os.path.basename(path))

distutils/command/build_clib.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def run(self) -> None:
8888
if not self.libraries:
8989
return
9090

91-
self.compiler = new_compiler(
92-
compiler=self.compiler, dry_run=self.dry_run, force=self.force
93-
)
91+
self.compiler = new_compiler(compiler=self.compiler, force=self.force)
9492
customize_compiler(self.compiler)
9593

9694
if self.include_dirs is not None:

distutils/command/build_ext.py

-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ def run(self) -> None: # noqa: C901
326326
self.compiler = new_compiler(
327327
compiler=self.compiler,
328328
verbose=self.verbose,
329-
dry_run=self.dry_run,
330329
force=self.force,
331330
)
332331
customize_compiler(self.compiler)

distutils/command/build_py.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,11 @@ def byte_compile(self, files) -> None:
394394
# method of the "install_lib" command, except for the determination
395395
# of the 'prefix' string. Hmmm.
396396
if self.compile:
397-
byte_compile(
398-
files, optimize=0, force=self.force, prefix=prefix, dry_run=self.dry_run
399-
)
397+
byte_compile(files, optimize=0, force=self.force, prefix=prefix)
400398
if self.optimize > 0:
401399
byte_compile(
402400
files,
403401
optimize=self.optimize,
404402
force=self.force,
405403
prefix=prefix,
406-
dry_run=self.dry_run,
407404
)

distutils/command/build_scripts.py

+13-23
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,24 @@ def _copy_script(self, script, outfiles, updated_files):
8787

8888
# Always open the file, but ignore failures in dry-run mode
8989
# in order to attempt to copy directly.
90-
try:
91-
f = tokenize.open(script)
92-
except OSError:
93-
if not self.dry_run:
94-
raise
95-
f = None
96-
else:
97-
first_line = f.readline()
98-
if not first_line:
99-
self.warn(f"{script} is an empty file (skipping)")
100-
return
90+
f = tokenize.open(script)
91+
92+
first_line = f.readline()
93+
if not first_line:
94+
self.warn(f"{script} is an empty file (skipping)")
95+
return
10196

102-
shebang_match = shebang_pattern.match(first_line)
97+
shebang_match = shebang_pattern.match(first_line)
10398

10499
updated_files.append(outfile)
105100
if shebang_match:
106101
log.info("copying and adjusting %s -> %s", script, self.build_dir)
107-
if not self.dry_run:
108-
post_interp = shebang_match.group(1) or ''
109-
shebang = f"#!python{post_interp}\n"
110-
self._validate_shebang(shebang, f.encoding)
111-
with open(outfile, "w", encoding=f.encoding) as outf:
112-
outf.write(shebang)
113-
outf.writelines(f.readlines())
102+
post_interp = shebang_match.group(1) or ''
103+
shebang = f"#!python{post_interp}\n"
104+
self._validate_shebang(shebang, f.encoding)
105+
with open(outfile, "w", encoding=f.encoding) as outf:
106+
outf.write(shebang)
107+
outf.writelines(f.readlines())
114108
if f:
115109
f.close()
116110
else:
@@ -126,10 +120,6 @@ def _change_modes(self, outfiles):
126120
self._change_mode(file)
127121

128122
def _change_mode(self, file):
129-
if self.dry_run:
130-
log.info("changing mode of %s", file)
131-
return
132-
133123
oldmode = os.stat(file)[ST_MODE] & 0o7777
134124
newmode = (oldmode | 0o555) & 0o7777
135125
if newmode != oldmode:

0 commit comments

Comments
 (0)