Skip to content

Commit c03fd73

Browse files
committed
Use dir_util in dist_info command for consistency
1 parent ebc980f commit c03fd73

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
@@ -49,9 +50,10 @@ class dist_info(Command):
4950
('tag-build=', 'b', "Specify explicit tag to add to version number"),
5051
('no-date', 'D', "Don't include date stamp [default]"),
5152
('keep-egg-info', None, "*TRANSITIONAL* will be removed in the future"),
53+
('use-cached', None, "*TRANSITIONAL* will be removed in the future"),
5254
]
5355

54-
boolean_options = ['tag-date', 'keep-egg-info']
56+
boolean_options = ['tag-date', 'keep-egg-info', 'use-cached']
5557
negative_opt = {'no-date': 'tag-date'}
5658

5759
def initialize_options(self):
@@ -62,6 +64,7 @@ def initialize_options(self):
6264
self.tag_date = None
6365
self.tag_build = None
6466
self.keep_egg_info = False
67+
self.use_cached = False
6568

6669
def finalize_options(self):
6770
if self.egg_base:
@@ -98,7 +101,10 @@ def _sync_tag_details(self, egg_info):
98101
self.tag_build = egg_info.tag_build
99102

100103
def run(self):
101-
self.output_dir.mkdir(parents=True, exist_ok=True)
104+
if self.use_cached and (self.dist_info_dir / "METADATA").is_file():
105+
return
106+
107+
self.mkpath(str(self.output_dir))
102108
self.egg_info.run()
103109
egg_info_dir = Path(self.egg_info.egg_info)
104110
dist_info_dir = self.dist_info_dir
@@ -111,18 +117,17 @@ def run(self):
111117
# METADATA, entry-points.txt
112118
shutil.copytree(egg_info_dir, dist_info_dir, ignore=lambda _, __: _IGNORE)
113119
metadata_file = dist_info_dir / "METADATA"
114-
shutil.copy2(egg_info_dir / "PKG-INFO", metadata_file)
115-
log.debug(f"creating {str(os.path.abspath(metadata_file))!r}")
120+
self.copy_file(egg_info_dir / "PKG-INFO", metadata_file)
116121
if self.distribution.dependency_links:
117-
shutil.copy2(egg_info_dir / "dependency_links.txt", dist_info_dir)
122+
self.copy_file(egg_info_dir / "dependency_links.txt", dist_info_dir)
118123

119124
for dest, orig in self._license_paths():
120125
dest = dist_info_dir / dest
121-
dest.parent.mkdir(exist_ok=True, parents=True)
122-
shutil.copy2(orig, dest)
126+
self.mkpath(str(dest.parent))
127+
self.copy_file(orig, dest)
123128

124129
if not self.keep_egg_info:
125-
shutil.rmtree(egg_info_dir)
130+
dir_util.remove_tree(egg_info_dir, self.verbose, self.dry_run)
126131

127132
def _license_paths(self):
128133
for file in self.distribution.metadata.license_files or ():

0 commit comments

Comments
 (0)