move the created wheel to the build folder at the end

This commit is contained in:
Axel Kohlmeyer
2022-06-17 08:05:28 -04:00
parent 18f9e5836b
commit deac9f05b1
3 changed files with 33 additions and 9 deletions

View File

@ -786,14 +786,16 @@ if(BUILD_SHARED_LIBS)
find_package(Python COMPONENTS Interpreter)
endif()
if(BUILD_IS_MULTI_CONFIG)
set(LIBLAMMPS_SHARED_BINARY ${CMAKE_BINARY_DIR}/$<CONFIG>/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(MY_BUILD_DIR ${CMAKE_BINARY_DIR}/$<CONFIG>)
else()
set(LIBLAMMPS_SHARED_BINARY ${CMAKE_BINARY_DIR}/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(MY_BUILD_DIR ${CMAKE_BINARY_DIR})
endif()
set(LIBLAMMPS_SHARED_BINARY ${MY_BUILD_DIR}/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX})
if(Python_EXECUTABLE)
add_custom_target(
install-python ${CMAKE_COMMAND} -E remove_directory build
COMMAND ${Python_EXECUTABLE} ${LAMMPS_PYTHON_DIR}/install.py -p ${LAMMPS_PYTHON_DIR}/lammps -l ${LIBLAMMPS_SHARED_BINARY}
COMMAND ${Python_EXECUTABLE} ${LAMMPS_PYTHON_DIR}/install.py -p ${LAMMPS_PYTHON_DIR}/lammps
-l ${LIBLAMMPS_SHARED_BINARY} -w ${MY_BUILD_DIR}
COMMENT "Installing LAMMPS Python module")
else()
add_custom_target(

View File

@ -23,6 +23,8 @@ parser.add_argument("-l", "--lib", required=True,
help="path to the compiled LAMMPS shared library")
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")
args = parser.parse_args()
@ -30,7 +32,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 %s does not exist" % args.package)
parser.print_help()
sys.exit(1)
else:
@ -38,12 +40,20 @@ if args.package:
if args.lib:
if not os.path.exists(args.lib):
print( "ERROR: LAMMPS shared library %s does not exist" % args.lib)
print("ERROR: LAMMPS shared library %s does not exist" % args.lib)
parser.print_help()
sys.exit(1)
else:
args.lib = os.path.abspath(args.lib)
if args.wheeldir:
if not os.path.exists(args.wheeldir):
print("ERROR: directory %s to store the wheel does not exist" % args.wheeldir)
parser.print_help()
sys.exit(1)
else:
args.wheeldir = os.path.abspath(args.wheeldir)
# we need to switch to the folder of the python package
olddir = os.path.abspath('.')
os.chdir(os.path.dirname(args.package))
@ -80,7 +90,11 @@ 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:
exit(0)
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.
# that will be a virtual environment, if active, or the system folder.
@ -108,6 +122,11 @@ 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')
@ -117,7 +136,10 @@ for wheel in glob.glob('lammps-*.whl'):
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)
shutil.copy(wheel, olddir)
os.remove(wheel)

View File

@ -461,7 +461,7 @@ mpi-stubs:
sinclude ../lib/python/Makefile.lammps
install-python:
@rm -rf ../python/build
@$(PYTHON) ../python/install.py -p ../python/lammps -l ../src/liblammps.so
@$(PYTHON) ../python/install.py -p ../python/lammps -l ../src/liblammps.so -w $(PWD)
# Create a tarball of src dir and packages