|
|
|
|
@ -25,6 +25,8 @@ parser.add_argument("-n", "--noinstall", action="store_true", default=False,
|
|
|
|
|
help="only build a binary wheel. Don't attempt to install it")
|
|
|
|
|
parser.add_argument("-w", "--wheeldir", required=False,
|
|
|
|
|
help="path to a directory where the created wheel will be stored")
|
|
|
|
|
parser.add_argument("-v", "--versionfile", required=True,
|
|
|
|
|
help="path to the LAMMPS version.h source file")
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
@ -32,7 +34,7 @@ args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
if args.package:
|
|
|
|
|
if not os.path.exists(args.package):
|
|
|
|
|
print("ERROR: LAMMPS package %s does not exist" % args.package)
|
|
|
|
|
print("ERROR: LAMMPS package folder %s does not exist" % args.package)
|
|
|
|
|
parser.print_help()
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
else:
|
|
|
|
|
@ -54,19 +56,32 @@ if args.wheeldir:
|
|
|
|
|
else:
|
|
|
|
|
args.wheeldir = os.path.abspath(args.wheeldir)
|
|
|
|
|
|
|
|
|
|
# we need to switch to the folder of the python package
|
|
|
|
|
if args.versionfile:
|
|
|
|
|
if not os.path.exists(args.versionfile):
|
|
|
|
|
print("ERROR: LAMMPS version file at %s does not exist" % args.versionfile)
|
|
|
|
|
parser.print_help()
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
else:
|
|
|
|
|
args.versionfile = os.path.abspath(args.versionfile)
|
|
|
|
|
|
|
|
|
|
olddir = os.path.abspath('.')
|
|
|
|
|
os.chdir(os.path.dirname(args.package))
|
|
|
|
|
pythondir = os.path.abspath(os.path.join(args.package,'..'))
|
|
|
|
|
os.putenv('LAMMPS_VERSION_FILE',os.path.abspath(args.versionfile))
|
|
|
|
|
|
|
|
|
|
# remove any wheel files left over from previous calls
|
|
|
|
|
if os.path.isdir(os.path.join(olddir,"build")):
|
|
|
|
|
# purge old build folder
|
|
|
|
|
if os.path.isdir(os.path.join(olddir, 'build-python')):
|
|
|
|
|
print("Cleaning old build directory")
|
|
|
|
|
shutil.rmtree(os.path.join(olddir,"build"))
|
|
|
|
|
shutil.rmtree(os.path.join(olddir, 'build-python'))
|
|
|
|
|
|
|
|
|
|
#print("Purging existing wheels...")
|
|
|
|
|
#for wheel in glob.glob('lammps-*.whl'):
|
|
|
|
|
# print("deleting " + wheel)
|
|
|
|
|
# os.remove(wheel)
|
|
|
|
|
# remove any old wheel files left over from previous calls
|
|
|
|
|
print("Purging existing wheels...")
|
|
|
|
|
for wheel in glob.glob('lammps-*.whl'):
|
|
|
|
|
print("deleting " + wheel)
|
|
|
|
|
os.remove(wheel)
|
|
|
|
|
|
|
|
|
|
# copy python tree to build folder
|
|
|
|
|
builddir = shutil.copytree(pythondir, os.path.join(olddir, 'build-python'))
|
|
|
|
|
os.chdir(builddir)
|
|
|
|
|
|
|
|
|
|
# copy shared object to the current folder so that
|
|
|
|
|
# it will show up in the installation at the expected location
|
|
|
|
|
@ -74,7 +89,7 @@ os.putenv('LAMMPS_SHARED_LIB',os.path.basename(args.lib))
|
|
|
|
|
shutil.copy(args.lib,'lammps')
|
|
|
|
|
|
|
|
|
|
# create a virtual environment for building the wheel
|
|
|
|
|
shutil.rmtree('buildwheel',True)
|
|
|
|
|
shutil.rmtree('buildwheel', True)
|
|
|
|
|
try:
|
|
|
|
|
txt = subprocess.check_output([sys.executable, '-m', 'venv', 'buildwheel'], stderr=subprocess.STDOUT, shell=False)
|
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
|
@ -86,18 +101,19 @@ except subprocess.CalledProcessError as err:
|
|
|
|
|
# there is no simple way to return from that in python.
|
|
|
|
|
os.system(sys.executable + ' makewheel.py')
|
|
|
|
|
|
|
|
|
|
# copy wheel to final location
|
|
|
|
|
for wheel in glob.glob('lammps-*.whl'):
|
|
|
|
|
if args.wheeldir:
|
|
|
|
|
shutil.copy(wheel, args.wheeldir)
|
|
|
|
|
|
|
|
|
|
print('wheel = ', wheel)
|
|
|
|
|
|
|
|
|
|
# remove temporary folders and files
|
|
|
|
|
shutil.rmtree('buildwheel',True)
|
|
|
|
|
shutil.rmtree('build',True)
|
|
|
|
|
shutil.rmtree('lammps.egg-info',True)
|
|
|
|
|
os.remove(os.path.join('lammps',os.path.basename(args.lib)))
|
|
|
|
|
os.chdir(olddir)
|
|
|
|
|
shutil.rmtree('build-python',True)
|
|
|
|
|
|
|
|
|
|
# stop here if we were asked not to install the wheel we created
|
|
|
|
|
if args.noinstall:
|
|
|
|
|
if args.wheeldir:
|
|
|
|
|
for wheel in glob.glob('lammps-*.whl'):
|
|
|
|
|
shutil.copy(wheel, args.wheeldir)
|
|
|
|
|
os.remove(wheel)
|
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
# install the wheel with pip. first try to install in the default environment.
|
|
|
|
|
@ -122,28 +138,17 @@ else:
|
|
|
|
|
print("Installing wheel into system site-packages folder")
|
|
|
|
|
py_exe = sys.executable
|
|
|
|
|
|
|
|
|
|
for wheel in glob.glob('lammps-*.whl'):
|
|
|
|
|
try:
|
|
|
|
|
txt = subprocess.check_output([py_exe, '-m', 'pip', 'install', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
|
if args.wheeldir:
|
|
|
|
|
shutil.copy(wheel, args.wheeldir)
|
|
|
|
|
else:
|
|
|
|
|
shutil.copy(wheel, olddir)
|
|
|
|
|
os.remove(wheel)
|
|
|
|
|
continue
|
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
|
errmsg = err.output.decode('UTF-8')
|
|
|
|
|
if errmsg.find("distutils installed"):
|
|
|
|
|
sys.exit(errmsg + "You need to uninstall the LAMMPS python module manually first.\n")
|
|
|
|
|
try:
|
|
|
|
|
print('Installing wheel into system site-packages folder failed. Trying user folder now')
|
|
|
|
|
txt = subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--user', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
|
if args.wheeldir:
|
|
|
|
|
shutil.copy(wheel, args.wheeldir)
|
|
|
|
|
else:
|
|
|
|
|
shutil.copy(wheel, olddir)
|
|
|
|
|
os.remove(wheel)
|
|
|
|
|
except:
|
|
|
|
|
sys.exit('Failed to install wheel ' + wheel)
|
|
|
|
|
try:
|
|
|
|
|
txt = subprocess.check_output([py_exe, '-m', 'pip', 'install', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
|
errmsg = err.output.decode('UTF-8')
|
|
|
|
|
if errmsg.find("distutils installed"):
|
|
|
|
|
sys.exit(errmsg + "You need to uninstall the LAMMPS python module manually first.\n")
|
|
|
|
|
try:
|
|
|
|
|
print('Installing wheel into system site-packages folder failed. Trying user folder now')
|
|
|
|
|
txt = subprocess.check_output([sys.executable, '-m', 'pip', 'install', '--user', '--force-reinstall', wheel], stderr=subprocess.STDOUT, shell=False)
|
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
|
except:
|
|
|
|
|
sys.exit('Failed to install wheel ' + wheel)
|
|
|
|
|
|