Hide keyboard shortcuts

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""" 

5 

6 

7def get_default_ignore_modules(): 

8 """ 

9 A couple of modules have some dependencies on not supported modules 

10 or modules integrated to the standard distributiion such 

11 `enum34 <https://pypi.python.org/pypi/enum34>`_. 

12 This function returns this list. 

13 Skips errors such as ``Module 'cachecontrol' misses 'msgpack_python'``. 

14 """ 

15 return [ 

16 "argparse", # standard distribution (>= 3.5) 

17 "backports.weakref", # standard distribution (>= 3.4) 

18 "distribute", # standard distribution 

19 "enum", # standard distribution (>= 3.4) 

20 "enum34", # standard distribution (>= 3.4) 

21 "enum_compat", # standard distribution (>= 3.4) 

22 "enum-compat", # standard distribution (>= 3.4) 

23 "fasttsne", # deprecated module 

24 "futures", # standard distribution (>= 3.5) 

25 "holoviews", # needed by geoviews but still marked as missing 

26 "hypertemp", # temporary solution, should disappear 

27 "keyrings.alt", # weird this one on Windows 

28 # "guidata", 

29 # "monotonic", 

30 "msgpack_python", # Called msgpack now. 

31 "msgpack-python", # Called msgpack now. 

32 "onnx", # working on it 

33 "ordereddict", # standard distribution (>= 3.4) 

34 "path", # subfolder of existing module 

35 "path.py", # weird 

36 "pathlib", # standard distribution (>= 3.5) 

37 "pip", # almost standard distribution, should be rare 

38 "pipdeptree", # weird 

39 # manny names for this one (PTable, not maintained anymore) 

40 "prettytable", 

41 "pycryptodome", # many names for this one 

42 "pydocstyle", # does not seem to be maintained 

43 "pyopengl", # weird this one 

44 "pypiwin32", # manny names for this one 

45 "pythonnet", # weird 

46 "pywin32", # manny names for this one 

47 "pywin32_ctypes", # manny names for this one 

48 "rope", # for spyder 

49 "setuptools", # standard distribution 

50 "typing", # standard distribution (>= 3.6) 

51 ] 

52 

53 

54def _main_pipdeptree(local_only=False): 

55 """ 

56 The function relies on module 

57 `pipdeptree.main <https://pypi.python.org/pypi/pipdeptree>`_. 

58 """ 

59 from pip._internal.utils.misc import get_installed_distributions 

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 

65 

66 

67def missing_dependencies(specific=None, ignore_module=get_default_ignore_modules()): 

68 """ 

69 Returns the list of missing dependencies for the installed modules. 

70 

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) 

75 

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