import sys
import os
from pysrc import genutil
def fatal(m):
sys.stderr.write("\n\nXED build error: %s\n\n" % (m) )
sys.exit(1)
def try_mbuild_import():
try:
import mbuild
return True
except:
return False
def find_mbuild_import():
if try_mbuild_import():
return
script_name = sys.argv[0]
mbuild_install_path_derived = \
os.path.join(os.path.dirname(script_name), '..', 'mbuild')
mbuild_install_path_relative = genutil.find_dir('mbuild')
mbuild_install_path = mbuild_install_path_derived
if not os.path.exists(mbuild_install_path):
if not mbuild_install_path_relative:
mbuild_install_path_relative=''
mbuild_install_path = mbuild_install_path_relative
if not os.path.exists(mbuild_install_path):
s = "mfile.py cannot find the mbuild directory: [%s] or [%s]"
fatal(s % (mbuild_install_path_derived,
mbuild_install_path_relative))
if 'PYTHONPATH' in os.environ:
sep = os.pathsep
os.environ['PYTHONPATH'] = mbuild_install_path + sep + \
os.environ['PYTHONPATH']
else:
os.environ['PYTHONPATH'] = mbuild_install_path
sys.path.insert(0,mbuild_install_path)
def work():
if sys.version_info[0] == 3:
if sys.version_info[1] < 8:
fatal("Need python version 3.8 or later.")
else:
fatal("Need python version 3.8 or later.")
try:
find_mbuild_import()
except:
fatal("mbuild import failed")
import xed_mbuild
import xed_build_common
try:
retval = xed_mbuild.execute()
except Exception as e:
xed_build_common.handle_exception_and_die(e)
return retval
if __name__ == "__main__":
retval = work()
sys.exit(retval)