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  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.core_version:
88  cmake_cmd += ['-DCORE_VERSION=' + args.core_version]
89  if args.D is not None:
90  cmake_cmd += ['-D' + x for x in args.D]
91  if args.cmake_debug:
92  cmake_cmd += ['-Wdev', '--debug-output']
93  check_windows_cmake(cmake_cmd)
94  rtn = subprocess.check_call(cmake_cmd, cwd=args.build_dir,
95  shell=(os.name == 'nt'))
96 
97  if args.config_only:
98  return
99 
100  if args.update:
102 
103  make_cmd = ['make']
104  if args.threads:
105  make_cmd += ['-j' + str(args.threads)]
106  rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
107  shell=(os.name == 'nt'))
108 
109  if args.test:
110  make_cmd += ['test']
111  elif not args.build_only:
112  make_cmd += ['install']
113 
114  rtn = subprocess.check_call(make_cmd, cwd=args.build_dir,
115  shell=(os.name == 'nt'))
116 
118  makefile = os.path.join(args.build_dir, 'Makefile')
119  if not os.path.exists(args.build_dir) or not os.path.exists(makefile):
120  sys.exit("May not uninstall Cyclus since it has not yet been built.")
121  rtn = subprocess.check_call(['make', 'uninstall'], cwd=args.build_dir,
122  shell=(os.name == 'nt'))
123 
124 
125 def main():
126  localdir = absexpanduser('~/.local')
127 
128  description = "A Cyclus installation helper script. " +\
129  "For more information, please see cyclus.github.com."
130  parser = ap.ArgumentParser(description=description)
131 
132  build_dir = 'where to place the build directory'
133  parser.add_argument('--build_dir', help=build_dir, default='build')
134 
135  uninst = 'uninstall'
136  parser.add_argument('--uninstall', action='store_true', help=uninst, default=False)
137 
138  noupdate = 'do not update the hash in version.cc'
139  parser.add_argument('--no-update', dest='update', action='store_false',
140  help=noupdate, default=True)
141 
142  clean = 'attempt to remove the build directory before building'
143  parser.add_argument('--clean-build', action='store_true', help=clean)
144 
145  threads = "the number of threads to use in the make step"
146  parser.add_argument('-j', '--threads', type=int, help=threads)
147 
148  prefix = "the relative path to the installation directory"
149  parser.add_argument('--prefix', help=prefix, default=localdir)
150 
151  config_only = 'only configure the package, do not build or install'
152  parser.add_argument('--config-only', action='store_true', help=config_only)
153 
154  build_only = 'only build the package, do not install'
155  parser.add_argument('--build-only', action='store_true', help=build_only)
156 
157  test = 'run tests after building'
158  parser.add_argument('--test', action='store_true', help=test)
159 
160  parser.add_argument('--allow-milps', action='store_true',
161  dest='allow_milps', default=None,
162  help='Allows mixed integer linear programs by default')
163  parser.add_argument('--dont-allow-milps', action='store_false',
164  dest='allow_milps',
165  help="Don't Allows mixed integer linear programs "
166  "by default")
167 
168  deps = "the path to the directory containing all dependencies"
169  parser.add_argument('--deps-root', '--deps_root', help=deps,
170  default=None, dest='deps_root')
171 
172  coin = "the relative path to the Coin-OR libraries directory"
173  parser.add_argument('--coin-root', '--coin_root', help=coin)
174 
175  boost = "the relative path to the Boost libraries directory"
176  parser.add_argument('--boost_root', help=boost)
177 
178  hdf5 = "the path to the HDF5 libraries directory"
179  parser.add_argument('--hdf5_root', help=hdf5)
180 
181  cyclus = "the relative path to Cyclus installation directory"
182  parser.add_argument('--cyclus-root', '--cyclus_root', help=cyclus)
183 
184  cmake_prefix_path = "the cmake prefix path for use with FIND_PACKAGE, " + \
185  "FIND_PATH, FIND_PROGRAM, or FIND_LIBRARY macros"
186  parser.add_argument('--cmake_prefix_path', help=cmake_prefix_path)
187 
188  build_type = "the CMAKE_BUILD_TYPE"
189  parser.add_argument('--build-type', '--build_type', help=build_type)
190 
191  parser.add_argument('--core-version', dest='core_version', default=None,
192  help='Sets the core version number.')
193 
194  parser.add_argument('-D', metavar='VAR', action='append',
195  help='Set enviornment variable(s).')
196  parser.add_argument('--cmake-debug', action='store_true', default=False,
197  dest='cmake_debug', help='puts CMake itself in a debug mode '
198  'when dealing with build system issues.')
199 
200  args = parser.parse_args()
201  # modify roots as needed
202  if args.deps_root is not None:
203  roots = ['coin_root', 'boost_root', 'hdf5_root', 'cyclus_root']
204  for name in roots:
205  if not getattr(args, name, None):
206  setattr(args, name, args.deps_root)
207  # run code
208  if args.uninstall:
209  uninstall_cyclus(args)
210  else:
211  install_cyclus(args)
212 
213 if __name__ == "__main__":
214  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:117
def main()
Definition: install.py:125
absexpanduser
Definition: install.py:20