CYCAMORE
Loading...
Searching...
No Matches
install.py
Go to the documentation of this file.
1#! /usr/bin/env python3
2from __future__ import print_function, unicode_literals
3import os
4import sys
5import tarfile
6import platform
7import subprocess
8import shutil
9import io
10if sys.version_info[0] < 3:
11 from urllib import urlopen
12else:
13 from urllib.request import urlopen
14
15try:
16 import argparse as ap
17except ImportError:
18 import pyne._argparse as ap
19
20absexpanduser = lambda x: os.path.abspath(os.path.expanduser(x))
21
22
23def check_windows_cmake(cmake_cmd):
24 if os.name == 'nt':
25 files_on_path = set()
26 for p in os.environ['PATH'].split(';')[::-1]:
27 if os.path.exists(p):
28 files_on_path.update(os.listdir(p))
29 if 'cl.exe' in files_on_path:
30 pass
31 elif 'sh.exe' in files_on_path:
32 cmake_cmd += ['-G "MSYS Makefiles"']
33 elif 'gcc.exe' in files_on_path:
34 cmake_cmd += ['-G "MinGW Makefiles"']
35 cmake_cmd = ' '.join(cmake_cmd)
36
38 root_dir = os.path.split(__file__)[0]
39 fname = os.path.join(root_dir, 'src', 'version.cc.in')
40 cmd = 'touch {0}'.format(fname)
41 subprocess.check_call(cmd.split(), shell=(os.name == 'nt'))
42
44 if not os.path.exists(args.build_dir):
45 os.mkdir(args.build_dir)
46 elif args.clean_build:
47 shutil.rmtree(args.build_dir)
48 os.mkdir(args.build_dir)
49
50 root_dir = os.path.split(__file__)[0]
51 makefile = os.path.join(args.build_dir, 'Makefile')
52 on_darwin = platform.system() == 'Darwin'
53 libext = '.dylib' if on_darwin else '.so'
54
55 if not os.path.exists(makefile):
56 rtn = subprocess.call(['which', 'cmake'], shell=(os.name == 'nt'))
57 if rtn != 0:
58 sys.exit("CMake could not be found, "
59 "please install CMake before developing Cyclus.")
60 cmake_cmd = ['cmake', os.path.abspath(root_dir)]
61 if args.prefix:
62 cmake_cmd += ['-DCMAKE_INSTALL_PREFIX=' +
63 absexpanduser(args.prefix)]
64 if args.cmake_prefix_path:
65 cmake_cmd += ['-DCMAKE_PREFIX_PATH=' +
66 absexpanduser(args.cmake_prefix_path)]
67 if cmake_cmd is not None:
68 cmake_cmd += ['-DDEFAULT_ALLOW_MILPS=' +
69 ('TRUE' if args.allow_milps else 'FALSE')]
70 if args.deps_root:
71 cmake_cmd += ['-DDEPS_ROOT_DIR=' + absexpanduser(args.deps_root)]
72 if args.coin_root:
73 cmake_cmd += ['-DCOIN_ROOT_DIR=' + absexpanduser(args.coin_root)]
74 if args.boost_root:
75 cmake_cmd += ['-DBOOST_ROOT=' + absexpanduser(args.boost_root)]
76 if args.cyclus_root:
77 cmake_cmd += ['-DCYCLUS_ROOT_DIR='+absexpanduser(args.cyclus_root)]
78 if args.hdf5_root:
79 h5root = absexpanduser(args.hdf5_root)
80 cmake_cmd += ['-DHDF5_ROOT=' + h5root,
81 '-DHDF5_LIBRARIES={0}/lib/libhdf5{1};{0}/lib/libhdf5_hl{1}'.format(h5root, libext),
82 '-DHDF5_LIBRARY_DIRS=' + h5root + '/lib',
83 '-DHDF5_INCLUDE_DIRS=' + h5root + '/include',
84 ]
85 if args.build_type:
86 cmake_cmd += ['-DCMAKE_BUILD_TYPE=' + args.build_type]
87 if args.D is not None:
88 cmake_cmd += ['-D' + x for x in args.D]
89 if args.cmake_debug:
90 cmake_cmd += ['-Wdev', '--debug-output']
91 check_windows_cmake(cmake_cmd)
92 rtn = subprocess.check_call(cmake_cmd, cwd=args.build_dir,
93 shell=(os.name == 'nt'))
94
95 if args.config_only:
96 return
97
98 if args.update:
100
101 make_cmd = ['make']
102 if args.threads:
103 make_cmd += ['-j' + str(args.threads)]
104 rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
105 shell=(os.name == 'nt'))
106
107 if args.test:
108 make_cmd += ['test']
109 elif not args.build_only:
110 make_cmd += ['install']
111
112 rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
113 shell=(os.name == 'nt'))
114
116 makefile = os.path.join(args.build_dir, 'Makefile')
117 if not os.path.exists(args.build_dir) or not os.path.exists(makefile):
118 sys.exit("May not uninstall Cyclus since it has not yet been built.")
119 rtn = subprocess.check_call(['make', 'uninstall'], cwd=args.build_dir,
120 shell=(os.name == 'nt'))
121
122
123def main():
124 localdir = absexpanduser('~/.local')
125
126 description = "A Cyclus installation helper script. " +\
127 "For more information, please see cyclus.github.com."
128 parser = ap.ArgumentParser(description=description)
129
130 build_dir = 'where to place the build directory'
131 parser.add_argument('--build_dir', help=build_dir, default='build')
132
133 uninst = 'uninstall'
134 parser.add_argument('--uninstall', action='store_true', help=uninst, default=False)
135
136 noupdate = 'do not update the hash in version.cc'
137 parser.add_argument('--no-update', dest='update', action='store_false',
138 help=noupdate, default=True)
139
140 clean = 'attempt to remove the build directory before building'
141 parser.add_argument('--clean-build', action='store_true', help=clean)
142
143 threads = "the number of threads to use in the make step"
144 parser.add_argument('-j', '--threads', type=int, help=threads)
145
146 prefix = "the relative path to the installation directory"
147 parser.add_argument('--prefix', help=prefix, default=localdir)
148
149 config_only = 'only configure the package, do not build or install'
150 parser.add_argument('--config-only', action='store_true', help=config_only)
151
152 build_only = 'only build the package, do not install'
153 parser.add_argument('--build-only', action='store_true', help=build_only)
154
155 test = 'run tests after building'
156 parser.add_argument('--test', action='store_true', help=test)
157
158 parser.add_argument('--allow-milps', action='store_true',
159 dest='allow_milps', default=None,
160 help='Allows mixed integer linear programs by default')
161 parser.add_argument('--dont-allow-milps', action='store_false',
162 dest='allow_milps',
163 help="Don't Allows mixed integer linear programs "
164 "by default")
165
166 deps = "the path to the directory containing all dependencies"
167 parser.add_argument('--deps-root', '--deps_root', help=deps,
168 default=None, dest='deps_root')
169
170 coin = "the relative path to the Coin-OR libraries directory"
171 parser.add_argument('--coin-root', '--coin_root', help=coin)
172
173 boost = "the relative path to the Boost libraries directory"
174 parser.add_argument('--boost_root', help=boost)
175
176 hdf5 = "the path to the HDF5 libraries directory"
177 parser.add_argument('--hdf5_root', help=hdf5)
178
179 cyclus = "the relative path to Cyclus installation directory"
180 parser.add_argument('--cyclus-root', '--cyclus_root', help=cyclus)
181
182 cmake_prefix_path = "the cmake prefix path for use with FIND_PACKAGE, " + \
183 "FIND_PATH, FIND_PROGRAM, or FIND_LIBRARY macros"
184 parser.add_argument('--cmake_prefix_path', help=cmake_prefix_path)
185
186 build_type = "the CMAKE_BUILD_TYPE"
187 parser.add_argument('--build-type', '--build_type', help=build_type,
188 default='Release')
189
190 parser.add_argument('-D', metavar='VAR', action='append',
191 help='Set enviornment variable(s).')
192 parser.add_argument('--cmake-debug', action='store_true', default=False,
193 dest='cmake_debug', help='puts CMake itself in a debug mode '
194 'when dealing with build system issues.')
195
196 args = parser.parse_args()
197 # modify roots as needed
198 if args.deps_root is not None:
199 roots = ['coin_root', 'boost_root', 'hdf5_root', 'cyclus_root']
200 for name in roots:
201 if not getattr(args, name, None):
202 setattr(args, name, args.deps_root)
203 # run code
204 if args.uninstall:
205 uninstall_cyclus(args)
206 else:
207 install_cyclus(args)
208
209if __name__ == "__main__":
210 main()
uninstall_cyclus(args)
Definition install.py:115
check_windows_cmake(cmake_cmd)
Definition install.py:23
os absexpanduser
Definition install.py:20
update_describe()
Definition install.py:37
install_cyclus(args)
Definition install.py:43