Skip to content

Commit 60c1b37

Browse files
committed
Merge branch 'debt/dry-run' of https://github.com/pypa/distutils into debt/dry-run
2 parents fb1013d + 99b3a91 commit 60c1b37

25 files changed

+155
-296
lines changed

Diff for: setuptools/_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]

Diff for: setuptools/_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
)

Diff for: setuptools/_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)

Diff for: setuptools/_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))

Diff for: setuptools/_distutils/command/build.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010
from collections.abc import Callable
1111
from typing import ClassVar
1212

13+
from ..ccompiler import show_compilers
1314
from ..core import Command
1415
from ..errors import DistutilsOptionError
1516
from ..util import get_platform
1617

1718

18-
def show_compilers():
19-
from ..ccompiler import show_compilers
20-
21-
show_compilers()
22-
23-
2419
class build(Command):
2520
description = "build everything needed to install"
2621

Diff for: setuptools/_distutils/command/build_clib.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@
1919
from distutils._log import log
2020
from typing import ClassVar
2121

22+
from ..ccompiler import new_compiler, show_compilers
2223
from ..core import Command
2324
from ..errors import DistutilsSetupError
2425
from ..sysconfig import customize_compiler
2526

2627

27-
def show_compilers():
28-
from ..ccompiler import show_compilers
29-
30-
show_compilers()
31-
32-
3328
class build_clib(Command):
3429
description = "build C/C++ libraries used by Python extensions"
3530

@@ -93,12 +88,7 @@ def run(self) -> None:
9388
if not self.libraries:
9489
return
9590

96-
# Yech -- this is cut 'n pasted from build_ext.py!
97-
from ..ccompiler import new_compiler
98-
99-
self.compiler = new_compiler(
100-
compiler=self.compiler, dry_run=self.dry_run, force=self.force
101-
)
91+
self.compiler = new_compiler(compiler=self.compiler, force=self.force)
10292
customize_compiler(self.compiler)
10393

10494
if self.include_dirs is not None:

Diff for: setuptools/_distutils/command/build_ext.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import ClassVar
1717

1818
from .._modified import newer_group
19+
from ..ccompiler import new_compiler, show_compilers
1920
from ..core import Command
2021
from ..errors import (
2122
CCompilerError,
@@ -34,12 +35,6 @@
3435
extension_name_re = re.compile(r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
3536

3637

37-
def show_compilers():
38-
from ..ccompiler import show_compilers
39-
40-
show_compilers()
41-
42-
4338
class build_ext(Command):
4439
description = "build C/C++ extensions (compile/link to build directory)"
4540

@@ -303,8 +298,6 @@ def finalize_options(self) -> None: # noqa: C901
303298
raise DistutilsOptionError("parallel should be an integer")
304299

305300
def run(self) -> None: # noqa: C901
306-
from ..ccompiler import new_compiler
307-
308301
# 'self.extensions', as supplied by setup.py, is a list of
309302
# Extension instances. See the documentation for Extension (in
310303
# distutils.extension) for details.
@@ -333,7 +326,6 @@ def run(self) -> None: # noqa: C901
333326
self.compiler = new_compiler(
334327
compiler=self.compiler,
335328
verbose=self.verbose,
336-
dry_run=self.dry_run,
337329
force=self.force,
338330
)
339331
customize_compiler(self.compiler)

0 commit comments

Comments
 (0)