Skip to content

Commit

Permalink
Use dir_util in dist_info command for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 24, 2023
1 parent fb3aaee commit 79e5761
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions setuptools/command/dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
from distutils import log
from distutils.core import Command
from distutils import dir_util # prefer dir_util for log/cache consistency
from pathlib import Path

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

boolean_options = ['tag-date', 'keep-egg-info']
boolean_options = ['tag-date', 'keep-egg-info', 'use-cached']
negative_opt = {'no-date': 'tag-date'}

def initialize_options(self):
Expand All @@ -54,6 +56,7 @@ def initialize_options(self):
self.tag_date = None
self.tag_build = None
self.keep_egg_info = False
self.use_cached = False

def finalize_options(self):
if self.egg_base:
Expand Down Expand Up @@ -90,7 +93,10 @@ def _sync_tag_details(self, egg_info):
self.tag_build = egg_info.tag_build

def run(self):
self.output_dir.mkdir(parents=True, exist_ok=True)
if self.use_cached and (self.dist_info_dir / "METADATA").is_file():
return

self.mkpath(str(self.output_dir))
self.egg_info.run()
egg_info_dir = Path(self.egg_info.egg_info)
dist_info_dir = self.dist_info_dir
Expand All @@ -103,18 +109,17 @@ def run(self):
# METADATA, entry-points.txt
shutil.copytree(egg_info_dir, dist_info_dir, ignore=lambda _, __: _IGNORE)
metadata_file = dist_info_dir / "METADATA"
shutil.copy2(egg_info_dir / "PKG-INFO", metadata_file)
log.debug(f"creating {str(os.path.abspath(metadata_file))!r}")
self.copy_file(egg_info_dir / "PKG-INFO", metadata_file)
if self.distribution.dependency_links:
shutil.copy2(egg_info_dir / "dependency_links.txt", dist_info_dir)
self.copy_file(egg_info_dir / "dependency_links.txt", dist_info_dir)

for dest, orig in self._license_paths():
dest = dist_info_dir / dest
dest.parent.mkdir(exist_ok=True, parents=True)
shutil.copy2(orig, dest)
self.mkpath(str(dest.parent))
self.copy_file(orig, dest)

if not self.keep_egg_info:
shutil.rmtree(egg_info_dir)
dir_util.remove_tree(egg_info_dir, self.verbose, self.dry_run)

def _license_paths(self):
for file in (self.distribution.metadata.license_files or ()):
Expand Down

0 comments on commit 79e5761

Please sign in to comment.