add check to lammps python module to check consistent versions between module and shared library
This commit is contained in:
@ -10,7 +10,7 @@ build target in the conventional and CMake based build systems
|
|||||||
# copy LAMMPS shared library and lammps package to system dirs
|
# copy LAMMPS shared library and lammps package to system dirs
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,shutil
|
import sys,os,re,shutil
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
parser = ArgumentParser(prog='install.py',
|
parser = ArgumentParser(prog='install.py',
|
||||||
@ -90,11 +90,35 @@ def get_lammps_version(header):
|
|||||||
|
|
||||||
verstr = get_lammps_version(args.version)
|
verstr = get_lammps_version(args.version)
|
||||||
|
|
||||||
|
# convert string version to numeric version
|
||||||
|
vernum = 0
|
||||||
|
vregex = re.compile(r"([0-9]+)([A-Za-z]+)(2[0-9]+)")
|
||||||
|
m = vregex.match(verstr)
|
||||||
|
if (m):
|
||||||
|
month2num = { 'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'May' : 5, 'Jun' : 6,
|
||||||
|
'Jul' : 7, 'Aug' : 8, 'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12 }
|
||||||
|
try:
|
||||||
|
vernum = int(m.group(3))*10000
|
||||||
|
vernum += month2num[m.group(2)]*100
|
||||||
|
vernum += int(m.group(1))
|
||||||
|
except:
|
||||||
|
exit('Failure to parse version string: %s' % verstr)
|
||||||
|
|
||||||
print("Installing LAMMPS Python package version %s into site-packages folder" % verstr)
|
print("Installing LAMMPS Python package version %s into site-packages folder" % verstr)
|
||||||
|
|
||||||
# we need to switch to the folder of the python package
|
# we need to switch to the folder of the python package
|
||||||
os.chdir(os.path.dirname(args.package))
|
os.chdir(os.path.dirname(args.package))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# update version number in lammps module
|
||||||
|
vregex = re.compile(r".*(__version__ += +)[0-9]+")
|
||||||
|
with open(os.path.join('lammps','__init__.py'), "r+") as f:
|
||||||
|
content = f.read()
|
||||||
|
f.seek(0)
|
||||||
|
f.write(re.sub(vregex, lambda match: '{}{}'.format(match.group(1), vernum), content))
|
||||||
|
f.truncate()
|
||||||
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
from distutils.sysconfig import get_python_lib
|
from distutils.sysconfig import get_python_lib
|
||||||
import site
|
import site
|
||||||
|
|||||||
@ -2,3 +2,7 @@ from .constants import *
|
|||||||
from .core import *
|
from .core import *
|
||||||
from .data import *
|
from .data import *
|
||||||
from .pylammps import *
|
from .pylammps import *
|
||||||
|
|
||||||
|
# automatically updated during installation
|
||||||
|
|
||||||
|
__version__ = 20201224
|
||||||
|
|||||||
@ -381,6 +381,12 @@ class lammps(object):
|
|||||||
self._installed_packages = None
|
self._installed_packages = None
|
||||||
self._available_styles = None
|
self._available_styles = None
|
||||||
|
|
||||||
|
# check if liblammps version matches the installed python module version
|
||||||
|
import lammps
|
||||||
|
if lammps.__version__ != self.lib.lammps_version(self.lmp):
|
||||||
|
raise(AttributeError("LAMMPS Python module installed for LAMMPS version %d, but shared library is version %d" \
|
||||||
|
% (lammps.__version__, self.lib.lammps_version(self.lmp))))
|
||||||
|
|
||||||
# add way to insert Python callback for fix external
|
# add way to insert Python callback for fix external
|
||||||
self.callback = {}
|
self.callback = {}
|
||||||
self.FIX_EXTERNAL_CALLBACK_FUNC = CFUNCTYPE(None, py_object, self.c_bigint, c_int, POINTER(self.c_tagint), POINTER(POINTER(c_double)), POINTER(POINTER(c_double)))
|
self.FIX_EXTERNAL_CALLBACK_FUNC = CFUNCTYPE(None, py_object, self.c_bigint, c_int, POINTER(self.c_tagint), POINTER(POINTER(c_double)), POINTER(POINTER(c_double)))
|
||||||
|
|||||||
Reference in New Issue
Block a user