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#!python
2"""
3script which looks into the dependencies for a module
5.. todoext::
6 :title: add a script to look into dependencies
7 :tag: done
8 :cost: 0.5
9 :date: 2016-09-18
10 :hidden:
11 :release: 1.1
13 Add a script to check the missing dependencies.
15.. versionadded:: 1.1
16"""
17from __future__ import print_function
18import sys
19import os
20import argparse
23def get_parser():
24 """
25 defines the way to parse the script ``pymy_deps``
26 """
27 parser = argparse.ArgumentParser(
28 description='look dependencies for modules')
29 parser.add_argument(
30 'module',
31 nargs="*",
32 default="all",
33 help='update only the list of modules included in this list or all modules if not specified or equal to all')
34 return parser
37def do_main(list_modules=None):
38 """
39 calls function @see fn missing_dependencies
41 @param list_modules list of modules to update or None for all
42 """
43 try:
44 from pymyinstall.installhelper import missing_dependencies, get_module_dependencies
45 except ImportError:
46 pfolder = os.path.normpath(os.path.join(
47 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
48 sys.path.append(pfolder)
49 if "pymyinstall" in sys.modules:
50 del sys.modules["pymyinstall"]
51 if "pymyinstall.installhelper" in sys.modules:
52 del sys.modules["pymyinstall.installhelper"]
53 try:
54 from pymyinstall.installhelper import missing_dependencies, get_module_dependencies
55 except ImportError as e:
56 mes = "pfolder={0}\nPATH:\n{1}".format(
57 pfolder, "\n".join(sys.path))
58 raise ImportError(mes) from e
59 res = missing_dependencies(list_modules)
60 if len(res) > 0:
61 for r in res:
62 print(r)
63 elif list_modules is not None and len(list_modules) > 0:
64 for mod in list_modules:
65 print("checking ", mod)
66 res = get_module_dependencies(mod)
67 for r, v in sorted(res.items()):
68 print(" ", r, v)
69 else:
70 print("no missing dependencies")
73def main():
74 """
75 calls function @see fn missing_dependencies but is meant to be added to scripts folder,
76 parse command line arguments
77 """
78 parser = get_parser()
79 try:
80 res = parser.parse_args()
81 except SystemExit:
82 print(parser.format_usage())
83 res = None
85 if res is not None:
86 list_module = None if res.module in [
87 "all", "", "-", None, []] else res.module
88 do_main(list_modules=list_module)
91if __name__ == "__main__":
92 main()