Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/setuptools/command/sdist.py
7757 views
from distutils import log1import distutils.command.sdist as orig2import os3import sys4import io5import contextlib67from setuptools.extern import six, ordered_set89from .py36compat import sdist_add_defaults1011import pkg_resources1213_default_revctrl = list141516def walk_revctrl(dirname=''):17"""Find all files under revision control"""18for ep in pkg_resources.iter_entry_points('setuptools.file_finders'):19for item in ep.load()(dirname):20yield item212223class sdist(sdist_add_defaults, orig.sdist):24"""Smart sdist that finds anything supported by revision control"""2526user_options = [27('formats=', None,28"formats for source distribution (comma-separated list)"),29('keep-temp', 'k',30"keep the distribution tree around after creating " +31"archive file(s)"),32('dist-dir=', 'd',33"directory to put the source distribution archive(s) in "34"[default: dist]"),35]3637negative_opt = {}3839README_EXTENSIONS = ['', '.rst', '.txt', '.md']40READMES = tuple('README{0}'.format(ext) for ext in README_EXTENSIONS)4142def run(self):43self.run_command('egg_info')44ei_cmd = self.get_finalized_command('egg_info')45self.filelist = ei_cmd.filelist46self.filelist.append(os.path.join(ei_cmd.egg_info, 'SOURCES.txt'))47self.check_readme()4849# Run sub commands50for cmd_name in self.get_sub_commands():51self.run_command(cmd_name)5253self.make_distribution()5455dist_files = getattr(self.distribution, 'dist_files', [])56for file in self.archive_files:57data = ('sdist', '', file)58if data not in dist_files:59dist_files.append(data)6061def initialize_options(self):62orig.sdist.initialize_options(self)6364self._default_to_gztar()6566def _default_to_gztar(self):67# only needed on Python prior to 3.6.68if sys.version_info >= (3, 6, 0, 'beta', 1):69return70self.formats = ['gztar']7172def make_distribution(self):73"""74Workaround for #51675"""76with self._remove_os_link():77orig.sdist.make_distribution(self)7879@staticmethod80@contextlib.contextmanager81def _remove_os_link():82"""83In a context, remove and restore os.link if it exists84"""8586class NoValue:87pass8889orig_val = getattr(os, 'link', NoValue)90try:91del os.link92except Exception:93pass94try:95yield96finally:97if orig_val is not NoValue:98setattr(os, 'link', orig_val)99100def __read_template_hack(self):101# This grody hack closes the template file (MANIFEST.in) if an102# exception occurs during read_template.103# Doing so prevents an error when easy_install attempts to delete the104# file.105try:106orig.sdist.read_template(self)107except Exception:108_, _, tb = sys.exc_info()109tb.tb_next.tb_frame.f_locals['template'].close()110raise111112# Beginning with Python 2.7.2, 3.1.4, and 3.2.1, this leaky file handle113# has been fixed, so only override the method if we're using an earlier114# Python.115has_leaky_handle = (116sys.version_info < (2, 7, 2)117or (3, 0) <= sys.version_info < (3, 1, 4)118or (3, 2) <= sys.version_info < (3, 2, 1)119)120if has_leaky_handle:121read_template = __read_template_hack122123def _add_defaults_optional(self):124if six.PY2:125sdist_add_defaults._add_defaults_optional(self)126else:127super()._add_defaults_optional()128if os.path.isfile('pyproject.toml'):129self.filelist.append('pyproject.toml')130131def _add_defaults_python(self):132"""getting python files"""133if self.distribution.has_pure_modules():134build_py = self.get_finalized_command('build_py')135self.filelist.extend(build_py.get_source_files())136self._add_data_files(self._safe_data_files(build_py))137138def _safe_data_files(self, build_py):139"""140Extracting data_files from build_py is known to cause141infinite recursion errors when `include_package_data`142is enabled, so suppress it in that case.143"""144if self.distribution.include_package_data:145return ()146return build_py.data_files147148def _add_data_files(self, data_files):149"""150Add data files as found in build_py.data_files.151"""152self.filelist.extend(153os.path.join(src_dir, name)154for _, src_dir, _, filenames in data_files155for name in filenames156)157158def _add_defaults_data_files(self):159try:160if six.PY2:161sdist_add_defaults._add_defaults_data_files(self)162else:163super()._add_defaults_data_files()164except TypeError:165log.warn("data_files contains unexpected objects")166167def check_readme(self):168for f in self.READMES:169if os.path.exists(f):170return171else:172self.warn(173"standard file not found: should have one of " +174', '.join(self.READMES)175)176177def make_release_tree(self, base_dir, files):178orig.sdist.make_release_tree(self, base_dir, files)179180# Save any egg_info command line options used to create this sdist181dest = os.path.join(base_dir, 'setup.cfg')182if hasattr(os, 'link') and os.path.exists(dest):183# unlink and re-copy, since it might be hard-linked, and184# we don't want to change the source version185os.unlink(dest)186self.copy_file('setup.cfg', dest)187188self.get_finalized_command('egg_info').save_version_info(dest)189190def _manifest_is_not_generated(self):191# check for special comment used in 2.7.1 and higher192if not os.path.isfile(self.manifest):193return False194195with io.open(self.manifest, 'rb') as fp:196first_line = fp.readline()197return (first_line !=198'# file GENERATED by distutils, do NOT edit\n'.encode())199200def read_manifest(self):201"""Read the manifest file (named by 'self.manifest') and use it to202fill in 'self.filelist', the list of files to include in the source203distribution.204"""205log.info("reading manifest file '%s'", self.manifest)206manifest = open(self.manifest, 'rb')207for line in manifest:208# The manifest must contain UTF-8. See #303.209if not six.PY2:210try:211line = line.decode('UTF-8')212except UnicodeDecodeError:213log.warn("%r not UTF-8 decodable -- skipping" % line)214continue215# ignore comments and blank lines216line = line.strip()217if line.startswith('#') or not line:218continue219self.filelist.append(line)220manifest.close()221222def check_license(self):223"""Checks if license_file' or 'license_files' is configured and adds any224valid paths to 'self.filelist'.225"""226227files = ordered_set.OrderedSet()228229opts = self.distribution.get_option_dict('metadata')230231# ignore the source of the value232_, license_file = opts.get('license_file', (None, None))233234if license_file is None:235log.debug("'license_file' option was not specified")236else:237files.add(license_file)238239try:240files.update(self.distribution.metadata.license_files)241except TypeError:242log.warn("warning: 'license_files' option is malformed")243244for f in files:245if not os.path.exists(f):246log.warn(247"warning: Failed to find the configured license file '%s'",248f)249files.remove(f)250251self.filelist.extend(files)252253254