update generic Install.py script to use argparse
This commit is contained in:
@ -7,33 +7,46 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,subprocess
|
import sys,os,subprocess
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
from install_helpers import error,get_cpus
|
from install_helpers import get_cpus,fullpath
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
# parse args
|
parser = ArgumentParser(prog='Install.py',
|
||||||
|
description="LAMMPS library build wrapper script")
|
||||||
|
|
||||||
args = sys.argv[1:]
|
help = """
|
||||||
nargs = len(args)
|
Syntax from src dir: make lib-libname args="-m machine -e suffix"
|
||||||
if nargs == 0: error()
|
Syntax from lib dir: python Install.py -m machine -e suffix
|
||||||
|
|
||||||
machine = None
|
libname = name of lib dir (e.g. atc, h5md, meam, poems, etc)
|
||||||
extraflag = 0
|
specify -m and optionally -e, order does not matter
|
||||||
|
|
||||||
iarg = 0
|
Examples:
|
||||||
while iarg < nargs:
|
|
||||||
if args[iarg] == "-m":
|
make lib-poems args="-m serial" # build POEMS lib with same settings as in the serial Makefile in src
|
||||||
if iarg+2 > nargs: error()
|
make lib-colvars args="-m mpi" # build USER-COLVARS lib with same settings as in the mpi Makefile in src
|
||||||
machine = args[iarg+1]
|
make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (using Intel Fortran)
|
||||||
iarg += 2
|
"""
|
||||||
elif args[iarg] == "-e":
|
|
||||||
if iarg+2 > nargs: error()
|
# parse and process arguments
|
||||||
extraflag = 1
|
|
||||||
suffix = args[iarg+1]
|
parser.add_argument("-m", "--machine",
|
||||||
iarg += 2
|
help="suffix of a <libname>/Makefile.* file used for compiling this library")
|
||||||
else: error()
|
parser.add_argument("-e", "--extramake",
|
||||||
|
help="set EXTRAMAKE variable in <libname>/Makefile.<machine> to Makefile.lammps.<extramake>")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# print help message and exit, if neither build nor path options are given
|
||||||
|
if not args.machine and not args.extramake:
|
||||||
|
parser.print_help()
|
||||||
|
sys.exit(help)
|
||||||
|
|
||||||
|
machine = args.machine
|
||||||
|
extraflag = args.extramake
|
||||||
|
|
||||||
# set lib from working dir
|
# set lib from working dir
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = fullpath('.')
|
||||||
lib = os.path.basename(cwd)
|
lib = os.path.basename(cwd)
|
||||||
|
|
||||||
# create Makefile.auto as copy of Makefile.machine
|
# create Makefile.auto as copy of Makefile.machine
|
||||||
@ -70,5 +83,6 @@ except subprocess.CalledProcessError as e:
|
|||||||
|
|
||||||
if os.path.exists("lib%s.a" % lib): print("Build was successful")
|
if os.path.exists("lib%s.a" % lib): print("Build was successful")
|
||||||
else: error("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib))
|
else: error("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib))
|
||||||
|
|
||||||
if has_extramake and not os.path.exists("Makefile.lammps"):
|
if has_extramake and not os.path.exists("Makefile.lammps"):
|
||||||
print("lib/%s/Makefile.lammps was NOT created" % lib)
|
print("WARNING: lib/%s/Makefile.lammps was NOT created" % lib)
|
||||||
|
|||||||
@ -1,36 +1,5 @@
|
|||||||
import hashlib,os,subprocess,sys
|
import hashlib,os,subprocess,sys
|
||||||
|
|
||||||
# default help message
|
|
||||||
|
|
||||||
defhelp = """
|
|
||||||
Syntax from src dir: make lib-libname args="-m machine -e suffix"
|
|
||||||
Syntax from lib dir: python Install.py -m machine -e suffix
|
|
||||||
|
|
||||||
libname = name of lib dir (e.g. atc, h5md, meam, poems, etc)
|
|
||||||
specify -m and optionally -e, order does not matter
|
|
||||||
|
|
||||||
-m = peform a clean followed by "make -f Makefile.machine"
|
|
||||||
machine = suffix of a lib/Makefile.* file
|
|
||||||
-e = set EXTRAMAKE variable in Makefile.machine to Makefile.lammps.suffix
|
|
||||||
does not alter existing Makefile.machine
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
make lib-poems args="-m serial" # build POEMS lib with same settings as in the serial Makefile in src
|
|
||||||
make lib-colvars args="-m mpi" # build USER-COLVARS lib with same settings as in the mpi Makefile in src
|
|
||||||
make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (using Intel Fortran)
|
|
||||||
"""
|
|
||||||
|
|
||||||
# print error message or help
|
|
||||||
def error(str=None,help=None):
|
|
||||||
if not str:
|
|
||||||
if not help:
|
|
||||||
print(defhelp)
|
|
||||||
else:
|
|
||||||
print(help)
|
|
||||||
else: print("ERROR",str)
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# try to auto-detect the maximum number of available CPUs
|
# try to auto-detect the maximum number of available CPUs
|
||||||
def get_cpus():
|
def get_cpus():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -6,8 +6,7 @@
|
|||||||
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,get_cpus,fullpath,which,geturl
|
from install_helpers import get_cpus,fullpath,geturl
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
parser = ArgumentParser(prog='Install.py',
|
parser = ArgumentParser(prog='Install.py',
|
||||||
|
|||||||
Reference in New Issue
Block a user