91 def parse(cls, command, config, args):
93 Parse user-supplied TOML file if given and add its arguments to a CLI command.
96 parsed_command =
""; parsed_data = {}; delimn =
" ";
98 try: method = next(iter(key
for key, value
in cls.
alias().items()
if args.method[0]
in value))
99 except StopIteration: method = args.method[0]
101 if config
and args.method[-1].lower()
not in [
"-h",
"--help"]
and any(method
in Utility.PathLeaf(x)
for x
in command.split(delimn)):
102 print(
"==================================")
103 print(
"Processing info from %s" % config)
104 print(
"==================================")
109 data = tomlkit.parse(open(config).read())[
"tool"]
111 base = cls().CommandObjectKind
113 if data.get(base.lower(),{}): data = data[base.lower()].get(args.method[0],{})
116 if not data: data = tomlkit.parse(open(config).read())[
"tool"].get(args.method[0],{})
118 command = command.split(delimn)
120 index = [n
for n, x
in enumerate(command, 1)
if method
in x][0]
122 for key, value
in data.items():
124 if isinstance(value,list):
128 for x
in value: parsed_dict.update(x)
129 parsed_data[key] = parsed_dict
135 parsed_data[key] = value
137 for key, value
in parsed_data.items():
140 if os.path.isdir(os.path.normpath(value))
or os.path.isfile(os.path.normpath(value)):
141 value = os.path.normpath(value)
145 parsed_command +=
" --%s " % str(key)
146 if isinstance(value, str): parsed_command +=
"%s" % str(value)
147 if isinstance(value, list): parsed_command += delimn.join([
"'%s'" % x
for x
in value])
148 if isinstance(value, dict): parsed_command +=
"'%s'" % json.dumps(value)
150 command.insert(index,parsed_command)
152 command = delimn.join(command)
159 Return command script if verified.
162 aliases = kwargs.get(
"aliases",{v:k
for k, v
in cls.
alias().items()})
164 methods = kwargs.get(
"methods",cls.
cli()[
"methods"])
166 identifier = aliases.get(selection,selection)
167 found = [str(identifier)
in x
if len(x) == len(str(identifier))
else False for x
in list(zip(*methods))[1]]
169 if not any(found):
raise ValueError(
"Unknown CLI option %s" % str(selection))
171 path,method,ext = [methods[i]
for i,x
in enumerate(found)
if x][0]
173 script = os.path.join(path,
".".join([str(method),ext]))
178 def run(cls, namespace=None, **kwargs):
180 Execute command line parser for VTL module.
183 def __cli(namespace, **kwargs):
185 CLI parser for VTL module.
189 script = cls.
verify(namespace)
191 if not script.endswith(
".py"):
raise ValueError
193 argv =
" ".join(sys.argv).split(namespace,1)[1].split()
194 commands.append(
" ".join([sys.executable,script]+argv))
197 def __cmd(namespace, **kwargs):
199 CMD script execution for VTL module.
201 commands = []; script =
None
203 if Utility.GetExecutable(namespace): script = namespace
207 script = cls.
verify(namespace)
209 if Utility.GetPlatform()
in [
"linux"]: commands.append(
" ".join([
"chmod",
"u+x",script]))
211 argv =
" ".join(sys.argv).split(namespace)[1].split()
212 commands.append(
" ".join([script]+argv))
217 config = os.getenv(
"pyx_poetry_config",os.path.join(os.getcwd(),
"pyproject.toml"))
219 if not os.path.exists(config): config =
None
223 dash_index = sys.argv.index(
"--")
224 dashed_args = sys.argv[dash_index+1:]
225 sys.argv = sys.argv[:dash_index]
226 except ValueError: dashed_args = []
230 if not namespace
or (namespace
and config
and namespace
in sys.argv[-1]
and not namespace
in sys.argv[-2]):
231 parser, options = cls.
main(is_subparser=
True)
233 args, _ = parser.parse_known_args()
235 commands = [delimn.join([sys.executable,
"-m"] + args.method)]
237 if not namespace: namespace = str(args.method[0])
239 else: commands = []; options = kwargs
241 if namespace
and config:
245 if args.method[0] != args.method[-1]: args.method.pop(0)
247 if len(args.method) != 1: config =
None
251 except UnboundLocalError: config =
None
253 try: commands = __cli(namespace, **options)
255 try: commands = __cmd(namespace, **options)
256 except: commands = []
259 if not commands:
raise ValueError(
"Unknown CLI option")
261 for i, command
in enumerate(commands,1):
263 if i == len(commands):
265 if config: command = cls.
parse(command,config,args)
267 command = str(delimn.join([command]+dashed_args)).strip()
269 subprocess.call(shlex.split(command,posix=
not os.name.lower()
in [
"nt"]),stderr=sys.stderr, stdout=sys.stdout)
275 Main entrypoint of PyXMake CLI. All other subparsers are derived from here.
278 from PyXMake
import __version__
282 argument = [
"method", {
"metavar":
'namespace',
"type":str,
"nargs":argparse.REMAINDER,
"choices":options[
"choices"],
283 "help":
'An option identifier. Unknown arguments are ignored. Allowed values are: '+
', '.join(options[
"choices"]) } ]
285 base = cls().CommandObjectKind
287 parser = argparse.ArgumentParser(prog=base, description=
'CLI wrapper options for %s.' % base)
288 parser.add_argument(
'-v',
'--version', action=
'version', version=
'%(prog)s ' +
"(%s)" % __version__)
290 if not kwargs.get(
"is_subparser",
False):
292 subparsers = parser.add_subparsers(dest=
'namespace')
294 __run = subparsers.add_parser(
'run', help=
'Run a predefined CLI command.')
295 __run.add_argument(argument[0],**argument[1])
297 subparsers.add_parser(
'info', help=
'Get information about the current version of %s' % base)
299 args = parser.parse_args()
300 if args.namespace
in [
"run"]: Command.run(namespace=str(args.method[0]), **options)
301 elif args.namespace
in [
"info"]: parser.parse_args([
'--version'])
302 else: parser.print_help(sys.stdout)
307 parser.add_argument(argument[0],**argument[1])
309 return parser, options
406 Return the recommended command line during the build process for selected make operations.
408 @param: make_opt: An integer value representing the make operation.
409 @type: make_opt: integer
413 with open(os.path.join(os.getcwd(),
"build",
"CMakeCache.txt"))
as f:
414 sequential = [x.strip().split(
"=")[-1]
for x
in f.readlines()
if "sequential" in x.lower()][-1]
415 multithreading =
not Utility.GetBoolean(sequential)
416 except: multithreading =
True
419 win_java_command =
"-nologo -O3 -Qopenmp -Qauto_scalar -Qparallel -Qmkl:parallel -Qopt-matmul -fpp -DDEBUG -recursive \
420 -reentrancy:threaded -"+_format+
" -extend_source:132 -fpe:0 -heap-arrays1 -iface:cref -libs:static -threads -MT -W1 "
423 win_fortran_command =
"-nologo -O3 -QxSSE3 -Qopenmp -Qauto_scalar -Qparallel -Qmkl:parallel -Qopt-matmul -fpp -DDEBUG -recursive \
424 -reentrancy:threaded -"+_format+
" -extend_source:132 -fpe:0 -fp:precise -traceback -heap-arrays1 -iface:cref -libs:dll -threads -MD -W1"
427 win_cxx_command =
"-nologo -Os -W0 -MD -TP -EHsc -Qpar -clr:nostdlib -fp:precise -std:c++latest "
428 win_cxx_command +=
"-FI pyx_muesli_def.h "
429 win_cxx_command +=
"-FI algorithm -FI ctime "
430 win_cxx_command +=
"-FI iso646.h "
431 win_cxx_command +=
"-FI pyx_muesli_undef.h "
434 win_pyd_command =
' -DNO_APPEND_FORTRAN '
435 win_pyd_command +=
' --f90flags="-'+_format+
' -fpe:0 -fp:precise -threads -recursive -Qauto-scalar -Qopenmp -Qmkl:parallel -heap-arrays:1" '
436 win_pyd_command +=
' --opt="-O2" --arch="-QaxSSE3 /assume:nounderscore" --quiet --compiler=msvc '
439 lin_pyd_command =
'--quiet --fcompiler=intelem --opt="-O2" --f90flags="-'+_format+
' -fp-model precise -fpe0 -recursive -parallel -auto -qopenmp -qopt-matmul -mkl:parallel"'
442 lin_fortran_command =
"-fpp -qopenmp -DCLUSTER -DDEBUG -DUSE_MUESLI -fPIC -auto "
443 lin_fortran_command +=
"-mkl:parallel -extend_source -O2 -"+_format+
" -parallel -fpe0 -traceback -recursive "
444 lin_fortran_command +=
"-nostandard-realloc-lhs"
447 win_abq_command =
"ECHO import os >> %ABQ_ENV_FILE% "
448 win_abq_command +=
"&& ECHO usub_lib_dir=os.getcwd() >> %ABQ_ENV_FILE% "
449 win_abq_command +=
"&& ( "
450 win_abq_command +=
"ECHO compile_fortran=compile_fortran[:3] + ["
451 win_abq_command +=
"'/heap-arrays:1', "
452 win_abq_command +=
"'/O3', "
453 win_abq_command +=
"'/fpe:0', "
454 win_abq_command +=
"'/traceback', "
455 win_abq_command +=
"'/Qopt-matmul', "
456 win_abq_command +=
"'/threads', "
459 if not Utility.GetExecutable(
"oneapi-cli")
or multithreading:
460 win_abq_command +=
"'/MD', "
461 win_abq_command +=
"'/Qparallel', "
462 win_abq_command +=
"'/Qmkl:parallel', "
463 win_abq_command +=
"'/Qopenmp', "
464 win_abq_command +=
"'/libs:dll', "
466 win_abq_command +=
"'/Qmkl:sequential', "
482 win_abq_command +=
"] + compile_fortran[3:] ) >> %ABQ_ENV_FILE% "
483 win_abq_command +=
"&& ( "
484 if not Utility.GetExecutable(
"oneapi-cli")
or multithreading:
485 win_abq_command +=
"ECHO link_sl=link_sl[:3] + ["
487 win_abq_command +=
"r'/def:"+os.getenv(
"pyx_abaqus_def",
"%E")+
"', '/INCLUDE:_DllMainCRTStartup', '/FORCE'] + link_sl[3:] + ["
490 win_abq_command +=
"ECHO link_sl=['LINK','/NODEFAULTLIB:LIBCMT.LIB','/FORCE','/dll','/def:%E','/out:%U','%F','%A','%L','%B',"
493 win_abq_command +=
"%pyx_libs%] ) >> %ABQ_ENV_FILE% "
494 win_abq_command +=
'&& %pyx_abaqus% make -library %pyx_file%'
496 lin_per_command =
"";
498 lin_per_command +=
'if [ -z ${HOME+x} ]; then : ; else HOME=${PWD};fi; '
500 lin_per_command +=
"WorkDir=$PWD;"
501 lin_per_command +=
"ZipArchive='peridigm.zip';"
503 lin_per_command +=
'TempDir=$HOME/"${ZipArchive%.*}"/;'
505 lin_per_command +=
"builddir='build'; srcdir='src';"
507 lin_per_command +=
"file_cmake='cmake.cmake';"
508 lin_per_command +=
"file_cmake_log='cmake.log';"
509 lin_per_command +=
"file_make_log='make.log';"
510 lin_per_command +=
"file_make_install_log='make_install.log';"
511 lin_per_command +=
"file_peridigm_bin='Peridigm';"
513 lin_per_command +=
"make_cpus=$((`nproc`+1));"
515 lin_per_command +=
"if [ -d ${TempDir} ]; then"
516 lin_per_command +=
" echo 'Directory '${TempDir}' already exists. Exit.';"
517 lin_per_command +=
" exit 0;"
518 lin_per_command +=
"fi;"
520 lin_per_command +=
"mkdir ${TempDir};"
521 lin_per_command +=
"cd ${TempDir};"
522 lin_per_command +=
"mkdir ${builddir};"
523 lin_per_command +=
"mkdir ${srcdir};"
524 lin_per_command +=
"cd ${srcdir};"
526 lin_per_command +=
"unzip -q ../../${ZipArchive} -d . &&"
527 lin_per_command +=
"mv peridigm-master peridigm 2>/dev/null &&"
528 lin_per_command +=
"cd ../${builddir};"
529 lin_per_command +=
"cd $WorkDir;"
530 lin_per_command+=
"mv $ZipArchive $TempDir/ &&"
531 lin_per_command +=
"cd $TempDir/$builddir;"
533 lin_per_command +=
"echo 'rm -f CMakeCache.txt' >> ${file_cmake};"
534 lin_per_command +=
"echo 'rm -rf CMakeFiles/' >> ${file_cmake};"
535 lin_per_command +=
"echo '' >> ${file_cmake};"
536 lin_per_command +=
r"echo 'cmake \' >> ${file_cmake};"
537 lin_per_command +=
r"echo '-D USE_MCODAC:BOOL=TRUE \' >> ${file_cmake};"
538 lin_per_command +=
r"echo '-D MESH_CONVERTER_DIR:STRING=mesh_converter \' >> ${file_cmake};"
539 lin_per_command +=
r"echo '-D CMAKE_BUILD_TYPE:STRING=Release \' >> ${file_cmake};"
540 lin_per_command +=
r"echo '-D CMAKE_INSTALL_PREFIX='${TempDir}${builddir}' \' >> ${file_cmake};"
541 lin_per_command +=
r"echo '-D CMAKE_CXX_COMPILER:STRING="+
'"mpicxx"'+
r" \' >> ${file_cmake};"
542 lin_per_command+=
"echo '-D CMAKE_CXX_FLAGS:STRING="+
'"-DUSE_MCODAC -O2 -Wall -std=c++11 -pedantic -Wno-long-long -ftrapv -Wno-deprecated"'+
r" \' >> ${file_cmake};"
543 lin_per_command+=
"echo '-D CMAKE_EXE_LINKER_FLAGS:STRING="+
'"${pyx_per_linking:--L${HOME}/mcodac/bin -lperuser}"'+
r" \' >> ${file_cmake};"
544 lin_per_command +=
"echo ${TempDir}${srcdir}'/peridigm/' >> ${file_cmake};"
546 lin_per_command +=
"chmod u+x ${file_cmake};"
547 lin_per_command +=
"./${file_cmake} > ${file_cmake_log} 2>&1;"
549 lin_per_command +=
"make -j ${make_cpus} > ${file_make_log} 2>&1;"
550 lin_per_command +=
"make install > ${file_make_install_log} 2>&1;"
552 lin_per_command +=
"cd bin;"
553 lin_per_command +=
"cp ${file_peridigm_bin} ${pyx_per_output:-${HOME}}/${file_peridigm_bin};"
554 lin_per_command +=
"cd $WorkDir;"
555 lin_per_command +=
"rm -rf $TempDir;"
557 lin_tri_command =
"";
558 lin_tri_command +=
"cmake "
559 lin_tri_command +=
"-DTPL_LAPACK_LIBRARIES='/sw/MPI/GCC/8.2.0-2.31.1/OpenMPI/3.1.3/ScaLAPACK/2.0.2-OpenBLAS-0.3.5/lib/liblapack.a' "
560 lin_tri_command +=
"-DTPL_ENABLE_HDF5:BOOL=ON -DTPL_ENABLE_Matio=OFF "
561 lin_tri_command +=
"-DTPL_ENABLE_MPI=ON -DTrilinos_ENABLE_ALL_PACKAGES=ON "
562 lin_tri_command +=
"-DCMAKE_INSTALL_PREFIX=/home/garb_ma/mcodac/external/trilinos /home/garb_ma/trilinos"
567 win_pyd_command +=
" --fcompiler=intelv"
569 elif (
'x64' in _arch):
571 win_pyd_command +=
" --fcompiler=intelvem"
574 command = win_pyd_command
576 command = win_java_command
578 command = win_fortran_command
580 command = win_cxx_command
582 command = lin_pyd_command
584 command = lin_fortran_command
587 command = win_abq_command
589 command = lin_per_command
591 raise NotImplementedError
597 Return all mandatory include directories for the requested make operation in dependence of key_opt.
599 @param: key_opt, make_opt: [An integer value representing the source code file (e.g. MCODAC, BoxBeam, BEOS),
600 An integer value representing the make operation.]
601 @type: key_opt, make_opt: integer
604 if key_opt == 0
and make_opt
in range(6):
606 inc = list(Utility.PathWalk(os.path.join(base_path,
"include",Utility.GetPlatform(),architecture), startswith=(
".",
"__")))[0][1]
611 if os.path.exists(base_path):
612 sys.path.append(base_path)
618 __occ_name = OCC.__name__
620 __occ_src_path = OCC.__path__[0]
623 __occ_name =
""; __occ_src_path =
""
628 __pyc_name = PyCODAC.__name__
630 __pyc_src_path = PyCODAC.PyCODACPath
633 __pyc_name =
""; __pyc_src_path =
""
636 inc = [
"six.py",
"ipykernel_launcher.py",
638 os.path.join(__pyc_name,
"__init__.py"),
639 os.path.join(__pyc_name,
"Paths.log"),
640 os.path.join(__pyc_name,
"Tools",
"__init__.py"),
641 os.path.join(__pyc_name,
"Tools",
"Utility.py"),
642 os.path.join(__pyc_name,
"Core",
"cmd"),
644 os.path.join(__pyc_name,
"Core",
"bin",Utility.GetPlatform(),architecture),
645 os.path.join(__pyc_name,
"Study",
"bin",architecture),
646 os.path.join(__pyc_name,
"Study",
"cmd",Utility.GetPlatform()),
648 os.path.join(__pyc_name,
"Database"),
650 os.path.join(__pyc_name,
"Plugin",
"JupyterLab",
"bin", Utility.GetPlatform()),
651 os.path.pathsep.join([os.path.join(__pyc_src_path,
"Plugin",
"JupyterLab",
"config",
"jupyter_notebook_utils.py"),
"."]),
652 os.path.pathsep.join([os.path.join(__pyc_src_path,
"Plugin",
"JupyterLab",
"config"),os.path.join(__pyc_name,
"Plugin",
"JupyterLab",
"config",
".")]),
654 os.path.join(__pyc_name,
"Plugin",
"Smetana",
"config",
"pyc_smetana.config"),
656 os.path.pathsep.join([os.path.join(__pyc_src_path,
"GUI",
"res",
"pyc_lab_icon.png"), os.path.join(__pyc_name,
"GUI",
"res",
".")]),
657 os.path.pathsep.join([os.path.join(__pyc_src_path,
"GUI",
"res",
"pyc_dic_analysis.png"),os.path.join(__pyc_name,
"GUI",
"res",
".")]),
658 os.path.pathsep.join([os.path.join(__pyc_src_path,
"GUI",
"res",
"stmlab_icon.png"), os.path.join(__pyc_name,
"GUI",
"res",
".")]),
659 os.path.pathsep.join([os.path.join(__pyc_src_path,
"GUI",
"res",
"stm_main.png"),os.path.join(__pyc_name,
"GUI",
"res",
".")]),
660 os.path.pathsep.join([os.path.join(__pyc_src_path,
"GUI",
"res",
"stm_lightweight.png"),os.path.join(__pyc_name,
"GUI",
"res",
".")]),
661 os.path.pathsep.join([os.path.join(__pyc_src_path,
"GUI",
"res",
"stm_vph.png"), os.path.join(__pyc_name,
"GUI",
"res",
".")])]
664 if os.path.exists(__occ_src_path): inc.insert(3,os.path.pathsep.join([__occ_src_path,os.path.join(__occ_name,
".")]))
668 from PyCODAC
import __hook__
670 imported = set([x
for x
in dir(__hook__)
if not x.startswith(
"_")]) - set(dir(__builtins__)) - set([
"PyCODAC",
"PyXMake"])
671 data = [importlib.import_module(x)
for x
in imported]
672 inc.extend([os.path.pathsep.join([os.path.dirname(x.__file__),os.path.join(x.__name__,
".")])
if x.__file__.endswith(
"__init__.py")
else Utility.PathLeaf(x.__file__)
for x
in data])
674 dist_search_paths = set([os.path.abspath(os.path.join(x.__file__, os.path.pardir, os.path.pardir))
if x.__file__.endswith(
"__init__.py")
else os.path.abspath(os.path.join(x.__file__, os.path.pardir))
for x
in data])
675 inc.extend([os.path.pathsep.join([os.path.join(path,Utility.PathLeaf(y)),os.path.join(Utility.PathLeaf(y),
".")])
for path
in dist_search_paths
for y
in os.listdir(path)
for found
in data
if y.startswith(found.__name__)
and y.endswith(
".dist-info")])
676 except Exception
as _:
pass