Path: blob/main/test/lib/python3.9/site-packages/setuptools/__init__.py
4798 views
"""Extensions to the 'distutils' for large or complex distributions"""12import functools3import os4import re5import warnings67import _distutils_hack.override # noqa: F40189import distutils.core10from distutils.errors import DistutilsOptionError11from distutils.util import convert_path as _convert_path1213from ._deprecation_warning import SetuptoolsDeprecationWarning1415import setuptools.version16from setuptools.extension import Extension17from setuptools.dist import Distribution18from setuptools.depends import Require19from setuptools.discovery import PackageFinder, PEP420PackageFinder20from . import monkey21from . import logging222324__all__ = [25'setup',26'Distribution',27'Command',28'Extension',29'Require',30'SetuptoolsDeprecationWarning',31'find_packages',32'find_namespace_packages',33]3435__version__ = setuptools.version.__version__3637bootstrap_install_from = None383940find_packages = PackageFinder.find41find_namespace_packages = PEP420PackageFinder.find424344def _install_setup_requires(attrs):45# Note: do not use `setuptools.Distribution` directly, as46# our PEP 517 backend patch `distutils.core.Distribution`.47class MinimalDistribution(distutils.core.Distribution):48"""49A minimal version of a distribution for supporting the50fetch_build_eggs interface.51"""5253def __init__(self, attrs):54_incl = 'dependency_links', 'setup_requires'55filtered = {k: attrs[k] for k in set(_incl) & set(attrs)}56super().__init__(filtered)57# Prevent accidentally triggering discovery with incomplete set of attrs58self.set_defaults._disable()5960def _get_project_config_files(self, filenames=None):61"""Ignore ``pyproject.toml``, they are not related to setup_requires"""62try:63cfg, toml = super()._split_standard_project_metadata(filenames)64return cfg, ()65except Exception:66return filenames, ()6768def finalize_options(self):69"""70Disable finalize_options to avoid building the working set.71Ref #2158.72"""7374dist = MinimalDistribution(attrs)7576# Honor setup.cfg's options.77dist.parse_config_files(ignore_option_errors=True)78if dist.setup_requires:79dist.fetch_build_eggs(dist.setup_requires)808182def setup(**attrs):83# Make sure we have any requirements needed to interpret 'attrs'.84logging.configure()85_install_setup_requires(attrs)86return distutils.core.setup(**attrs)878889setup.__doc__ = distutils.core.setup.__doc__909192_Command = monkey.get_unpatched(distutils.core.Command)939495class Command(_Command):96__doc__ = _Command.__doc__9798command_consumes_arguments = False99100def __init__(self, dist, **kw):101"""102Construct the command for dist, updating103vars(self) with any keyword parameters.104"""105super().__init__(dist)106vars(self).update(kw)107108def _ensure_stringlike(self, option, what, default=None):109val = getattr(self, option)110if val is None:111setattr(self, option, default)112return default113elif not isinstance(val, str):114raise DistutilsOptionError(115"'%s' must be a %s (got `%s`)" % (option, what, val)116)117return val118119def ensure_string_list(self, option):120r"""Ensure that 'option' is a list of strings. If 'option' is121currently a string, we split it either on /,\s*/ or /\s+/, so122"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become123["foo", "bar", "baz"].124"""125val = getattr(self, option)126if val is None:127return128elif isinstance(val, str):129setattr(self, option, re.split(r',\s*|\s+', val))130else:131if isinstance(val, list):132ok = all(isinstance(v, str) for v in val)133else:134ok = False135if not ok:136raise DistutilsOptionError(137"'%s' must be a list of strings (got %r)" % (option, val)138)139140def reinitialize_command(self, command, reinit_subcommands=0, **kw):141cmd = _Command.reinitialize_command(self, command, reinit_subcommands)142vars(cmd).update(kw)143return cmd144145146def _find_all_simple(path):147"""148Find all files under 'path'149"""150results = (151os.path.join(base, file)152for base, dirs, files in os.walk(path, followlinks=True)153for file in files154)155return filter(os.path.isfile, results)156157158def findall(dir=os.curdir):159"""160Find all files under 'dir' and return the list of full filenames.161Unless dir is '.', return full filenames with dir prepended.162"""163files = _find_all_simple(dir)164if dir == os.curdir:165make_rel = functools.partial(os.path.relpath, start=dir)166files = map(make_rel, files)167return list(files)168169170@functools.wraps(_convert_path)171def convert_path(pathname):172from inspect import cleandoc173174msg = """175The function `convert_path` is considered internal and not part of the public API.176Its direct usage by 3rd-party packages is considered deprecated and the function177may be removed in the future.178"""179warnings.warn(cleandoc(msg), SetuptoolsDeprecationWarning)180return _convert_path(pathname)181182183class sic(str):184"""Treat this string as-is (https://en.wikipedia.org/wiki/Sic)"""185186187# Apply monkey patches188monkey.patch_all()189190191