Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Guess missing dependencies
4"""
5from .pip_helper import get_installed_distributions
8def get_default_ignore_modules():
9 """
10 A couple of modules have some dependencies on not supported modules
11 or modules integrated to the standard distributiion such
12 `enum34 <https://pypi.python.org/pypi/enum34>`_.
13 This function returns this list.
14 Skips errors such as ``Module 'cachecontrol' misses 'msgpack_python'``.
15 """
16 return [
17 "argparse", # standard distribution (>= 3.5)
18 "backports.weakref", # standard distribution (>= 3.4)
19 "distribute", # standard distribution
20 "enum", # standard distribution (>= 3.4)
21 "enum34", # standard distribution (>= 3.4)
22 "enum_compat", # standard distribution (>= 3.4)
23 "enum-compat", # standard distribution (>= 3.4)
24 "fasttsne", # deprecated module
25 "futures", # standard distribution (>= 3.5)
26 "holoviews", # needed by geoviews but still marked as missing
27 "hypertemp", # temporary solution, should disappear
28 "keyrings.alt", # weird this one on Windows
29 # "guidata",
30 # "monotonic",
31 "msgpack_python", # Called msgpack now.
32 "msgpack-python", # Called msgpack now.
33 "onnx", # working on it
34 "ordereddict", # standard distribution (>= 3.4)
35 "path", # subfolder of existing module
36 "path.py", # weird
37 "pathlib", # standard distribution (>= 3.5)
38 "pip", # almost standard distribution, should be rare
39 "pipdeptree", # weird
40 # manny names for this one (PTable, not maintained anymore)
41 "prettytable",
42 "pycryptodome", # many names for this one
43 "pydocstyle", # does not seem to be maintained
44 "pyopengl", # weird this one
45 "pypiwin32", # manny names for this one
46 "pythonnet", # weird
47 "pywin32", # manny names for this one
48 "pywin32_ctypes", # manny names for this one
49 "rope", # for spyder
50 "setuptools", # standard distribution
51 "typing", # standard distribution (>= 3.6)
52 ]
55def _main_pipdeptree(local_only=False):
56 """
57 The function relies on module
58 `pipdeptree.main <https://pypi.python.org/pypi/pipdeptree>`_.
59 """
60 default_skip = ['setuptools', 'pip', 'python', 'distribute', 'hypertemp']
61 skip = default_skip + ['pipdeptree']
62 pkgs = get_installed_distributions(local_only=local_only, skip=skip)
63 req_map = dict((p.key, (p, p.requires())) for p in pkgs)
64 return req_map
67def missing_dependencies(specific=None, ignore_module=get_default_ignore_modules()):
68 """
69 Returns the list of missing dependencies for the installed modules.
71 @param specific look dependencies only for a specific module
72 @param ignore_module list of modules not to consider as a missing dependency
73 even if they are installed
74 @return list of missing dependencies as dictionary (module, missing dependencies)
76 .. versionchanged:: 1.5
77 Parameters *ignore_module*.
78 """
79 skip = set(ignore_module)
80 tree = _main_pipdeptree()
81 stack = {}
82 for k, v in tree.items():
83 if specific is not None and specific != k:
84 continue
85 for mod in v[1]:
86 dep = mod.key
87 if dep in skip:
88 continue
89 if dep not in tree:
90 if "-" in dep:
91 dep = dep.replace("-", "_")
92 elif "_" in dep:
93 dep = dep.replace("_", "_")
94 if dep not in tree:
95 if k not in stack:
96 stack[k] = []
97 stack[k].append(dep)
98 return stack