This commit is contained in:
lz_db
2026-10-16 22:48:30 +08:00
parent 190de72571
commit 0b36fd3383
3161 changed files with 12787 additions and 77274 deletions
@@ -1,61 +1,50 @@
from __future__ import annotations
import contextlib
from distutils import log
import distutils.command.sdist as orig
import os
import re
import sys
import io
import contextlib
from itertools import chain
from typing import ClassVar
from .py36compat import sdist_add_defaults
from .._importlib import metadata
from ..dist import Distribution
from .build import _ORIGINAL_SUBCOMMANDS
import distutils.command.sdist as orig
from distutils import log
_default_revctrl = list
def walk_revctrl(dirname=''):
"""Find all files under revision control"""
for ep in metadata.entry_points(group='setuptools.file_finders'):
yield from ep.load()(dirname)
for item in ep.load()(dirname):
yield item
class sdist(orig.sdist):
class sdist(sdist_add_defaults, orig.sdist):
"""Smart sdist that finds anything supported by revision control"""
user_options = [
('formats=', None, "formats for source distribution (comma-separated list)"),
(
'keep-temp',
'k',
"keep the distribution tree around after creating " + "archive file(s)",
),
(
'dist-dir=',
'd',
"directory to put the source distribution archive(s) in [default: dist]",
),
(
'owner=',
'u',
"Owner name used when creating a tar file [default: current user]",
),
(
'group=',
'g',
"Group name used when creating a tar file [default: current group]",
),
('formats=', None,
"formats for source distribution (comma-separated list)"),
('keep-temp', 'k',
"keep the distribution tree around after creating " +
"archive file(s)"),
('dist-dir=', 'd',
"directory to put the source distribution archive(s) in "
"[default: dist]"),
('owner=', 'u',
"Owner name used when creating a tar file [default: current user]"),
('group=', 'g',
"Group name used when creating a tar file [default: current group]"),
]
distribution: Distribution # override distutils.dist.Distribution with setuptools.dist.Distribution
negative_opt: ClassVar[dict[str, str]] = {}
negative_opt = {}
README_EXTENSIONS = ['', '.rst', '.txt', '.md']
READMES = tuple(f'README{ext}' for ext in README_EXTENSIONS)
READMES = tuple('README{0}'.format(ext) for ext in README_EXTENSIONS)
def run(self) -> None:
def run(self):
self.run_command('egg_info')
ei_cmd = self.get_finalized_command('egg_info')
self.filelist = ei_cmd.filelist
@@ -74,10 +63,18 @@ class sdist(orig.sdist):
if data not in dist_files:
dist_files.append(data)
def initialize_options(self) -> None:
def initialize_options(self):
orig.sdist.initialize_options(self)
def make_distribution(self) -> None:
self._default_to_gztar()
def _default_to_gztar(self):
# only needed on Python prior to 3.6.
if sys.version_info >= (3, 6, 0, 'beta', 1):
return
self.formats = ['gztar']
def make_distribution(self):
"""
Workaround for #516
"""
@@ -103,9 +100,9 @@ class sdist(orig.sdist):
yield
finally:
if orig_val is not NoValue:
os.link = orig_val
setattr(os, 'link', orig_val)
def add_defaults(self) -> None:
def add_defaults(self):
super().add_defaults()
self._add_defaults_build_sub_commands()
@@ -158,22 +155,17 @@ class sdist(orig.sdist):
except TypeError:
log.warn("data_files contains unexpected objects")
def prune_file_list(self) -> None:
super().prune_file_list()
# Prevent accidental inclusion of test-related cache dirs at the project root
sep = re.escape(os.sep)
self.filelist.exclude_pattern(r"^(\.tox|\.nox|\.venv)" + sep, is_regex=True)
def check_readme(self) -> None:
def check_readme(self):
for f in self.READMES:
if os.path.exists(f):
return
else:
self.warn(
"standard file not found: should have one of " + ', '.join(self.READMES)
"standard file not found: should have one of " +
', '.join(self.READMES)
)
def make_release_tree(self, base_dir, files) -> None:
def make_release_tree(self, base_dir, files):
orig.sdist.make_release_tree(self, base_dir, files)
# Save any egg_info command line options used to create this sdist
@@ -191,9 +183,10 @@ class sdist(orig.sdist):
if not os.path.isfile(self.manifest):
return False
with open(self.manifest, 'rb') as fp:
with io.open(self.manifest, 'rb') as fp:
first_line = fp.readline()
return first_line != b'# file GENERATED by distutils, do NOT edit\n'
return (first_line !=
'# file GENERATED by distutils, do NOT edit\n'.encode())
def read_manifest(self):
"""Read the manifest file (named by 'self.manifest') and use it to
@@ -202,12 +195,12 @@ class sdist(orig.sdist):
"""
log.info("reading manifest file '%s'", self.manifest)
manifest = open(self.manifest, 'rb')
for bytes_line in manifest:
for line in manifest:
# The manifest must contain UTF-8. See #303.
try:
line = bytes_line.decode('UTF-8')
line = line.decode('UTF-8')
except UnicodeDecodeError:
log.warn(f"{line!r} not UTF-8 decodable -- skipping")
log.warn("%r not UTF-8 decodable -- skipping" % line)
continue
# ignore comments and blank lines
line = line.strip()