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 installs 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_install``
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 '-d',
34 '--deps',
35 action='store_true',
36 help='install a module or the modules with their dependencies')
37 parser.add_argument(
38 '--check',
39 default="",
40 help='check every installed module by importing them, all others options are ignored, ' +
41 'the value can be null, a module name or a list comma separated, two integers semi-colon separated 1:end')
42 parser.add_argument(
43 '--deep-deps',
44 action='store_true',
45 help='install a module or the modules with their dependencies, check dependencies of dependencies are installed')
46 parser.add_argument(
47 '--set',
48 default="-",
49 type=typstr,
50 help='set of module to install, see documentation of function get_name_set to get a comprehensive list, ' +
51 'this option is ignored if a module is specified on the command line')
52 parser.add_argument(
53 '--schedule',
54 action='store_true',
55 help='do not install the modules, returned the list scheduled to be installed')
56 parser.add_argument(
57 '--force',
58 action='store_true',
59 help='install or download even the module is already installed')
60 parser.add_argument(
61 '--download',
62 action='store_true',
63 help='do not install the modules but download them')
64 parser.add_argument(
65 '-t',
66 '--task',
67 default="install",
68 type=typstr,
69 choices=['install', 'shebang', 'download', 'tool', 'tool_download'],
70 help='default task is install but the script can patch shebang in their current location (task=shebang)')
71 parser.add_argument(
72 'module',
73 nargs='*',
74 default="all",
75 help='update only the list of modules included in this list or all modules if not specified or equal to all')
76 parser.add_argument(
77 '--source',
78 default="",
79 type=typstr,
80 help='overwrite the source of the wheels')
81 return parser
84def do_main(temp_folder="build/update_modules",
85 skip_module=None, # ["ete", "dataspyre", "pycuda", "cubehelix"],
86 list_module=None, deps=False, schedule_only=False,
87 deep_deps=False, checkings=None,
88 task="install", source=None, download_only=False,
89 force=False):
90 """
91 calls function @see fn install_all but is meant to be added to scripts folder
93 @param temp_folder folder where modules will be downloaded
94 @param skip_module skip the module on this list
95 @param list_module list of modules to update or None for all
96 @param deps install a module with its dependencies
97 @param schedule_only if True, the function returns the list of modules scheduled to be installed
98 @param deep_deps check dependencies for dependencies
99 @param checkings if True, run checkings, do not install anything, example of values
100 @param task *install* or *shebang* or *download*
101 ``""``, ``matplotlib``, ``100,end``,
102 option *download* is equivalent to *checkings*
103 @param source overwrite the source of the wheel
104 @param download_only only download the modules, no installation
105 @param force force the download or the installation
107 If *deps* is True, *list_module* cannot be empty.
109 .. versionchanged:: 1.1
110 Parameters *source*, *force* were added.
111 """
112 try:
113 from pymyinstall import is_travis_or_appveyor
114 except ImportError:
115 def is_travis_or_appveyor():
116 if "travis" in sys.executable:
117 return "travis"
118 if os.environ.get("USERNAME", os.environ.get("USER", None)) == "appveyor":
119 return "appveyor"
120 return None
121 if is_travis_or_appveyor() and source is None:
122 source = "2"
124 if task in ("install", "download"):
125 checkings = checkings or task == "download"
126 if checkings:
127 try:
128 from pymyinstall.win_installer import import_every_module
129 except ImportError:
130 pfolder = os.path.normpath(os.path.join(
131 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
132 sys.path.append(pfolder)
133 if "pymyinstall" in sys.modules:
134 del sys.modules["pymyinstall"]
135 if "pymyinstall.win_installer" in sys.modules:
136 del sys.modules["pymyinstall.win_installer"]
137 from pymyinstall.win_installer import import_every_module
139 def to_int(s):
140 if "end" in s:
141 return -1
142 try:
143 return int(s)
144 except ValueError:
145 return -1
147 if checkings in ("", "0,end", "0,-1"):
148 module_list = None
149 start = 0
150 end = -1
151 elif ":" in checkings:
152 module_list = None
153 spl = checkings.split(":")
154 if len(spl) == 2:
155 start = to_int(spl[0])
156 end = to_int(spl[1])
157 else:
158 raise ValueError("unable to interpret: " + checkings)
159 else:
160 module_list = [_.strip() for _ in checkings.split(",")]
161 start = 0
162 end = -1
164 print("CHECKINGS {}:{} -- {}".format(start, end,
165 "all" if module_list is None else ",".join(module_list)))
166 import_every_module(None, module_list, start=start, end=end)
167 else:
168 if not os.path.exists(temp_folder):
169 os.makedirs(temp_folder)
170 try:
171 from pymyinstall.packaged import install_all
172 except ImportError:
173 folder = os.path.normpath(os.path.join(
174 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
175 sys.path.append(folder)
176 if "pymyinstall" in sys.modules:
177 del sys.modules["pymyinstall"]
178 if "pymyinstall.packaged" in sys.modules:
179 del sys.modules["pymyinstall.packaged"]
180 from pymyinstall.packaged import install_all
181 res = install_all(temp_folder=temp_folder, verbose=True,
182 skip_module=skip_module, list_module=list_module, deps=deps,
183 schedule_only=schedule_only,
184 deep_deps=deep_deps, source=source,
185 download_only=download_only, force=force)
186 if schedule_only:
187 print("SCHEDULED")
188 for r in res:
189 print(r)
190 elif task == "shebang":
191 try:
192 from pymyinstall.win_installer import win_patch_paths
193 from pymyinstall.installhelper import get_pip_program
194 except ImportError:
195 pfolder = os.path.normpath(os.path.join(
196 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
197 sys.path.append(pfolder)
198 if "pymyinstall" in sys.modules:
199 del sys.modules["pymyinstall"]
200 if "pymyinstall.packaged" in sys.modules:
201 del sys.modules["pymyinstall.packaged"]
202 if "pymyinstall.win_installer" in sys.modules:
203 del sys.modules["pymyinstall.win_installer"]
204 from pymyinstall.win_installer import win_patch_paths
205 from pymyinstall.installhelper import get_pip_program
206 pip = get_pip_program()
207 folder = os.path.dirname(os.path.abspath(pip))
208 win_patch_paths(temp_folder, None, fLOG=print)
209 elif task in ("tool", "tool_download"):
210 try:
211 from pymyinstall.installcustom import install_graphviz
212 except ImportError:
213 pfolder = os.path.normpath(os.path.join(
214 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
215 sys.path.append(pfolder)
216 if "pymyinstall" in sys.modules:
217 del sys.modules["pymyinstall"]
218 if "pymyinstall.installcustom" in sys.modules:
219 del sys.modules["pymyinstall.installcustom"]
220 from pymyinstall.installcustom import install_graphviz
221 if list_module is None:
222 raise ValueError("A tool must be precised, list cannot be empty.")
223 low = [_.lower() for _ in list_module]
224 for tool in low:
225 if tool == "graphviz":
226 install_graphviz(temp_folder, install=task ==
227 "tool", fLOG=print, source=source)
228 else:
229 raise NameError("unable to install '{0}'".format(tool))
230 else:
231 raise ValueError("unable to interpret task: " + task)
234def main():
235 """
236 calls function @see fn install_all but is meant to be added to scripts folder,
237 parse command line arguments
238 """
239 parser = get_parser()
240 try:
241 res = parser.parse_args()
242 except SystemExit:
243 print(parser.format_usage())
244 res = None
246 if res is not None:
247 skip_module = None if res.skip in [
248 "", "-", None, []] else res.skip.split(",")
249 list_module = None if res.module in [
250 "all", "", "-", None, []] else res.module
251 if list_module is None and res.set is not None and len(res.set) > 0 and res.set != "-":
252 list_module = res.set
253 do_main(temp_folder=res.folder, skip_module=skip_module,
254 list_module=list_module, deps=res.deps, schedule_only=res.schedule,
255 deep_deps=res.deep_deps, checkings=res.check, task=res.task,
256 source=res.source if res.source else None,
257 download_only=res.download, force=res.force)
260if __name__ == "__main__":
261 main()