Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/setuptools/__init__.py
811 views
1
"""Extensions to the 'distutils' for large or complex distributions"""
2
3
import os
4
import functools
5
6
# Disabled for now due to: #2228, #2230
7
# import setuptools.distutils_patch # noqa: F401
8
9
import distutils.core
10
import distutils.filelist
11
import re
12
from distutils.errors import DistutilsOptionError
13
from distutils.util import convert_path
14
from fnmatch import fnmatchcase
15
16
from ._deprecation_warning import SetuptoolsDeprecationWarning
17
18
from setuptools.extern.six import PY3, string_types
19
from setuptools.extern.six.moves import filter, map
20
21
import setuptools.version
22
from setuptools.extension import Extension
23
from setuptools.dist import Distribution
24
from setuptools.depends import Require
25
from . import monkey
26
27
__metaclass__ = type
28
29
30
__all__ = [
31
'setup', 'Distribution', 'Command', 'Extension', 'Require',
32
'SetuptoolsDeprecationWarning',
33
'find_packages'
34
]
35
36
if PY3:
37
__all__.append('find_namespace_packages')
38
39
__version__ = setuptools.version.__version__
40
41
bootstrap_install_from = None
42
43
# If we run 2to3 on .py files, should we also convert docstrings?
44
# Default: yes; assume that we can detect doctests reliably
45
run_2to3_on_doctests = True
46
# Standard package names for fixer packages
47
lib2to3_fixer_packages = ['lib2to3.fixes']
48
49
50
class PackageFinder:
51
"""
52
Generate a list of all Python packages found within a directory
53
"""
54
55
@classmethod
56
def find(cls, where='.', exclude=(), include=('*',)):
57
"""Return a list all Python packages found within directory 'where'
58
59
'where' is the root directory which will be searched for packages. It
60
should be supplied as a "cross-platform" (i.e. URL-style) path; it will
61
be converted to the appropriate local path syntax.
62
63
'exclude' is a sequence of package names to exclude; '*' can be used
64
as a wildcard in the names, such that 'foo.*' will exclude all
65
subpackages of 'foo' (but not 'foo' itself).
66
67
'include' is a sequence of package names to include. If it's
68
specified, only the named packages will be included. If it's not
69
specified, all found packages will be included. 'include' can contain
70
shell style wildcard patterns just like 'exclude'.
71
"""
72
73
return list(cls._find_packages_iter(
74
convert_path(where),
75
cls._build_filter('ez_setup', '*__pycache__', *exclude),
76
cls._build_filter(*include)))
77
78
@classmethod
79
def _find_packages_iter(cls, where, exclude, include):
80
"""
81
All the packages found in 'where' that pass the 'include' filter, but
82
not the 'exclude' filter.
83
"""
84
for root, dirs, files in os.walk(where, followlinks=True):
85
# Copy dirs to iterate over it, then empty dirs.
86
all_dirs = dirs[:]
87
dirs[:] = []
88
89
for dir in all_dirs:
90
full_path = os.path.join(root, dir)
91
rel_path = os.path.relpath(full_path, where)
92
package = rel_path.replace(os.path.sep, '.')
93
94
# Skip directory trees that are not valid packages
95
if ('.' in dir or not cls._looks_like_package(full_path)):
96
continue
97
98
# Should this package be included?
99
if include(package) and not exclude(package):
100
yield package
101
102
# Keep searching subdirectories, as there may be more packages
103
# down there, even if the parent was excluded.
104
dirs.append(dir)
105
106
@staticmethod
107
def _looks_like_package(path):
108
"""Does a directory look like a package?"""
109
return os.path.isfile(os.path.join(path, '__init__.py'))
110
111
@staticmethod
112
def _build_filter(*patterns):
113
"""
114
Given a list of patterns, return a callable that will be true only if
115
the input matches at least one of the patterns.
116
"""
117
return lambda name: any(fnmatchcase(name, pat=pat) for pat in patterns)
118
119
120
class PEP420PackageFinder(PackageFinder):
121
@staticmethod
122
def _looks_like_package(path):
123
return True
124
125
126
find_packages = PackageFinder.find
127
128
if PY3:
129
find_namespace_packages = PEP420PackageFinder.find
130
131
132
def _install_setup_requires(attrs):
133
# Note: do not use `setuptools.Distribution` directly, as
134
# our PEP 517 backend patch `distutils.core.Distribution`.
135
class MinimalDistribution(distutils.core.Distribution):
136
"""
137
A minimal version of a distribution for supporting the
138
fetch_build_eggs interface.
139
"""
140
def __init__(self, attrs):
141
_incl = 'dependency_links', 'setup_requires'
142
filtered = {
143
k: attrs[k]
144
for k in set(_incl) & set(attrs)
145
}
146
distutils.core.Distribution.__init__(self, filtered)
147
148
def finalize_options(self):
149
"""
150
Disable finalize_options to avoid building the working set.
151
Ref #2158.
152
"""
153
154
dist = MinimalDistribution(attrs)
155
156
# Honor setup.cfg's options.
157
dist.parse_config_files(ignore_option_errors=True)
158
if dist.setup_requires:
159
dist.fetch_build_eggs(dist.setup_requires)
160
161
162
def setup(**attrs):
163
# Make sure we have any requirements needed to interpret 'attrs'.
164
_install_setup_requires(attrs)
165
return distutils.core.setup(**attrs)
166
167
168
setup.__doc__ = distutils.core.setup.__doc__
169
170
171
_Command = monkey.get_unpatched(distutils.core.Command)
172
173
174
class Command(_Command):
175
__doc__ = _Command.__doc__
176
177
command_consumes_arguments = False
178
179
def __init__(self, dist, **kw):
180
"""
181
Construct the command for dist, updating
182
vars(self) with any keyword parameters.
183
"""
184
_Command.__init__(self, dist)
185
vars(self).update(kw)
186
187
def _ensure_stringlike(self, option, what, default=None):
188
val = getattr(self, option)
189
if val is None:
190
setattr(self, option, default)
191
return default
192
elif not isinstance(val, string_types):
193
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
194
% (option, what, val))
195
return val
196
197
def ensure_string_list(self, option):
198
r"""Ensure that 'option' is a list of strings. If 'option' is
199
currently a string, we split it either on /,\s*/ or /\s+/, so
200
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
201
["foo", "bar", "baz"].
202
"""
203
val = getattr(self, option)
204
if val is None:
205
return
206
elif isinstance(val, string_types):
207
setattr(self, option, re.split(r',\s*|\s+', val))
208
else:
209
if isinstance(val, list):
210
ok = all(isinstance(v, string_types) for v in val)
211
else:
212
ok = False
213
if not ok:
214
raise DistutilsOptionError(
215
"'%s' must be a list of strings (got %r)"
216
% (option, val))
217
218
def reinitialize_command(self, command, reinit_subcommands=0, **kw):
219
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
220
vars(cmd).update(kw)
221
return cmd
222
223
224
def _find_all_simple(path):
225
"""
226
Find all files under 'path'
227
"""
228
results = (
229
os.path.join(base, file)
230
for base, dirs, files in os.walk(path, followlinks=True)
231
for file in files
232
)
233
return filter(os.path.isfile, results)
234
235
236
def findall(dir=os.curdir):
237
"""
238
Find all files under 'dir' and return the list of full filenames.
239
Unless dir is '.', return full filenames with dir prepended.
240
"""
241
files = _find_all_simple(dir)
242
if dir == os.curdir:
243
make_rel = functools.partial(os.path.relpath, start=dir)
244
files = map(make_rel, files)
245
return list(files)
246
247
248
class sic(str):
249
"""Treat this string as-is (https://en.wikipedia.org/wiki/Sic)"""
250
251
252
# Apply monkey patches
253
monkey.patch_all()
254
255