Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pkg_resources/extern/__init__.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
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 = 'packaging', 'pyparsing', 'six', 'appdirs' | |
66 VendorImporter(__name__, names).install() |