Skip to content

Commit 79e5761

Browse files
committed
Use dir_util in dist_info command for consistency
1 parent fb3aaee commit 79e5761

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

setuptools/command/dist_info.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
from distutils import log
99
from distutils.core import Command
10+
from distutils import dir_util # prefer dir_util for log/cache consistency
1011
from pathlib import Path
1112

1213
from .. import _normalization
@@ -41,9 +42,10 @@ class dist_info(Command):
4142
('tag-build=', 'b', "Specify explicit tag to add to version number"),
4243
('no-date', 'D', "Don't include date stamp [default]"),
4344
('keep-egg-info', None, "*TRANSITIONAL* will be removed in the future"),
45+
('use-cached', None, "*TRANSITIONAL* will be removed in the future"),
4446
]
4547

46-
boolean_options = ['tag-date', 'keep-egg-info']
48+
boolean_options = ['tag-date', 'keep-egg-info', 'use-cached']
4749
negative_opt = {'no-date': 'tag-date'}
4850

4951
def initialize_options(self):
@@ -54,6 +56,7 @@ def initialize_options(self):
5456
self.tag_date = None
5557
self.tag_build = None
5658
self.keep_egg_info = False
59+
self.use_cached = False
5760

5861
def finalize_options(self):
5962
if self.egg_base:
@@ -90,7 +93,10 @@ def _sync_tag_details(self, egg_info):
9093
self.tag_build = egg_info.tag_build
9194

9295
def run(self):
93-
self.output_dir.mkdir(parents=True, exist_ok=True)
96+
if self.use_cached and (self.dist_info_dir / "METADATA").is_file():
97+
return
98+
99+
self.mkpath(str(self.output_dir))
94100
self.egg_info.run()
95101
egg_info_dir = Path(self.egg_info.egg_info)
96102
dist_info_dir = self.dist_info_dir
@@ -103,18 +109,17 @@ def run(self):
103109
# METADATA, entry-points.txt
104110
shutil.copytree(egg_info_dir, dist_info_dir, ignore=lambda _, __: _IGNORE)
105111
metadata_file = dist_info_dir / "METADATA"
106-
shutil.copy2(egg_info_dir / "PKG-INFO", metadata_file)
107-
log.debug(f"creating {str(os.path.abspath(metadata_file))!r}")
112+
self.copy_file(egg_info_dir / "PKG-INFO", metadata_file)
108113
if self.distribution.dependency_links:
109-
shutil.copy2(egg_info_dir / "dependency_links.txt", dist_info_dir)
114+
self.copy_file(egg_info_dir / "dependency_links.txt", dist_info_dir)
110115

111116
for dest, orig in self._license_paths():
112117
dest = dist_info_dir / dest
113-
dest.parent.mkdir(exist_ok=True, parents=True)
114-
shutil.copy2(orig, dest)
118+
self.mkpath(str(dest.parent))
119+
self.copy_file(orig, dest)
115120

116121
if not self.keep_egg_info:
117-
shutil.rmtree(egg_info_dir)
122+
dir_util.remove_tree(egg_info_dir, self.verbose, self.dry_run)
118123

119124
def _license_paths(self):
120125
for file in (self.distribution.metadata.license_files or ()):

0 commit comments

Comments
 (0)