find LAMMPS shared object location for ctypes loading from introspection
This commit is contained in:
@ -3,42 +3,19 @@
|
|||||||
# copy LAMMPS src/liblammps.so and lammps.py to system dirs
|
# copy LAMMPS src/liblammps.so and lammps.py to system dirs
|
||||||
|
|
||||||
instructions = """
|
instructions = """
|
||||||
Syntax: python install.py [-h] [libdir] [pydir]
|
Syntax: python install.py [-h] [pydir]
|
||||||
libdir = target dir for src/liblammps.so, default = /usr/local/lib
|
pydir = target dir for lammps.py and liblammps.so, default = Python site-packages dir
|
||||||
pydir = target dir for lammps.py, default = Python site-packages dir
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys,os,commands
|
import sys,os,commands
|
||||||
|
|
||||||
if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 3:
|
if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 2:
|
||||||
print instructions
|
print instructions
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if len(sys.argv) >= 2: libdir = sys.argv[1]
|
if len(sys.argv) == 2: pydir = sys.argv[1]
|
||||||
else: libdir = "/usr/local/lib"
|
|
||||||
|
|
||||||
if len(sys.argv) == 3: pydir = sys.argv[2]
|
|
||||||
else: pydir = ""
|
else: pydir = ""
|
||||||
|
|
||||||
# copy C lib to libdir if it exists
|
|
||||||
# warn if not in LD_LIBRARY_PATH or LD_LIBRARY_PATH is undefined
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
str = "cp ../src/liblammps.so %s" % libdir
|
|
||||||
print str
|
|
||||||
outstr = commands.getoutput(str)
|
|
||||||
if len(outstr.strip()): print outstr
|
|
||||||
|
|
||||||
# copy lammps.py to pydir if it exists
|
# copy lammps.py to pydir if it exists
|
||||||
# if pydir not specified, install in site-packages via distutils setup()
|
# if pydir not specified, install in site-packages via distutils setup()
|
||||||
|
|
||||||
@ -50,6 +27,9 @@ if pydir:
|
|||||||
print str
|
print str
|
||||||
outstr = commands.getoutput(str)
|
outstr = commands.getoutput(str)
|
||||||
if len(outstr.strip()): print outstr
|
if len(outstr.strip()): print outstr
|
||||||
|
str = "cp ../src/liblammps.so %s" % pydir
|
||||||
|
print str
|
||||||
|
outstr = commands.getoutput(str)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
print "installing lammps.py in Python site-packages dir"
|
print "installing lammps.py in Python site-packages dir"
|
||||||
@ -59,7 +39,7 @@ os.chdir('../python') # in case invoked via make in src dir
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
sys.argv = ["setup.py","install"] # as if had run "python setup.py install"
|
sys.argv = ["setup.py","install"] # as if had run "python setup.py install"
|
||||||
setup(name = "lammps",
|
setup(name = "lammps",
|
||||||
version = "15Aug12",
|
version = "15May15",
|
||||||
author = "Steve Plimpton",
|
author = "Steve Plimpton",
|
||||||
author_email = "sjplimp@sandia.gov",
|
author_email = "sjplimp@sandia.gov",
|
||||||
url = "http://lammps.sandia.gov",
|
url = "http://lammps.sandia.gov",
|
||||||
|
|||||||
@ -15,17 +15,21 @@
|
|||||||
|
|
||||||
import sys,traceback,types
|
import sys,traceback,types
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
import os.path
|
from os.path import dirname,abspath,join
|
||||||
|
from inspect import getsourcefile
|
||||||
|
|
||||||
class lammps:
|
class lammps:
|
||||||
def __init__(self,name="",cmdargs=None,ptr=None):
|
def __init__(self,name="",cmdargs=None,ptr=None):
|
||||||
|
|
||||||
|
# determine module location
|
||||||
|
modpath = dirname(abspath(getsourcefile(lambda:0)))
|
||||||
|
|
||||||
# load liblammps.so by default
|
# load liblammps.so by default
|
||||||
# if name = "g++", load liblammps_g++.so
|
# if name = "g++", load liblammps_g++.so
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not name: self.lib = CDLL("liblammps.so",RTLD_GLOBAL)
|
if not name: self.lib = CDLL(join(modpath,"liblammps.so"),RTLD_GLOBAL)
|
||||||
else: self.lib = CDLL("liblammps_%s.so" % name,RTLD_GLOBAL)
|
else: self.lib = CDLL(join(modpath,"/liblammps_%s.so" % name),RTLD_GLOBAL)
|
||||||
except:
|
except:
|
||||||
type,value,tb = sys.exc_info()
|
type,value,tb = sys.exc_info()
|
||||||
traceback.print_exception(type,value,tb)
|
traceback.print_exception(type,value,tb)
|
||||||
|
|||||||
Reference in New Issue
Block a user