CYCAMORE
install.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 from __future__ import print_function, unicode_literals
3 import os
4 import sys
5 import tarfile
6 import platform
7 import subprocess
8 import shutil
9 import io
10 if sys.version_info[0] < 3:
11  from urllib import urlopen
12 else:
13  from urllib.request import urlopen
14 
15 try:
16  import argparse as ap
17 except ImportError:
18  import pyne._argparse as ap
19 
20 absexpanduser = lambda x: os.path.abspath(os.path.expanduser(x))
21 
22 
23 def 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 
43 def install_cyclus(args):
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  cmake_cmd += ['-DDEFAULT_ALLOW_MILPS=' +
68  ('TRUE' if args.allow_milps else 'FALSE')]
69  if args.deps_root:
70  cmake_cmd += ['-DDEPS_ROOT_DIR=' + absexpanduser(args.deps_root)]
71  if args.coin_root:
72  cmake_cmd += ['-DCOIN_ROOT_DIR=' + absexpanduser(args.coin_root)]
73  if args.boost_root:
74  cmake_cmd += ['-DBOOST_ROOT=' + absexpanduser(args.boost_root)]
75  if args.cyclus_root:
76  cmake_cmd += ['-DCYCLUS_ROOT_DIR='+absexpanduser(args.cyclus_root)]
77  if args.hdf5_root:
78  h5root = absexpanduser(args.hdf5_root)
79  cmake_cmd += ['-DHDF5_ROOT=' + h5root,
80  '-DHDF5_LIBRARIES={0}/lib/libhdf5{1};{0}/lib/libhdf5_hl{1}'.format(h5root, libext),
81  '-DHDF5_LIBRARY_DIRS=' + h5root + '/lib',
82  '-DHDF5_INCLUDE_DIRS=' + h5root + '/include',
83  ]
84  if args.build_type:
85  cmake_cmd += ['-DCMAKE_BUILD_TYPE=' + args.build_type]
86  if args.D is not None:
87  cmake_cmd += ['-D' + x for x in args.D]
88  check_windows_cmake(cmake_cmd)
89  rtn = subprocess.check_call(cmake_cmd, cwd=args.build_dir,
90  shell=(os.name == 'nt'))
91 
92  if args.config_only:
93  return
94 
95  if args.update:
97 
98  make_cmd = ['make']
99  if args.threads:
100  make_cmd += ['-j' + str(args.threads)]
101  rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
102  shell=(os.name == 'nt'))
103 
104  if args.test:
105  make_cmd += ['test']
106  elif not args.build_only:
107  make_cmd += ['install']
108 
109  rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
110  shell=(os.name == 'nt'))
111 
113  makefile = os.path.join(args.build_dir, 'Makefile')
114  if not os.path.exists(args.build_dir) or not os.path.exists(makefile):
115  sys.exist("May not uninstall Cyclus since it has not yet been built.")
116  rtn = subprocess.check_call(['make', 'uninstall'], cwd=args.build_dir,
117  shell=(os.name == 'nt'))
118 
119 
120 def main():
121  localdir = absexpanduser('~/.local')
122 
123  description = "A Cyclus installation helper script. " +\
124  "For more information, please see cyclus.github.com."
125  parser = ap.ArgumentParser(description=description)
126 
127  build_dir = 'where to place the build directory'
128  parser.add_argument('--build_dir', help=build_dir, default='build')
129 
130  uninst = 'uninstall'
131  parser.add_argument('--uninstall', action='store_true', help=uninst, default=False)
132 
133  noupdate = 'do not update the hash in version.cc'
134  parser.add_argument('--no-update', dest='update', action='store_false',
135  help=noupdate, default=True)
136 
137  clean = 'attempt to remove the build directory before building'
138  parser.add_argument('--clean-build', action='store_true', help=clean)
139 
140  threads = "the number of threads to use in the make step"
141  parser.add_argument('-j', '--threads', type=int, help=threads)
142 
143  prefix = "the relative path to the installation directory"
144  parser.add_argument('--prefix', help=prefix, default=localdir)
145 
146  config_only = 'only configure the package, do not build or install'
147  parser.add_argument('--config-only', action='store_true', help=config_only)
148 
149  build_only = 'only build the package, do not install'
150  parser.add_argument('--build-only', action='store_true', help=build_only)
151 
152  test = 'run tests after building'
153  parser.add_argument('--test', action='store_true', help=test)
154 
155  parser.add_argument('--allow-milps', action='store_true',
156  dest='allow_milps', default=True,
157  help='Allows mixed integer linear programs by default')
158  parser.add_argument('--dont-allow-milps', action='store_false',
159  dest='allow_milps',
160  help="Don't Allows mixed integer linear programs "
161  "by default")
162 
163  deps = "the path to the directory containing all dependencies"
164  parser.add_argument('--deps-root', '--deps_root', help=deps,
165  default=None, dest='deps_root')
166 
167  coin = "the relative path to the Coin-OR libraries directory"
168  parser.add_argument('--coin-root', '--coin_root', help=coin)
169 
170  boost = "the relative path to the Boost libraries directory"
171  parser.add_argument('--boost_root', help=boost)
172 
173  hdf5 = "the path to the HDF5 libraries directory"
174  parser.add_argument('--hdf5_root', help=hdf5)
175 
176  cyclus = "the relative path to Cyclus installation directory"
177  parser.add_argument('--cyclus-root', '--cyclus_root', help=cyclus)
178 
179  cmake_prefix_path = "the cmake prefix path for use with FIND_PACKAGE, " + \
180  "FIND_PATH, FIND_PROGRAM, or FIND_LIBRARY macros"
181  parser.add_argument('--cmake_prefix_path', help=cmake_prefix_path)
182 
183  build_type = "the CMAKE_BUILD_TYPE"
184  parser.add_argument('--build-type', '--build_type', help=build_type)
185 
186  parser.add_argument('-D', metavar='VAR', action='append',
187  help='Set enviornment variable(s).')
188 
189  args = parser.parse_args()
190  # modify roots as needed
191  if args.deps_root is not None:
192  roots = ['coin_root', 'boost_root', 'hdf5_root', 'cyclus_root']
193  for name in roots:
194  if not getattr(args, name, None):
195  setattr(args, name, args.deps_root)
196  # run code
197  if args.uninstall:
198  uninstall_cyclus(args)
199  else:
200  install_cyclus(args)
201 
202 if __name__ == "__main__":
203  main()
def check_windows_cmake(cmake_cmd)
Definition: install.py:23
def install_cyclus(args)
Definition: install.py:43
def update_describe()
Definition: install.py:37
def uninstall_cyclus(args)
Definition: install.py:112
def main()
Definition: install.py:120
absexpanduser
Definition: install.py:20