-
Notifications
You must be signed in to change notification settings - Fork 35
/
setuptools.py
90 lines (73 loc) · 3.18 KB
/
setuptools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import sys
import textwrap
if sys.version_info[0] == 2:
from cStringIO import StringIO
else:
from io import StringIO
PRESCRIPT = textwrap.dedent(
"""\
import pkg_resources, zipimport, os
def find_eggs_in_zip(importer, path_item, only=False):
if importer.archive.endswith('.whl'):
# wheels are not supported with this finder
# they don't have PKG-INFO metadata, and won't ever contain eggs
return
metadata = pkg_resources.EggMetadata(importer)
if metadata.has_metadata('PKG-INFO'):
yield Distribution.from_filename(path_item, metadata=metadata)
for subitem in metadata.resource_listdir(''):
if not only and pkg_resources._is_egg_path(subitem):
subpath = os.path.join(path_item, subitem)
dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath)
for dist in dists:
yield dist
elif subitem.lower().endswith(('.dist-info', '.egg-info')):
subpath = os.path.join(path_item, subitem)
submeta = pkg_resources.EggMetadata(zipimport.zipimporter(subpath))
submeta.egg_info = subpath
yield pkg_resources.Distribution.from_location(path_item, subitem, submeta)
def _fixup_pkg_resources():
pkg_resources.register_finder(zipimport.zipimporter, find_eggs_in_zip)
pkg_resources.working_set.entries = []
list(map(pkg_resources.working_set.add_entry, sys.path))
_fixup_pkg_resources()
"""
)
def check(cmd, mf):
m = mf.findNode("pkg_resources")
if m is None or m.filename is None:
return None
if m.filename.endswith("__init__.py"):
vendor_dir = os.path.join(os.path.dirname(m.filename), "_vendor")
else:
vendor_dir = os.path.join(m.filename, "_vendor")
expected_missing_imports = {
"__main__.__requires__",
}
if os.path.exists(vendor_dir):
for topdir, dirs, files in os.walk(vendor_dir):
for fn in files:
if fn in ("__pycache__", "__init__.py"):
continue
relnm = os.path.relpath(os.path.join(topdir, fn), vendor_dir)
if relnm.endswith(".py"):
relnm = relnm[:-3]
relnm = relnm.replace("/", ".")
if fn.endswith(".py"):
mf.import_hook("pkg_resources._vendor." + relnm, m, ["*"])
expected_missing_imports.add("pkg_resources.extern." + relnm)
for dn in dirs:
if not os.path.exists(os.path.join(topdir, dn, "__init__.py")):
continue
relnm = os.path.relpath(os.path.join(topdir, dn), vendor_dir)
relnm = relnm.replace("/", ".")
mf.import_hook("pkg_resources._vendor." + relnm, m, ["*"])
expected_missing_imports.add("pkg_resources.extern." + relnm)
mf.import_hook("pkg_resources._vendor", m)
if sys.version[0] != 2:
expected_missing_imports.add("__builtin__")
return {
"expected_missing_imports": expected_missing_imports,
"prescripts": [StringIO(PRESCRIPT)],
}