Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/setuptools/extern/__init__.py
811 views
1
import sys
2
3
4
class VendorImporter:
5
"""
6
A PEP 302 meta path importer for finding optionally-vendored
7
or otherwise naturally-installed packages from root_name.
8
"""
9
10
def __init__(self, root_name, vendored_names=(), vendor_pkg=None):
11
self.root_name = root_name
12
self.vendored_names = set(vendored_names)
13
self.vendor_pkg = vendor_pkg or root_name.replace('extern', '_vendor')
14
15
@property
16
def search_path(self):
17
"""
18
Search first the vendor package then as a natural package.
19
"""
20
yield self.vendor_pkg + '.'
21
yield ''
22
23
def find_module(self, fullname, path=None):
24
"""
25
Return self when fullname starts with root_name and the
26
target module is one vendored through this importer.
27
"""
28
root, base, target = fullname.partition(self.root_name + '.')
29
if root:
30
return
31
if not any(map(target.startswith, self.vendored_names)):
32
return
33
return self
34
35
def load_module(self, fullname):
36
"""
37
Iterate over the search path to locate and load fullname.
38
"""
39
root, base, target = fullname.partition(self.root_name + '.')
40
for prefix in self.search_path:
41
try:
42
extant = prefix + target
43
__import__(extant)
44
mod = sys.modules[extant]
45
sys.modules[fullname] = mod
46
return mod
47
except ImportError:
48
pass
49
else:
50
raise ImportError(
51
"The '{target}' package is required; "
52
"normally this is bundled with this package so if you get "
53
"this warning, consult the packager of your "
54
"distribution.".format(**locals())
55
)
56
57
def install(self):
58
"""
59
Install this importer into sys.meta_path if not already present.
60
"""
61
if self not in sys.meta_path:
62
sys.meta_path.append(self)
63
64
65
names = 'six', 'packaging', 'pyparsing', 'ordered_set',
66
VendorImporter(__name__, names, 'setuptools._vendor').install()
67
68