Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keewenaw
GitHub Repository: keewenaw/ethereum-wallet-cracker
Path: blob/main/test/lib/python3.9/site-packages/setuptools/__init__.py
4798 views
1
"""Extensions to the 'distutils' for large or complex distributions"""
2
3
import functools
4
import os
5
import re
6
import warnings
7
8
import _distutils_hack.override # noqa: F401
9
10
import distutils.core
11
from distutils.errors import DistutilsOptionError
12
from distutils.util import convert_path as _convert_path
13
14
from ._deprecation_warning import SetuptoolsDeprecationWarning
15
16
import setuptools.version
17
from setuptools.extension import Extension
18
from setuptools.dist import Distribution
19
from setuptools.depends import Require
20
from setuptools.discovery import PackageFinder, PEP420PackageFinder
21
from . import monkey
22
from . import logging
23
24
25
__all__ = [
26
'setup',
27
'Distribution',
28
'Command',
29
'Extension',
30
'Require',
31
'SetuptoolsDeprecationWarning',
32
'find_packages',
33
'find_namespace_packages',
34
]
35
36
__version__ = setuptools.version.__version__
37
38
bootstrap_install_from = None
39
40
41
find_packages = PackageFinder.find
42
find_namespace_packages = PEP420PackageFinder.find
43
44
45
def _install_setup_requires(attrs):
46
# Note: do not use `setuptools.Distribution` directly, as
47
# our PEP 517 backend patch `distutils.core.Distribution`.
48
class MinimalDistribution(distutils.core.Distribution):
49
"""
50
A minimal version of a distribution for supporting the
51
fetch_build_eggs interface.
52
"""
53
54
def __init__(self, attrs):
55
_incl = 'dependency_links', 'setup_requires'
56
filtered = {k: attrs[k] for k in set(_incl) & set(attrs)}
57
super().__init__(filtered)
58
# Prevent accidentally triggering discovery with incomplete set of attrs
59
self.set_defaults._disable()
60
61
def _get_project_config_files(self, filenames=None):
62
"""Ignore ``pyproject.toml``, they are not related to setup_requires"""
63
try:
64
cfg, toml = super()._split_standard_project_metadata(filenames)
65
return cfg, ()
66
except Exception:
67
return filenames, ()
68
69
def finalize_options(self):
70
"""
71
Disable finalize_options to avoid building the working set.
72
Ref #2158.
73
"""
74
75
dist = MinimalDistribution(attrs)
76
77
# Honor setup.cfg's options.
78
dist.parse_config_files(ignore_option_errors=True)
79
if dist.setup_requires:
80
dist.fetch_build_eggs(dist.setup_requires)
81
82
83
def setup(**attrs):
84
# Make sure we have any requirements needed to interpret 'attrs'.
85
logging.configure()
86
_install_setup_requires(attrs)
87
return distutils.core.setup(**attrs)
88
89
90
setup.__doc__ = distutils.core.setup.__doc__
91
92
93
_Command = monkey.get_unpatched(distutils.core.Command)
94
95
96
class Command(_Command):
97
__doc__ = _Command.__doc__
98
99
command_consumes_arguments = False
100
101
def __init__(self, dist, **kw):
102
"""
103
Construct the command for dist, updating
104
vars(self) with any keyword parameters.
105
"""
106
super().__init__(dist)
107
vars(self).update(kw)
108
109
def _ensure_stringlike(self, option, what, default=None):
110
val = getattr(self, option)
111
if val is None:
112
setattr(self, option, default)
113
return default
114
elif not isinstance(val, str):
115
raise DistutilsOptionError(
116
"'%s' must be a %s (got `%s`)" % (option, what, val)
117
)
118
return val
119
120
def ensure_string_list(self, option):
121
r"""Ensure that 'option' is a list of strings. If 'option' is
122
currently a string, we split it either on /,\s*/ or /\s+/, so
123
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
124
["foo", "bar", "baz"].
125
"""
126
val = getattr(self, option)
127
if val is None:
128
return
129
elif isinstance(val, str):
130
setattr(self, option, re.split(r',\s*|\s+', val))
131
else:
132
if isinstance(val, list):
133
ok = all(isinstance(v, str) for v in val)
134
else:
135
ok = False
136
if not ok:
137
raise DistutilsOptionError(
138
"'%s' must be a list of strings (got %r)" % (option, val)
139
)
140
141
def reinitialize_command(self, command, reinit_subcommands=0, **kw):
142
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
143
vars(cmd).update(kw)
144
return cmd
145
146
147
def _find_all_simple(path):
148
"""
149
Find all files under 'path'
150
"""
151
results = (
152
os.path.join(base, file)
153
for base, dirs, files in os.walk(path, followlinks=True)
154
for file in files
155
)
156
return filter(os.path.isfile, results)
157
158
159
def findall(dir=os.curdir):
160
"""
161
Find all files under 'dir' and return the list of full filenames.
162
Unless dir is '.', return full filenames with dir prepended.
163
"""
164
files = _find_all_simple(dir)
165
if dir == os.curdir:
166
make_rel = functools.partial(os.path.relpath, start=dir)
167
files = map(make_rel, files)
168
return list(files)
169
170
171
@functools.wraps(_convert_path)
172
def convert_path(pathname):
173
from inspect import cleandoc
174
175
msg = """
176
The function `convert_path` is considered internal and not part of the public API.
177
Its direct usage by 3rd-party packages is considered deprecated and the function
178
may be removed in the future.
179
"""
180
warnings.warn(cleandoc(msg), SetuptoolsDeprecationWarning)
181
return _convert_path(pathname)
182
183
184
class sic(str):
185
"""Treat this string as-is (https://en.wikipedia.org/wiki/Sic)"""
186
187
188
# Apply monkey patches
189
monkey.patch_all()
190
191