update Install.py for ScaFaCoS to use argparse

This commit is contained in:
Axel Kohlmeyer
2019-01-14 14:44:32 -05:00
parent e4cf409d69
commit ef25afcedb
2 changed files with 68 additions and 75 deletions

View File

@ -1,3 +1,4 @@
/scafacos* /scafacos*
/includelink /includelink
/liblink /liblink
/build

View File

@ -1,14 +1,23 @@
#!/usr/bin/env python #!/usr/bin/env python
# Install.py tool to download, unpack, build, and link to the Scafacos library # Install.py tool to download, unpack, build, and link to the ScaFaCoS library
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess,shutil import sys,os,re,subprocess,shutil
sys.path.append('..') sys.path.append('..')
from install_helpers import error,fullpath,which,geturl from install_helpers import fullpath,geturl,get_cpus
from argparse import ArgumentParser
# help message parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
# settings
version = "1.0.1"
url = "https://github.com/scafacos/scafacos/releases/download/v%s/scafacos-%s.tar.gz" % (version, version)
# extra help message
help = """ help = """
Syntax from src dir: make lib-scafacos args="-b" Syntax from src dir: make lib-scafacos args="-b"
@ -16,101 +25,84 @@ Syntax from src dir: make lib-scafacos args="-b"
Syntax from lib dir: python Install.py -b Syntax from lib dir: python Install.py -b
or: python Install.py -p /usr/local/scafacos or: python Install.py -p /usr/local/scafacos
specify zero or more options, order does not matter
-b = download and build the Scafacos library
-p = specify folder of existing Scafacos installation
always creates includelink, liblink to Scafacos dirs
Example: Example:
make lib-scafacos args="-b" # download/build in lib/scafacos/scafacos make lib-scafacos args="-b" # download/build in lib/scafacos/scafacos
make lib-scafacos args="-p $HOME/scafacos" # use existing Scafacos installation in $HOME make lib-scafacos args="-p $HOME/scafacos" # use existing ScaFaCoS installation in $HOME
""" """
# settings # parse and process arguments
version = "scafacos-1.0.1" pgroup = parser.add_mutually_exclusive_group()
url = "https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz" pgroup.add_argument("-b", "--build", action="store_true",
#url = "https://gigamove.rz.rwth-aachen.de/d/id/CTzyApN76MXMJ6/dd/100" % version help="download and build the ScaFaCoS library")
pgroup.add_argument("-p", "--path",
help="specify folder of existing ScaFaCoS installation")
parser.add_argument("-v", "--version", default=version,
help="set version of ScaFaCoS to download and build (default: %s)" % version)
# parse args args = parser.parse_args()
args = sys.argv[1:] # print help message and exit, if neither build nor path options are given
nargs = len(args) if args.build == False and not args.path:
parser.print_help()
sys.exit(help)
homepath = "." buildflag = args.build
pathflag = args.path != None
buildflag = True homepath = fullpath(".")
pathflag = False scafacospath = "%s/scafacos-%s" % (homepath,version)
linkflag = True
iarg = 0
while iarg < nargs:
if args[iarg] == "-v":
if iarg+2 > nargs: error(help=help)
version = args[iarg+1]
iarg += 2
elif args[iarg] == "-p":
if iarg+2 > nargs: error(help=help)
scafacospath = fullpath(args[iarg+1])
pathflag = True
iarg += 2
elif args[iarg] == "-b":
buildflag = True
iarg += 1
else: error(help=help)
homepath = fullpath(homepath)
homedir = "%s/%s" % (homepath,version)
if (pathflag): if (pathflag):
if not os.path.isdir(scafacospath): error("Scafacos path does not exist") scafacospath = args.path
homedir =scafacospath if not os.path.isdir("%s/include" % scafacospath):
sys.exit("ScaFaCoS include path for %s does not exist" % scafacospath)
if (not os.path.isdir("%s/lib64" % scafacospath)) \
and (not os.path.isdir("%s/lib" % scafacospath)):
sys.exit("ScaFaCoS lib path for %s does not exist" % scafacospath)
scafacospath = fullpath(scafacospath)
if (buildflag and pathflag): # download and unpack ScaFaCoS tarball
error("Cannot use -b and -p flag at the same time")
# download and unpack Scafacos tarball
if buildflag: if buildflag:
print("Downloading Scafacos ...") print("Downloading ScaFaCoS ...")
geturl(url,"%s/%s.tar.gz" % (homepath,version)) geturl(url,"%s/scafacos-%s.tar.gz" % (homepath,version))
print("Unpacking Scafacos tarball ...") print("Unpacking ScaFaCoS tarball ...")
if os.path.exists("%s/%s" % (homepath,version)): if os.path.exists(scafacospath):
shutil.rmtree("%s/%s" % (homepath,version)) shutil.rmtree(scafacospath)
cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version) cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,scafacospath)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/%s.tar.gz" % (homepath,version)) os.remove("%s.tar.gz" % scafacospath)
if os.path.basename(homedir) != version:
if os.path.exists(homedir):
shutil.rmtree(homedir)
os.rename("%s/%s" % (homepath,version),homedir)
# build Scafacos # build ScaFaCoS
print("Building ScaFaCoS ...")
if buildflag: n_cpu = get_cpus()
print("Building Scafacos ...") cmd = 'cd "%s"; ./configure --prefix="%s/build" --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m --with-internal-fftw --with-internal-pfft --with-internal-pnfft CC=mpicc FC=mpif90 CXX=mpicxx F77=; make -j%d; make install' % (scafacospath,homepath,n_cpu)
n_cpu = get_gpus()
cmd = 'cd "%s"; ./configure --prefix="%s/build" --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m --with-internal-fftw --with-internal-pfft --with-internal-pnfft CC=mpicc FC=mpif90 CXX=mpicxx F77=; make -j%d; make install' % (homedir,homedir,n_cpu)
try: try:
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print(txt.decode('UTF-8')) print(txt.decode('UTF-8'))
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print("Make failed with:\n %s" % e.output.decode('UTF-8')) sys.exit("Make failed with:\n %s" % e.output.decode('UTF-8'))
sys.exit(1)
# create 2 links in lib/scafacos to Scafacos include/lib dirs # create 2 links in lib/scafacos to ScaFaCoS include/lib dirs
if linkflag: print("Creating links to ScaFaCoS include and lib files")
print("Creating links to Scafacos include and lib files") if os.path.isfile("includelink") or os.path.islink("includelink"):
if os.path.isfile("includelink") or os.path.islink("includelink"): os.remove("includelink")
os.remove("includelink") if os.path.isfile("liblink") or os.path.islink("liblink"):
if os.path.isfile("liblink") or os.path.islink("liblink"): os.remove("liblink")
os.remove("liblink") if buildflag:
cmd = 'ln -s "%s/build/include" includelink' % homedir cmd = 'ln -s "%s/build/include" includelink' % homepath
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'ln -s "%s/build/lib" liblink' % homedir cmd = 'ln -s "%s/build/lib" liblink' % homepath
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
else:
cmd = 'ln -s "%s/include" includelink' % scafacospath
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if os.path.isdir("%s/lib64" % scafacospath):
cmd = 'ln -s "%s/lib64" liblink' % scafacospath
else:
cmd = 'ln -s "%s/lib" liblink' % scafacospath
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)