Path: blob/master/venv/Lib/site-packages/setuptools/extern/__init__.py
811 views
import sys123class VendorImporter:4"""5A PEP 302 meta path importer for finding optionally-vendored6or otherwise naturally-installed packages from root_name.7"""89def __init__(self, root_name, vendored_names=(), vendor_pkg=None):10self.root_name = root_name11self.vendored_names = set(vendored_names)12self.vendor_pkg = vendor_pkg or root_name.replace('extern', '_vendor')1314@property15def search_path(self):16"""17Search first the vendor package then as a natural package.18"""19yield self.vendor_pkg + '.'20yield ''2122def find_module(self, fullname, path=None):23"""24Return self when fullname starts with root_name and the25target module is one vendored through this importer.26"""27root, base, target = fullname.partition(self.root_name + '.')28if root:29return30if not any(map(target.startswith, self.vendored_names)):31return32return self3334def load_module(self, fullname):35"""36Iterate over the search path to locate and load fullname.37"""38root, base, target = fullname.partition(self.root_name + '.')39for prefix in self.search_path:40try:41extant = prefix + target42__import__(extant)43mod = sys.modules[extant]44sys.modules[fullname] = mod45return mod46except ImportError:47pass48else:49raise ImportError(50"The '{target}' package is required; "51"normally this is bundled with this package so if you get "52"this warning, consult the packager of your "53"distribution.".format(**locals())54)5556def install(self):57"""58Install this importer into sys.meta_path if not already present.59"""60if self not in sys.meta_path:61sys.meta_path.append(self)626364names = 'six', 'packaging', 'pyparsing', 'ordered_set',65VendorImporter(__name__, names, 'setuptools._vendor').install()666768