move the created wheel to the build folder at the end
This commit is contained in:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user