From 2e7bd3367f6b09ba03d2e8836da00c7314e264a0 Mon Sep 17 00:00:00 2001 From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa> Date: Wed, 15 Aug 2012 19:49:01 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8672 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- python/install.py | 87 +++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/python/install.py b/python/install.py index c1e62fc853..e1fa4612b4 100644 --- a/python/install.py +++ b/python/install.py @@ -1,52 +1,67 @@ -#!/usr/bin/env python +#!/usr/local/bin/python -instructions = """copy LAMMPS shared library src/liblammps.so and lammps.py to system dirs -Syntax: python install.py [libdir] [pydir] - libdir = target dir for src/liblammps.so, default = /usr/local/lib, or the first - item in LD_LIBRARY_PATH if it doesn't exist. - pydir = target dir for lammps.py, default = Python site-packages, via distutils.""" +# copy LAMMPS src/liblammps.so and lammps.py to system dirs -import sys, shutil, os +instructions = """ +Syntax: python install.py [-h] [libdir] [pydir] + libdir = target dir for src/liblammps.so, default = /usr/local/lib + pydir = target dir for lammps.py, default = Python site-packages dir +""" -if len(sys.argv) > 3: +import sys,os,commands + +if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 3: print instructions sys.exit() -# verify that our user-specified path is in LD_LIBRARY_PATH -# since if not, the install won't work - -libdir = "/usr/local/lib" -libpaths = os.environ['LD_LIBRARY_PATH'].split(':') -if not libdir in libpaths: - libdir = libpaths[0] +if len(sys.argv) >= 2: libdir = sys.argv[1] +else: libdir = "/usr/local/lib" + +if len(sys.argv) == 3: pydir = sys.argv[2] +else: pydir = "" -pydir = False -try: - libdir = sys.argv[1] - pydir = sys.argv[2] -except IndexError: - pass +# copy C lib to libdir if it exists +# warn if not in LD_LIBRARY_PATH or LD_LIBRARY_PATH is undefined -# copy the C library into place +if not os.path.isdir(libdir): + print "ERROR: libdir %s does not exist" % libdir + sys.exit() + +if "LD_LIBRARY_PATH" not in os.environ: + print "WARNING: LD_LIBRARY_PATH undefined, cannot check libdir %s" % libdir +else: + libpaths = os.environ['LD_LIBRARY_PATH'].split(':') + if libdir not in libpaths: + print "WARNING: libdir %s not in LD_LIBRARY_PATH" % libdir -shutil.copy('../src/liblammps.so', libdir) +str = "cp ../src/liblammps.so %s" % libdir +print str +outstr = commands.getoutput(str) +if len(outstr.strip()): print outstr -# if user-specified, copy lammps.py into directory -# else invoke setup from Distutils to add to site-packages +# copy lammps.py to pydir if it exists +# if pydir not specified, install in site-packages via distutils setup() if pydir: - shutil.copy('../python/lammps.py', pydir) + if not os.path.isdir(pydir): + print "ERROR: pydir %s does not exist" % pydir sys.exit() + str = "cp ../python/lammps.py %s" % pydir + print str + outstr = commands.getoutput(str) + if len(outstr.strip()): print outstr + sys.exit() + +print "installing lammps.py in Python site-packages dir" -from distutils.core import setup - -os.chdir('../python') +os.chdir('../python') # in case invoked via make in src dir +from distutils.core import setup +sys.argv = ["setup.py","install"] # as if had run "python setup.py install" setup(name = "lammps", - version = "15Aug12", - author = "Steve Plimpton", - author_email = "sjplimp@sandia.gov", - url = "http://lammps.sandia.gov", - description = """LAMMPS molecular dynamics library""", - py_modules = ["lammps"] -) + version = "15Aug12", + author = "Steve Plimpton", + author_email = "sjplimp@sandia.gov", + url = "http://lammps.sandia.gov", + description = "LAMMPS molecular dynamics library", + py_modules = ["lammps"]) -- GitLab