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 updates all modules,
4works on Linux and Windows if the module is
5included the list of modules handled by this module
6"""
7from __future__ import print_function
8import sys
9import os
10import argparse
13def get_parser():
14 """
15 defines the way to parse the script ``pymy_update``
16 """
17 typstr = str # unicode#
18 parser = argparse.ArgumentParser(
19 description='update modules, consider wheels when the module includes C++ files')
20 parser.add_argument(
21 '-s',
22 '--skip',
23 default="ete,dataspyre,pycuda,cubehelix",
24 type=typstr,
25 help='list of modules to skip (not to be updated) separated by a comma')
26 parser.add_argument(
27 '-f',
28 '--folder',
29 type=typstr,
30 default="build/update_modules",
31 help='folder where modules will be downloaded')
32 parser.add_argument(
33 '--set',
34 default="-",
35 type=typstr,
36 help='set of module to install, see documentation of function get_name_set to get a comprehensive list, ' +
37 'this option is ignored if a module is specified on the command line')
38 parser.add_argument(
39 '--source',
40 default="",
41 type=typstr,
42 help='overwrite the source of the wheels')
43 parser.add_argument(
44 '--schedule',
45 action='store_true',
46 help='do not update the modules, returned the list scheduled to be updated')
47 parser.add_argument(
48 'module',
49 nargs="*",
50 default="all",
51 help='update only the list of modules included in this list or all modules if not specified or equal to all')
52 return parser
55def do_main(temp_folder="build/update_modules",
56 skip_module="ete dataspyre pycuda cubehelix".split(),
57 list_module=None, schedule_only=False, source=None):
58 """
59 calls function @see fn update_all but is meant to be added to scripts folder
61 @param temp_folder folder where modules will be downloaded
62 @param skip_module skip the module on this list
63 @param list_module list of modules to update or None for all
64 @param schedule_only if True, the function returns the list of modules scheduled to be installed
65 @param source overwrite the source of the wheels
66 """
67 try:
68 from pymyinstall import is_travis_or_appveyor
69 except ImportError:
70 def is_travis_or_appveyor():
71 if "travis" in sys.executable:
72 return "travis"
73 if os.environ.get("USERNAME", os.environ.get("USER", None)) == "appveyor":
74 return "appveyor"
75 return None
76 if is_travis_or_appveyor() and source is None:
77 source = "2"
79 if not os.path.exists(temp_folder):
80 os.makedirs(temp_folder)
81 try:
82 from pymyinstall.packaged import update_all
83 except ImportError:
84 pfolder = os.path.normpath(os.path.join(
85 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
86 sys.path.append(pfolder)
87 if "pymyinstall" in sys.modules:
88 del sys.modules["pymyinstall"]
89 if "pymyinstall.packaged" in sys.modules:
90 del sys.modules["pymyinstall.packaged"]
91 from pymyinstall.packaged import update_all
92 res = update_all(temp_folder=temp_folder, verbose=True,
93 skip_module=skip_module, list_module=list_module,
94 schedule_only=schedule_only, source=source)
95 if schedule_only:
96 print("SCHEDULED")
97 for r in res:
98 print(r)
101def main():
102 """
103 calls function @see fn update_all but is meant to be added to scripts folder,
104 parse command line arguments
105 """
106 parser = get_parser()
107 try:
108 res = parser.parse_args()
109 except SystemExit:
110 print(parser.format_usage())
111 res = None
113 if res is not None:
114 skip_module = None if res.skip in [
115 "", "-", None, []] else res.skip.split(",")
116 list_module = None if res.module in [
117 "all", "", "-", None, []] else res.module
118 if list_module is None and res.set is not None and len(res.set) > 0 and res.set != "-":
119 list_module = res.set
120 do_main(temp_folder=res.folder, skip_module=skip_module,
121 list_module=list_module, schedule_only=res.schedule,
122 source=res.source if res.source else None)
125if __name__ == "__main__":
126 main()