summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-03-09 16:09:48 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-05-03 14:10:21 +0100
commit957ff14547f24394264483cc100e728f3173959f (patch)
tree66e556d366179ae638ae520ef97d6ae023adffd5
parentae8ec5c3f4cfc7f14783b4dd58c436a7ba168138 (diff)
downloadpython-setuptools-git-957ff14547f24394264483cc100e728f3173959f.tar.gz
Avoid using pypa/wheel unstable API in dist_info
-rw-r--r--setuptools/command/dist_info.py88
1 files changed, 44 insertions, 44 deletions
diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py
index 99d3976d..f603a44a 100644
--- a/setuptools/command/dist_info.py
+++ b/setuptools/command/dist_info.py
@@ -5,8 +5,6 @@ As defined in the wheel specification
import os
import shutil
-import sys
-from contextlib import contextmanager
from distutils import log
from distutils.core import Command
from pathlib import Path
@@ -15,6 +13,16 @@ from .. import _normalization
from ..warnings import SetuptoolsDeprecationWarning
+_IGNORE = {
+ "PKG-INFO",
+ "requires.txt",
+ "SOURCES.txt",
+ "not-zip-safe",
+ "dependency_links.txt",
+}
+# Files to be ignored when copying the egg-info into dist-info
+
+
class dist_info(Command):
"""
This command is private and reserved for internal use of setuptools,
@@ -61,7 +69,16 @@ class dist_info(Command):
egg_info = self.reinitialize_command("egg_info")
egg_info.egg_base = str(self.output_dir)
+ self._sync_tag_details(egg_info)
+ egg_info.finalize_options()
+ self.egg_info = egg_info
+ name = _normalization.safer_name(dist.get_name())
+ version = _normalization.safer_best_effort_version(dist.get_version())
+ self.name = f"{name}-{version}"
+ self.dist_info_dir = Path(self.output_dir, f"{self.name}.dist-info")
+
+ def _sync_tag_details(self, egg_info):
if self.tag_date:
egg_info.tag_date = self.tag_date
else:
@@ -72,48 +89,31 @@ class dist_info(Command):
else:
self.tag_build = egg_info.tag_build
- egg_info.finalize_options()
- self.egg_info = egg_info
-
- name = _normalization.safer_name(dist.get_name())
- version = _normalization.safer_best_effort_version(dist.get_version())
- self.name = f"{name}-{version}"
- self.dist_info_dir = os.path.join(self.output_dir, f"{self.name}.dist-info")
-
- @contextmanager
- def _maybe_bkp_dir(self, dir_path: str, requires_bkp: bool):
- if requires_bkp:
- bkp_name = f"{dir_path}.__bkp__"
- _rm(bkp_name, ignore_errors=True)
- _copy(dir_path, bkp_name, dirs_exist_ok=True, symlinks=True)
- try:
- yield
- finally:
- _rm(dir_path, ignore_errors=True)
- shutil.move(bkp_name, dir_path)
- else:
- yield
-
def run(self):
self.output_dir.mkdir(parents=True, exist_ok=True)
self.egg_info.run()
- egg_info_dir = self.egg_info.egg_info
- assert os.path.isdir(egg_info_dir), ".egg-info dir should have been created"
-
- log.info("creating '{}'".format(os.path.abspath(self.dist_info_dir)))
- bdist_wheel = self.get_finalized_command('bdist_wheel')
-
- # TODO: if bdist_wheel if merged into setuptools, just add "keep_egg_info" there
- with self._maybe_bkp_dir(egg_info_dir, self.keep_egg_info):
- bdist_wheel.egg2dist(egg_info_dir, self.dist_info_dir)
-
-
-def _rm(dir_name, **opts):
- if os.path.isdir(dir_name):
- shutil.rmtree(dir_name, **opts)
-
-
-def _copy(src, dst, **opts):
- if sys.version_info < (3, 8):
- opts.pop("dirs_exist_ok", None)
- shutil.copytree(src, dst, **opts)
+ egg_info_dir = Path(self.egg_info.egg_info)
+ dist_info_dir = self.dist_info_dir
+
+ assert egg_info_dir.is_dir(), ".egg-info dir should have been created"
+ log.info(f"creating {str(os.path.abspath(dist_info_dir))!r}")
+
+ # The egg-info dir should now be basically equivalent to the dist-info dir
+ # If in the future we don't want to use egg_info, we have to create the files:
+ # METADATA, entry-points.txt
+ shutil.copytree(egg_info_dir, dist_info_dir, ignore=lambda _, __: _IGNORE)
+ shutil.copy2(egg_info_dir / "PKG-INFO", dist_info_dir / "METADATA")
+ if self.distribution.dependency_links:
+ shutil.copy2(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)
+
+ if not self.keep_egg_info:
+ shutil.rmtree(egg_info_dir)
+
+ def _license_paths(self):
+ for file in (self.distribution.metadata.license_files or ()):
+ yield os.path.basename(file), file