2013-06-10 23:01:13 +08:00
|
|
|
#!/usr/bin/env python
|
2012-08-14 23:40:43 +08:00
|
|
|
|
2012-08-16 03:49:01 +08:00
|
|
|
# copy LAMMPS src/liblammps.so and lammps.py to system dirs
|
2012-08-14 23:40:43 +08:00
|
|
|
|
2016-05-12 21:53:40 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2012-08-16 03:49:01 +08:00
|
|
|
instructions = """
|
2015-07-03 03:09:11 +08:00
|
|
|
Syntax: python install.py [-h] [pydir]
|
|
|
|
pydir = target dir for lammps.py and liblammps.so
|
|
|
|
default = Python site-packages dir
|
2012-08-16 03:49:01 +08:00
|
|
|
"""
|
2012-08-14 23:40:43 +08:00
|
|
|
|
2016-05-12 21:53:40 +08:00
|
|
|
import sys,os,shutil
|
2012-08-16 03:49:01 +08:00
|
|
|
|
2015-07-03 03:09:11 +08:00
|
|
|
if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 2:
|
2016-05-12 21:53:40 +08:00
|
|
|
print(instructions)
|
2012-08-15 04:13:20 +08:00
|
|
|
sys.exit()
|
2012-08-14 23:40:43 +08:00
|
|
|
|
2015-07-03 03:09:11 +08:00
|
|
|
if len(sys.argv) == 2: pydir = sys.argv[1]
|
2012-08-16 03:49:01 +08:00
|
|
|
else: pydir = ""
|
2012-08-14 23:40:43 +08:00
|
|
|
|
2012-08-16 03:49:01 +08:00
|
|
|
# copy lammps.py to pydir if it exists
|
|
|
|
# if pydir not specified, install in site-packages via distutils setup()
|
2012-08-15 22:34:23 +08:00
|
|
|
|
|
|
|
if pydir:
|
2012-08-16 03:49:01 +08:00
|
|
|
if not os.path.isdir(pydir):
|
2016-05-12 21:53:40 +08:00
|
|
|
print( "ERROR: pydir %s does not exist" % pydir)
|
2012-08-15 22:34:23 +08:00
|
|
|
sys.exit()
|
2012-08-16 03:49:01 +08:00
|
|
|
str = "cp ../python/lammps.py %s" % pydir
|
2016-05-12 21:53:40 +08:00
|
|
|
print(str)
|
|
|
|
try:
|
|
|
|
shutil.copyfile("../python/lammps.py", os.path.join(pydir,'lammps.py') )
|
|
|
|
except shutil.Error:
|
|
|
|
pass # source and destination are identical
|
|
|
|
|
2015-07-03 03:09:11 +08:00
|
|
|
str = "cp ../src/liblammps.so %s" % pydir
|
2016-05-12 21:53:40 +08:00
|
|
|
print(str)
|
|
|
|
try:
|
|
|
|
shutil.copyfile("../src/liblammps.so", os.path.join(pydir,"liblammps.so") )
|
|
|
|
except shutil.Error:
|
|
|
|
pass # source and destination are identical
|
2012-08-16 03:49:01 +08:00
|
|
|
sys.exit()
|
|
|
|
|
2016-05-12 21:53:40 +08:00
|
|
|
print("installing lammps.py in Python site-packages dir")
|
2012-08-15 22:34:23 +08:00
|
|
|
|
2012-08-16 03:49:01 +08:00
|
|
|
os.chdir('../python') # in case invoked via make in src dir
|
2012-08-15 22:34:23 +08:00
|
|
|
|
2016-02-15 23:30:15 +08:00
|
|
|
# extract version string from header
|
|
|
|
fp = open('../src/version.h','r')
|
|
|
|
txt=fp.read().split('"')[1].split()
|
|
|
|
verstr=txt[0]+txt[1]+txt[2]
|
|
|
|
fp.close()
|
|
|
|
|
2012-08-16 03:49:01 +08:00
|
|
|
from distutils.core import setup
|
2016-02-15 23:30:15 +08:00
|
|
|
from distutils.sysconfig import get_python_lib
|
|
|
|
import site
|
|
|
|
tryuser=False
|
|
|
|
|
|
|
|
try:
|
|
|
|
sys.argv = ["setup.py","install"] # as if had run "python setup.py install"
|
|
|
|
setup(name = "lammps",
|
|
|
|
version = verstr,
|
|
|
|
author = "Steve Plimpton",
|
|
|
|
author_email = "sjplimp@sandia.gov",
|
|
|
|
url = "http://lammps.sandia.gov",
|
|
|
|
description = "LAMMPS molecular dynamics library",
|
|
|
|
py_modules = ["lammps"],
|
|
|
|
data_files = [(get_python_lib(), ["../src/liblammps.so"])])
|
|
|
|
except:
|
|
|
|
tryuser=True
|
2016-05-12 21:53:40 +08:00
|
|
|
print ("Installation into global site-packages dir failed.\nTrying user site dir %s now." % site.USER_SITE)
|
2016-02-15 23:30:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
if tryuser:
|
|
|
|
try:
|
|
|
|
sys.argv = ["setup.py","install","--user"] # as if had run "python setup.py install --user"
|
|
|
|
setup(name = "lammps",
|
|
|
|
version = verstr,
|
|
|
|
author = "Steve Plimpton",
|
|
|
|
author_email = "sjplimp@sandia.gov",
|
|
|
|
url = "http://lammps.sandia.gov",
|
|
|
|
description = "LAMMPS molecular dynamics library",
|
|
|
|
py_modules = ["lammps"],
|
|
|
|
data_files = [(site.USER_SITE, ["../src/liblammps.so"])])
|
|
|
|
except:
|
2016-05-12 21:53:40 +08:00
|
|
|
print("Installation into user site package dir failed.\nGo to ../python and install manually.")
|
2016-02-15 23:30:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|