add some comments to the refactored scripts to explain technical details

This commit is contained in:
Axel Kohlmeyer
2022-02-25 20:10:13 -05:00
parent 1dbff92eeb
commit 7fd41bea6a
2 changed files with 24 additions and 5 deletions

View File

@ -10,8 +10,6 @@ in the GNU make and CMake based build systems. Can also be called
independently and used to build the wheel without installing it. independently and used to build the wheel without installing it.
""" """
# copy LAMMPS shared library and lammps package to system dirs
from __future__ import print_function from __future__ import print_function
import sys,os,shutil,time,glob,subprocess import sys,os,shutil,time,glob,subprocess
from argparse import ArgumentParser from argparse import ArgumentParser
@ -50,22 +48,28 @@ if args.lib:
olddir = os.path.abspath('.') olddir = os.path.abspath('.')
os.chdir(os.path.dirname(args.package)) os.chdir(os.path.dirname(args.package))
# remove any wheel files left over from previous calls
print("Purging existing wheels...") print("Purging existing wheels...")
for wheel in glob.glob('lammps-*.whl'): for wheel in glob.glob('lammps-*.whl'):
print("deleting " + wheel) print("deleting " + wheel)
os.remove(wheel) os.remove(wheel)
# create virtual environment for building the wheel # copy shared object to the current folder so that
shutil.rmtree('buildwheel',True) # it will show up in the installation at the expected location
os.putenv('LAMMPS_SHARED_LIB',args.lib) os.putenv('LAMMPS_SHARED_LIB',args.lib)
#os.environ['LAMMPS_SHARED_LIB'] = args.lib
shutil.copy(args.lib,'lammps') shutil.copy(args.lib,'lammps')
# create a virtual environment for building the wheel
shutil.rmtree('buildwheel',True)
try: try:
txt = subprocess.check_output([sys.executable, '-m', 'virtualenv', 'buildwheel', '-p', sys.executable], stderr=subprocess.STDOUT, shell=False) txt = subprocess.check_output([sys.executable, '-m', 'virtualenv', 'buildwheel', '-p', sys.executable], stderr=subprocess.STDOUT, shell=False)
print(txt.decode('UTF-8')) print(txt.decode('UTF-8'))
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
sys.exit("Failed to create a virtualenv: {0}".format(err.output.decode('UTF-8'))) sys.exit("Failed to create a virtualenv: {0}".format(err.output.decode('UTF-8')))
# now run the commands to build the wheel. those must be in a separate script
# and run in subprocess, since this will use the virtual environment and
# there is no simple way to return from that in python.
os.system(sys.executable + ' makewheel.py') os.system(sys.executable + ' makewheel.py')
# remove temporary folders and files # remove temporary folders and files
@ -74,9 +78,21 @@ shutil.rmtree('build',True)
shutil.rmtree('lammps.egg-info',True) shutil.rmtree('lammps.egg-info',True)
os.remove(os.path.join('lammps',os.path.basename(args.lib))) os.remove(os.path.join('lammps',os.path.basename(args.lib)))
# stop here if we were asked not to install the wheel we created
if args.noinstall: if args.noinstall:
exit(0) exit(0)
# install the wheel with pip. first try to install in the default environment.
# that will be a virtual environment, if active, or the system folder.
# recent versions of pip will automatically drop to use the user folder
# in case the system folder is not writable.
# we use a subprocess so we can catch an exception on failure.
# we need to check whether pip refused to install because of a
# version of the module previously installed with distutils. those
# must be uninstalled manually. We must not ignore this and drop
# back to install into a (forced) user folder.
print("Installing wheel") print("Installing wheel")
for wheel in glob.glob('lammps-*.whl'): for wheel in glob.glob('lammps-*.whl'):
try: try:

View File

@ -2,6 +2,7 @@
import sys,os,shutil import sys,os,shutil
# find python script to activate the virtual environment and source it
if sys.platform == 'win32': if sys.platform == 'win32':
virtenv=os.path.join('buildwheel','Scripts','activate_this.py') virtenv=os.path.join('buildwheel','Scripts','activate_this.py')
else: else:
@ -9,7 +10,9 @@ else:
exec(open(virtenv).read(), {'__file__': virtenv}) exec(open(virtenv).read(), {'__file__': virtenv})
# update pip and install all requirements to build the wheel
os.system('python -m pip install --upgrade pip') os.system('python -m pip install --upgrade pip')
os.system('python -m pip install --upgrade -r wheel_requirements.txt') os.system('python -m pip install --upgrade -r wheel_requirements.txt')
print("Building new binary wheel") print("Building new binary wheel")
os.system('python -m build -n --wheel -o .') os.system('python -m build -n --wheel -o .')