6 Create a make object to define the building environment and to execute the 7 build commands. The make event is subdivided in a pre-, main- and a post-build 14 ---------------------------------------------------------------------------------------------- 21 @author: garb_ma [DLR-FA,STM Braunschweig] 22 ---------------------------------------------------------------------------------------------- 34 from builtins
import object
38 import sys, os, platform
51 from shutil
import copyfile
52 from types
import MethodType
53 from collections
import OrderedDict
54 from PIL
import ImageColor
56 from ..Tools
import Utility
59 PyXMakePath = Utility.GetPyXMakePath()
61 Path2Config = os.path.join(PyXMakePath,
"Build",
"config")
66 @six.add_metaclass(abc.ABCMeta)
69 Parent class for all make objects. 72 def __init__(self, BuildID, Srcs, scratch=os.getcwd(), msvsc=
'vs2015', stype=
'Fortran', verbose=0, *args, **kwargs):
74 Low-level initialization of parent class. 82 self.
srcs.append(Srcs)
83 self.
srcs = list(Utility.ArbitraryFlattening(self.
srcs))
93 with Utility.ChangedWorkingDirectory(scratch):
102 with open(os.path.join(PyXMakePath,
'Paths.log'))
as f:
103 content = f.readlines()
104 content = [x.strip()
for x
in content]
126 self.
setarch =
True if kwargs.get(
'arch',
None)
in [
'x86',
'x64']
else False 129 if 'win' in sys.platform:
131 if ((
'32bit' in platform.architecture()
and not self.
setarch)
or (self.
setarch and kwargs.get(
'arch',
None) ==
"x86")):
133 os.environ[
'pyx_proc'] =
'x86' 134 os.environ[
'pyx_intel'] =
'ia32' 138 elif ((
'64bit' in platform.architecture()
and not self.
setarch)
or (self.
setarch and kwargs.get(
'arch',
None) ==
"x64")):
140 os.environ[
'pyx_proc'] =
'amd64' 141 os.environ[
'pyx_intel'] =
'intel64' 145 self.
iniCompiler =
r'"'+os.path.join(PyXMakePath,
"Build",
"cmd",
"windows",
"iniCompiler.bat")+
'"' 147 elif 'linux' in sys.platform:
148 raise NotImplementedError
152 os.environ[
'pyx_msvsc'] = self.
msvsc 159 mkl_include_path = os.path.join(self.
intelpath,
"mkl",
"include")
160 mkl_lib_path = os.path.join(self.
intelpath,
"mkl",
"lib",os.environ[
'pyx_intel'])
161 mkl_compiler_path = os.path.join(self.
intelpath,
"compiler",
"lib",os.environ[
'pyx_intel'])
163 self.
incdirs.append(mkl_include_path)
164 self.
libdirs.extend([mkl_lib_path, mkl_compiler_path])
167 os.environ[
"PATH"] =
";".join([os.getenv(
"PATH",
""),os.path.join(self.
intelpath,
"bin",os.environ[
'pyx_intel'])])
175 Prepare the object for pickling (2to3 compatible) 177 _dictobj = Utility.PrepareObjectforPickling(self)
182 Recover a dictionary from pickling (2to3 compatible) 184 _dictobj = Utility.RecoverDictionaryfromPickling(_dict)
185 self.__dict__.update(_dictobj)
190 Define additional include directories containing modules or source files as comma separated list. 198 Define additional directories containing 3rd party libraries as comma separated list. 200 self.
libdirs.append(dependencies)
206 Define which non-default libraries should be used during linking. 208 self.
libs.append(libs)
209 self.
libs = list(Utility.ArbitraryFlattening(self.
libs))
214 Define a new source directory. Input is read from workspace by default. 221 Define a new output directory. Output is written to the workspace by default. 231 Load an additional environment file prior to execution of all commands. 234 os.environ[
'pyx_environment'] = os.path.join(path,script)
235 if path.rsplit(
"\\",1)[1] ==
"bin":
236 self.
intelpath = path[::-1].replace(
"bin"[::-1],
"",1)[::-1]
242 if all(x
in inc
for x
in [
"mkl",
"include"]):
247 if all(x
in lib
for x
in [
"mkl",
"lib"])
or all(x
in lib
for x
in [
"compiler",
"lib"]):
251 mkl_include_path = os.path.join(self.
intelpath,
"mkl",
"include")
252 mkl_lib_path = os.path.join(self.
intelpath,
"mkl",
"lib",os.environ[
'pyx_intel'])
253 mkl_compiler_path = os.path.join(self.
intelpath,
"compiler",
"lib",os.environ[
'pyx_intel'])
255 self.
incdirs.append(mkl_include_path)
256 self.
libdirs.extend([mkl_lib_path, mkl_compiler_path])
259 def Preprocessing(self, cmdstring='', inend='', outend='', copyfiles=[],
260 replace = {'!DEC$ IF':
'#IF',
'!DEC$ ELSE':
'#ELSE',
'!DEC$ ENDIF':
'#ENDIF'}):
262 Assemble command string for the pre-build event. 265 if not Utility.IsNotEmpty(os.path.splitext(self.
buildname)[1]):
269 with Utility.ChangedWorkingDirectory(self.
scrtdir):
271 collsrcfile = Utility.GetTemporaryFileName(filename=
"coll" +
"_", extension=inend)
272 presrcfile = Utility.GetTemporaryFileName(filename=
"pre",extension=outend)
275 search_dir = [self.
srcdir]
277 search_dir.extend(self.
incdirs)
283 for subdir
in search_dir:
284 src_files = os.listdir(subdir)
285 file_names = [x
for x
in src_files
if x
in copyfiles]
286 for inputfile
in file_names:
287 full_file_name = os.path.join(subdir, inputfile)
288 if (os.path.isfile(full_file_name)):
289 shutil.copy(full_file_name, os.getcwd())
298 Utility.ConcatenateFiles(collsrcfile, self.
srcs, self.
srcdir, ending=inend)
301 Utility.ReplaceTextinFile(collsrcfile, presrcfile, replace, source=self.
scrtdir)
304 cmdstring +=
' %s %s' % (presrcfile, self.
buildname)
316 Assemble command string for the main build event. 322 includes = [
'-I"'+x+
'" ' for x
in self.
incdirs]
327 dependencies = [
'-L"'+x+
'" ' for x
in self.
libdirs]
328 for x
in dependencies:
332 libs = [
'-l'+x+
' ' for x
in self.
libs]
343 Assemble command string for the post-build event. 354 with Utility.ChangedWorkingDirectory(self.
scrtdir):
384 if self.
outdir != os.getcwd():
385 for f
in os.listdir(os.getcwd()):
388 copyfile(os.path.join(os.getcwd(),f), os.path.join(self.
outdir,f))
391 copyfile(os.path.join(os.getcwd(),f), os.path.join(self.
outdir,f))
399 Utility.DeleteFilesbyEnding(self.
temps)
406 Inherited class to build projects without any presets. 410 Initialization of Custom class object. 412 super(Custom, self).
__init__(*args, **kwargs)
417 self.
exe =
"cmd.exe /c &&" 424 os.environ[
"ABQ_ENV_FILE"] =
"abaqus_v6.env" 425 os.environ[
"pyx_abaqus"] = os.getenv(
"pyx_abaqus",
"abaqus")
428 self.
temps = self.
temps + (os.getenv(
"ABQ_ENV_FILE"), )
431 def Preprocessing(self, cmdstring='', inend='', outend='', replace = {'!DEC$ IF':
'#IF',
'!DEC$ ELSE':
'#ELSE',
'!DEC$ ENDIF':
'#ENDIF'}):
433 Assemble command string for the pre-build event. 439 with Utility.ChangedWorkingDirectory(self.
scrtdir):
442 collsrcfile = Utility.GetTemporaryFileName(filename=
"coll" +
"_", extension=inend)
443 presrcfile = Utility.GetTemporaryFileName(filename=
"pre",extension=outend)
446 Utility.ConcatenateFiles(collsrcfile,self.
srcs, self.
srcdir, inend)
450 Utility.ReplaceTextinFile(collsrcfile, presrcfile, replace, source=self.
scrtdir)
453 cmdstring +=
' %s %s' % (presrcfile, self.
buildname)
463 self.
temps = self.
temps + (collsrcfile, presrcfile)
468 Assemble command string for the main build event. 473 os.environ[
"INCLUDE"] = os.pathsep.join(list(self.
incdirs)) + os.pathsep + os.pathsep.join((os.environ.get(
"MSMPI_INC",
""), os.environ.get(
"INCLUDE",
"")))
476 os.environ[
"LIB"] = os.pathsep.join(self.
libdirs) + os.pathsep + os.pathsep.join((os.environ.get(
"MSMPI_LIB64",
""), os.environ.get(
"LIB",
"")))
479 os.environ[
"PATH"] = os.pathsep.join([self.
srcdir,self.
scrtdir]) + os.pathsep + os.getenv(
"PATH",
"")
485 if self.
msvsc.lower()
in [
"vs2015",
"vs2017"]:
486 self.
libs.extend([
"msvcrt",
"vcruntime",
"ucrt",
"legacy_stdio_definitions"])
489 pyx_libs = [
"'"+x+
".lib'" for x
in self.
libs]
492 os.environ[
"pyx_libs"] =
",".join(pyx_libs)
507 Inherited class to build projects using Intel C/C++. 511 Initialization of C/C++ class object. 513 super(CCxx, self).
__init__(*args, **kwargs)
521 self.
isStatic =
True if kwargs.get(
'lib',
'static')
not in [
'shared',
'SHARED',
'Shared']
else False 529 self.
exe +=
' -c %s' % (
' '.join(self.
srcs))
551 self.
incdirs.append(os.path.join(PyXMakePath,
"VTL",
"make"))
556 Define output directories for modules and libraries. 564 Assemble command strings for the main build event. 570 includes = [
' -I"'+x+
'" ' for x
in self.
incdirs]
576 librarian =
'link -dll -fixed:no -defaultlib:libcmt.lib -nodefaultlib:msvcrt.lib ' 587 self.
makecmd += self.
exe + cmd + cmdstring +
' && ' 602 with Utility.ChangedWorkingDirectory(self.
scrtdir):
612 dependencies = [
' -LIBPATH:"'+x+
'" ' for x
in self.
libdirs]
613 for y
in dependencies:
617 linklist = [
' '+x+
'.lib ' for x
in self.
libs]
641 Utility.DeleteFilesbyEnding(self.
temps)
649 Inherited class to build projects using Intel Fortran. 653 Initialization of Fortran class object. 655 super(Fortran, self).
__init__(*args, **kwargs)
660 self.
isStatic =
True if kwargs.get(
'lib',
'static')
not in [
'shared',
'SHARED',
'Shared']
else False 665 mkl_interface_lib =
"mkl_intel_c" 667 mkl_interface_lib =
"mkl_intel_lp64" 670 self.
libs.append([mkl_interface_lib,
"mkl_intel_thread",
"mkl_core",
"libiomp5md"])
671 self.
libs = list(Utility.ArbitraryFlattening(self.
libs))
704 Define output directories for modules and libraries. 707 if modulepath
is None:
715 def Preprocessing(self, inend='', outend='', copyfiles=[],
716 replace = {'!DEC$ IF':
'#IF',
'!DEC$ ELSE':
'#ELSE',
'!DEC$ ENDIF':
'#ENDIF'},
717 decorator=
"!DEC$ ATTRIBUTES DLLEXPORT::"):
719 Assemble command string for the pre-build event. 728 with Utility.ChangedWorkingDirectory(self.
scrtdir):
731 search_dir = [self.
srcdir]
733 search_dir.extend(self.
incdirs)
739 for subdir
in search_dir:
740 src_files = os.listdir(subdir)
741 file_names = [x
for x
in src_files
if x
in copyfiles]
743 for inputfile
in file_names:
744 full_file_name = os.path.join(subdir, inputfile)
745 if (os.path.isfile(full_file_name)):
746 shutil.copy(full_file_name, os.getcwd())
750 collsrcfile = Utility.GetTemporaryFileName(filename=
"coll" +
"_", extension=inend)
751 presrcfile = Utility.GetTemporaryFileName(filename=
"pre",extension=outend)
754 Utility.ConcatenateFiles(collsrcfile, self.
srcs, self.
srcdir, inend)
757 Utility.ReplaceTextinFile(collsrcfile, presrcfile, replace, source=self.
scrtdir)
760 Inputfile = os.path.join(os.getcwd(),presrcfile)
761 Outputfile = os.path.join(os.getcwd(),self.
buildname)
762 with open(Inputfile)
as infile, open(Outputfile,
'w')
as outfile:
766 xname, xline = line.partition(
'="')[0], line.partition(
'="')[2]
767 if xline !=
'' and validater
in xname.lower():
768 outfile.write(decorator+xline.partition(
'"')[0]+
"\n")
769 self.
temps = self.
temps + (collsrcfile, presrcfile, )
775 def Wrapper(self, module_name, source_name=None):
777 Assemble command string for the pre-build event. 780 makedir = os.path.join(PyXMakePath,
"VTL",
"make")
781 TmpFile = Utility.GetTemporaryFileName(extension=str(os.path.splitext(self.
wrapper_module)[1]))
787 self.
intermediate_wrapper = Utility.GetTemporaryFileName(extension=str(os.path.splitext(TmpFile)[1]))
790 with Utility.ChangedWorkingDirectory(self.
scrtdir):
800 Assemble command strings for the main build event. 802 sep =
" "; multi_objects = []
812 includes = [
' -I"'+x+
'" ' for x
in self.
incdirs]
818 librarian =
'link -dll -fixed:no -defaultlib:libcmt.lib -nodefaultlib:msvcrt.lib ' 836 makefile = sep.join([x
for x
in self.
srcs if os.path.splitext(x)[1].lower()
in (
".for",
".f95",
".f",
".f90")])
837 multi_objects = [os.path.splitext(x)[0]+
".obj" for x
in self.
srcs if os.path.splitext(x)[1].lower()
in (
".for",
".f95",
".f",
".f90")]
841 self.
makecmd +=
'ifort -c '+ makefile + cmd + cmdstring +
' && ' 843 if not multi_objects:
860 with Utility.ChangedWorkingDirectory(self.
scrtdir):
870 dependencies = [
' -LIBPATH:"'+x+
'" ' for x
in self.
libdirs]
871 for y
in dependencies:
875 linklist = [
' '+x+
'.lib ' for x
in self.
libs]
881 if f.endswith(
'.mod')
and not kwargs.get(
"combine",
False):
882 os.remove(os.path.join(self.
outmodule,f))
903 if self.
isStatic and kwargs.get(
"combine",
False):
904 sep =
' '; librarian =
'lib '; ext =
'.lib' 905 mergedid = os.path.basename(self.
outmodule)
907 multi_libs = [os.path.join(self.
outlibs,x)
for x
in [list(Utility.ArbitraryFlattening(x[2]))
for x
in Utility.PathWalk(self.
outlibs)][0]
if x.startswith(mergedid)]
917 for lib
in multi_libs:
918 os.remove(os.path.join(self.
outlibs,lib))
924 Utility.DeleteFilesbyEnding(self.
temps)
932 Inherited class to build projects using Py2X. 936 Initialization of Py2X class object. 938 @note Currently uses f2py - but should be build with Py2X (DLR) in the future 940 super(Py2X, self).
__init__(*args, **kwargs)
958 self.
path2exe = sys.executable.replace(
"\python.exe",
"")
966 old_numpy_call = os.path.join(self.
path2exe,
"Scripts",
"f2py.py")
967 new_numpy_call = os.path.join(self.
path2exe,
"Scripts",
"f2py.exe")
969 if os.path.exists(old_numpy_call):
970 self.
exe +=
'"{}"'.format(old_numpy_call)
972 self.
exe =
'"{}"'.format(new_numpy_call)
978 mkl_interface_lib =
"mkl_intel_c" 980 mkl_interface_lib =
"mkl_intel_lp64" 984 self.
libs.append([mkl_interface_lib,
"mkl_intel_thread",
"mkl_core",
"libiomp5md"])
985 self.
libs = list(Utility.ArbitraryFlattening(self.
libs))
988 self.
libs.append(
"mkl_rt")
989 self.
libs = list(Utility.ArbitraryFlattening(self.
libs))
996 c_files = [x
for x
in self.
srcs if os.path.splitext(x)[1].lower()
in (
".for",
".f95",
".f",
".f90")]
1002 copyfile(os.path.join(Path2Config,
".f2py_f2cmap"), os.path.join(self.
scrtdir,
".f2py_f2cmap"))
1017 Inherited class to build projects using PyInstaller. 1021 Initialization of PyInstaller class object. 1023 @note Creates stand-alone application of Python scripts using PyInstaller. 1025 super(PyInstaller, self).
__init__(*args, **kwargs)
1030 self.
buildtype = kwargs.get(
"type",
"onefile")
1044 Encrypt byte-code by using user-supplied or randomly generated key. 1047 @param encrypt: Boolean 1050 self.
key_string = kwargs.get(
"key_string",
''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits)
for _
in range(16)))
1055 Assemble command string for the pre-build event. 1063 def Build(self, mode="onefile", **kwargs):
1065 Switch build mode. Defaults to one single file. 1069 from PyInstaller.compat
import is_py27, is_py35, is_py36, is_py37
1070 from setuptools
import __version__
as set_version
1081 self.
makecmd.append(
"--icon=%s" % kwargs.get(
"icon",os.path.join(Path2Config,
"stm_logo.ico")))
1084 if int(str(set_version)[0:2]) >= 45:
1085 self.
makecmd.insert(1,
'--hidden-import=%s' %
"pkg_resources.py2_warn")
1088 if os.path.exists(os.path.join(PyXMakePath,
"Build",
"bin",
"upx")):
1089 self.
makecmd.append(
"--upx-dir=%s" % os.path.join(PyXMakePath,
"Build",
"bin",
"upx"))
1093 excludes = [
"python2.dll",
"python27.dll",
"qwindows.dll"]
1095 excludes = [x
for x
in os.listdir(os.path.dirname(sys.executable))
if x.endswith((
".dll"))]
1097 excludes = [x
for x
in os.listdir(os.path.dirname(sys.executable))
if x.endswith((
".dll"))]
1099 excludes = [
"python3.dll",
"python37.dll",
"ucrtbase.dll",
"qwindows.dll"]
1101 upx_exclude = [
"--upx-exclude=%s" % x
for x
in excludes]
1102 self.
makecmd.extend(upx_exclude)
1105 add_compile = list(Utility.ArbitraryFlattening(kwargs.get(
"add_compile",[])))
1108 if hasattr(self,
"incdirs"):
1110 if os.path.exists(data.split(os.path.pathsep)[0]):
1111 new_path = data.split(os.path.pathsep)[0]
1113 if Utility.PathLeaf(new_path).endswith(
".py")
and Utility.PathLeaf(new_path)
in add_compile:
1114 py_compile.compile(new_path,os.path.join(self.
scrtdir,Utility.PathLeaf(new_path)+
"c"))
1115 self.
temps = self.
temps + (Utility.PathLeaf(new_path)+
"c",)
1116 new_path = os.path.join(self.
scrtdir,Utility.PathLeaf(new_path)+
"c")
1117 data = os.path.pathsep.join([new_path,data.split(os.path.pathsep)[1]])
1118 self.
makecmd.insert(1,
'--add-data=%s' % data)
1120 for path
in sys.path:
1121 new_path = os.path.join(path,data.split(os.path.pathsep)[0])
1122 if os.path.exists(new_path)
and os.path.isdir(new_path):
1124 if not kwargs.get(
"add_plain",
False):
1125 for root, _, files
in Utility.PathWalk(new_path):
1127 if any(x
in root
for x
in [
".git",
".svn"]):
1131 if not file.endswith((
".pdf"))
and not any(x
in file
for x
in [
".cpython"]):
1132 base_path = data.split(os.path.pathsep)[-1]; sub_path = root.split(base_path)[-1]
1133 sub_struct =os.path.join(base_path,sub_path.lstrip(os.path.sep),
".")
1135 if len(data.split(os.path.pathsep)) != 1:
1136 save_path = os.path.join(data.split(os.path.pathsep)[-1],
".")
1138 save_path = sub_struct
1140 if file.endswith(
".py")
and os.path.exists(os.path.join(new_path,file+
"c")):
1142 elif file.endswith(
".py")
and file
in add_compile:
1144 py_compile.compile(os.path.join(new_path.split(data.split(os.path.pathsep)[0])[0],sub_struct.rstrip(
"."),file),
1145 os.path.join(new_path.split(data.split(os.path.pathsep)[0])[0],sub_struct.rstrip(
"."),file+
"c"))
1148 self.
makecmd.insert(1,
'--add-data=%s' % os.path.pathsep.join([os.path.join(new_path.split(
1149 data.split(os.path.pathsep)[0])[0],sub_struct.rstrip(
"."),file),save_path]))
1152 self.
makecmd.insert(1,
'--add-data=%s' % os.path.pathsep.join([new_path,data.split(os.path.pathsep)[-1]]))
1155 elif os.path.exists(new_path)
and os.path.isfile(new_path):
1156 if Utility.PathLeaf(new_path).endswith(
".py")
and Utility.PathLeaf(new_path)
in add_compile:
1157 py_compile.compile(new_path,os.path.join(self.
scrtdir,Utility.PathLeaf(new_path)+
"c"))
1158 self.
temps = self.
temps + (Utility.PathLeaf(new_path)+
"c",)
1159 new_path = os.path.join(self.
scrtdir,Utility.PathLeaf(new_path)+
"c")
1160 self.
makecmd.insert(1,
'--add-data=%s' % os.path.pathsep.join([new_path,os.path.join(os.path.dirname(data.split(os.path.pathsep)[-1]),
".")]))
1166 if hasattr(self,
"scrtdir"):
1167 self.
makecmd.insert(1,
'--specpath=%s' % os.path.join(self.
scrtdir))
1168 self.
makecmd.insert(1,
'--workpath=%s' % os.path.join(self.
scrtdir,
"build"))
1171 if hasattr(self,
"outdir"):
1172 self.
makecmd.insert(1,
'--distpath=%s' % os.path.join(self.
outdir))
1175 if hasattr(self,
"libdirs"):
1177 self.
makecmd.insert(1,
'--paths=%s' % path)
1180 if hasattr(self,
"key_string"):
1184 if hasattr(self,
"srcdir")
and self.
srcdir:
1190 if hasattr(self,
"verbose"):
1197 self.
makecmd.insert(1,
'--log-level=%s' % level)
1201 Execute make command 1204 import PyInstaller.__main__
as pyi
1207 sys.setrecursionlimit(kwargs.get(
"recursion_limit",5000))
1210 with Utility.ChangedWorkingDirectory(self.
scrtdir):
1226 Utility.DeleteFilesbyEnding(self.
temps)
1227 shutil.rmtree(
'build', ignore_errors=
True)
1236 Inherited class to build projects using NSIS. 1240 Initialization of PyInstaller class object. 1242 @note Creates a portable installer of a source folder using NSIS. 1244 super(NSIS, self).
__init__(*args, **kwargs)
1255 self.
path2exe = os.path.join(PyXMakePath,
"Build",
"bin",
"nsis",
"App",
"NSIS")
1266 def FTP(self, user, key, upload_file, host='ftp.dlr.de', path="/public/download/nightly"):
1268 Define settings to establish a FTP connection. 1275 with open(upload_file,
'rb')
as file:
1276 self.
ftp_client.storbinary(
"STOR %s" % Utility.PathLeaf(upload_file), file)
1281 Execute make command 1283 space =
" "; point =
"."; newline =
'\n' 1286 script = [
"Unicode true"]
1287 script.append(
"!define MULTIUSER_EXECUTIONLEVEL user")
1288 script.append(
"!define ZIP2EXE_NAME `%s`" % self.
buildid)
1289 script.append(
"!define ZIP2EXE_OUTFILE `%s`" % os.path.join(self.
outdir,point.join([self.
buildid,
"exe"])))
1290 script.append(
"!define ZIP2EXE_COMPRESSOR_LZMA")
1291 script.append(
"!define ZIP2EXE_INSTALLDIR `$EXEDIR`")
1292 script.append(
"!include `${NSISDIR}\Contrib\zip2exe\Base.nsh`")
1293 script.append(
"!include `${NSISDIR}\Contrib\zip2exe\Modern.nsh`")
1294 if kwargs.get(
"install_path",
""):
1295 script.append(
"InstallDir '%s'" % kwargs.get(
"install_path",
"$Desktop"))
1296 script.append(
"!insertmacro SECTION_BEGIN")
1297 script.append(
"SetOutPath $INSTDIR")
1299 for src
in self.
srcs:
1300 script.append(
"File /r /x *.nsh `%s`" % os.path.join(kwargs.get(
"assembly_path", self.
srcdir),src))
1301 script.append(
"!insertmacro SECTION_END")
1302 script.append(
'Icon "%s"' % kwargs.get(
"icon",os.path.join(Path2Config,
"stm_logo.ico")))
1303 script.append(
"RequestExecutionLevel user")
1306 with Utility.ChangedWorkingDirectory(self.
scrtdir):
1308 MakeFile = Utility.GetTemporaryFileName(extension=
".nsh")
1311 with open(MakeFile,
"w")
as f:
1312 f.write(newline.join(script))
1319 self.
temps += (MakeFile,)
1322 Utility.DeleteFilesbyEnding(self.
temps)
1325 if kwargs.get(
"upload",
False)
and not hasattr(self,
"ftp_client"):
1326 user = kwargs.get(
"user",os.getenv(
"username")); key = kwargs.get(
"key",
"")
1327 self.
FTP(user, key, point.join([os.path.join(self.
outdir,self.
buildid),
"exe"]))
1330 print(
"==================================")
1331 print(
"Uploaded result to DLR's FTP server")
1332 print(
"==================================")
1341 Inherited class to automatically build a documentation using Doxygen. 1345 Initialization of doxygen class object. 1347 super(Doxygen, self).
__init__(*args,**kwargs)
1351 os.environ[
'dox_pyjava'] =
'NO' 1352 os.environ[
'dox_fortran'] =
'NO' 1353 os.environ[
'dox_ccpp'] =
'NO' 1354 os.environ[
'dox_pdflatex'] =
'NO' 1358 self.
path2exe = os.path.join(PyXMakePath,
"Build",
"bin",
"doxygen")
1366 os.environ[
'dox_fortran'] =
'YES' 1371 elif self.
stype ==
'CCpp':
1372 os.environ[
'dox_ccpp'] =
'YES' 1376 temp = []; delimn =
" " 1378 temp.append(self.
srcs)
1379 os.environ[
'dox_pyjava'] =
'YES' 1380 paths = list(Utility.ArbitraryFlattening(temp))
1384 for x
in os.listdir(y):
1385 if x.endswith((
".java",
".py")):
1386 if not any([z ==
"__init__.py" for z
in os.listdir(y)])
and x.endswith((
".py")):
1389 open(os.path.join(y,
"__init__.py"),
'a+').close()
1391 self.
temps = self.
temps + (os.path.join(y,
"__init__.py"),)
1396 if y
in [os.path.dirname(k)
for k
in list(filter(os.path.isfile, self.
temps))]:
1401 for x
in list(filter(os.path.isfile, self.
temps)):
1404 path = os.path.dirname(x)
1405 if os.path.exists(os.path.join(path,
"__init__.py")):
1412 list(filter(os.path.isfile, self.
temps))
1415 self.
temps = tuple(filter(os.path.isfile, self.
temps))
1418 if list(self.
temps):
1420 rev_command = [
"del"] + list(self.
temps)
1421 self.
postcmd = delimn.join(rev_command)
1424 os.environ[
'dox_input'] = self.
buildname 1425 os.environ[
'dox_images'] = Path2Config
1426 os.environ[
'dox_footer'] = os.path.join(Path2Config,
"stm_doc_footer.html")
1427 os.environ[
'dox_logo'] = os.path.join(Path2Config,
"stm_logo.png")
1428 os.environ[
'dox_pyfilter'] = sys.executable+
" "+os.path.join(Path2Config,
"stm_pyfilter.py")
1431 if not all([os.getenv(x)
for x
in (
"dox_hue",
"dox_sat",
"dox_gamma")]):
1432 from PyXMake.Build.config.stm_color
import DLRBlue
as dox_color
1433 os.environ[
'dox_hue'], os.environ[
'dox_sat'], os.environ[
'dox_gamma'] = [str(int(round(x)))
for x
in np.multiply([360.,100.,100],
1434 np.array(colorsys.rgb_to_hsv(*(value/255
for value
in 1435 ImageColor.getcolor(dox_color,
"RGB")))))]
1443 def Settings(self, brief, header, outdir='', **kwargs):
1445 Define environment variables for the default configuration file. 1453 os.environ[
'dox_brief'] = brief
1454 os.environ[
'dox_header'] = header
1455 os.environ[
'dox_outdir'] = self.
outdir 1458 if kwargs.get(
"color",
""):
1460 os.environ[
'dox_hue'], os.environ[
'dox_sat'], os.environ[
'dox_gamma'] = [str(x)
for x
in np.multiply([360.,100.,100],
1461 np.array(colorsys.rgb_to_hsv(*(value/255
for value
in 1462 ImageColor.getcolor(kwargs.get(
"color"),
"RGB")))))]
1469 Inherited class to automatically build a documentation using Sphinx. 1473 Initialization of sphinx class object. 1475 super(Sphinx, self).
__init__(*args,**kwargs)
1480 from six
import exec_
1482 exec_(open(__install__.__file__).read(),{
"__name__":
"__main__",
"__file__":__install__.__file__})
1485 os.environ[
"PATH"] += os.pathsep + os.pathsep.join([os.path.join(os.path.dirname(sys.executable),
"Scripts")])
1489 self.
path2exe = os.path.join(os.path.dirname(sys.executable),
"Scripts")
1496 os.environ[
"sphinx_project"] = str(self.
buildid)
1499 os.environ[
"sphinx_master"] = str(self.
srcs[0])
1502 from PyXMake.Build.config.stm_color
import DLRBlue
as sphinx_color
1503 os.environ[
"sphinx_color"] = sphinx_color
1513 Define environment variables for the default configuration file. 1517 for key, value
in kwargs.items():
1518 os.environ[delimn.join([
"sphinx",str(key)])] = str(value)
1523 Execute make command 1525 from distutils.dir_util
import copy_tree
1528 self.
SPHINXOPTS = os.getenv(
'sphinx_opts',
'')
1529 self.
SPHINXBUILD = os.getenv(
'sphinx_build',
'sphinx-build')
1530 self.
PAPER = os.getenv(
'sphinx_paper',
None)
1533 self.
BUILDDIR = os.getenv(
'sphinx_builddir', Utility.PathLeaf(tempfile.NamedTemporaryFile().name))
1534 self.
TEMPDIR = os.getenv(
'sphinx_templates',
"_templates")
1535 self.
STATICEDIR = os.getenv(
'sphinx_static',
"_static")
1538 os.environ[
'sphinx_static'] = self.
STATICEDIR; os.environ[
'sphinx_templates'] = self.
TEMPDIR 1541 os.environ[
"sphinx_include"] = os.getenv(
"sphinx_include",
"")
1542 os.environ[
"sphinx_include"] += os.pathsep + os.pathsep.join(self.
incdirs)
1546 User-friendly check for sphinx-build 1548 with open(os.devnull,
'w')
as devnull:
1550 if subprocess.call([self.
SPHINXBUILD,
'--version'],stdout=devnull, stderr=devnull) == 0:
1552 except FileNotFoundError:
1555 "The '{0}' command was not found. Make sure you have Sphinx " 1556 "installed, then set the SPHINXBUILD environment variable " 1557 "to point to the full path of the '{0}' executable. " 1558 "Alternatively you can add the directory with the " 1559 "executable to your PATH. If you don't have Sphinx " 1560 "installed, grab it from http://sphinx-doc.org/)" 1565 def build(builder, success_msg=None, extra_opts=None, outdir=None,doctrees=True):
1569 builddir = os.path.join(self.
BUILDDIR or outdir)
1571 command.extend([
'-c', os.getenv(
'sphinx_config',self.
SOURCEDIR)])
1573 command = command[:len(command)-2]
1575 command.extend([
'-d', os.path.join(self.
BUILDDIR,
'doctrees')])
1577 command.extend(extra_opts)
1580 if Utility.Popen(command,self.
verbose) == 0:
1581 print(
'Build finished. ' + success_msg.format(self.
outdir or builddir))
1583 def buildmethod(function):
1585 Decorator function for each build option 1600 Remove the build directory 1602 shutil.rmtree(self.
BUILDDIR, ignore_errors=
True)
1607 Make standalone HTML files 1609 return build(
'html',
'The HTML pages are in {}.')
1614 Make HTML files named index.html in directories 1616 return build(
'dirhtml',
'The HTML pages are in {}')
1621 Make a single large HTML file 1623 return build(
'singlehtml',
'The HTML page is in {}.')
1630 return build(
'pickle',
'Now you can process the pickle files.')
1637 return build(
'json',
'Now you can process the JSON files.')
1642 Make HTML files and a HTML help project 1644 return build(
'htmlhelp',
'Now you can run HTML Help Workshop with the .hhp project file in {}.')
1649 Make HTML files and a qthelp project 1651 return build(
'qthelp',
'Now you can run "qcollectiongenerator" with the ' 1652 '.qhcp project file in {0}, like this: \n' 1653 '# qcollectiongenerator {0}/RinohType.qhcp\n' 1654 'To view the help file:\n' 1655 '# assistant -collectionFile {0}/RinohType.qhc')
1660 Make HTML files and a Devhelp project 1662 return build(
'devhelp',
'To view the help file:\n' 1663 '# mkdir -p $HOME/.local/share/devhelp/RinohType\n' 1664 '# ln -s {} $HOME/.local/share/devhelp/RinohType\n' 1672 return self.build(
'epub',
'The epub file is in {}.')
1677 Make a PDF using rinohtype 1679 return self.build(
'rinoh',
'The PDF file is in {}.')
1684 Make LaTeX files, you can set PAPER=a4 or PAPER=letter 1686 extra_opts = [
'-D',
'latex_paper_size={}'.format(self.
PAPER)]
if self.
PAPER else None 1687 return build(
'latex',
'The LaTeX files are in {}.\n' 1688 "Run 'make' in that directory to run these through " 1689 "(pdf)latex (use the 'latexpdf' target to do that " 1690 "automatically).", extra_opts)
1695 Make LaTeX files and run them through pdflatex 1698 print(
'Running LaTeX files through pdflatex...')
1699 builddir = os.path.join(self.
BUILDDIR,
'latex')
1700 subprocess.call([
'make',
'-C', builddir,
'all-pdf'])
1701 print(
'pdflatex finished; the PDF files are in {}.'.format(builddir))
1706 Make LaTeX files and run them through platex/dvipdfmx 1709 print(
'Running LaTeX files through platex and dvipdfmx...')
1710 builddir = os.path.join(self.
BUILDDIR,
'latex')
1711 subprocess.call([
'make',
'-C', builddir,
'all-pdf-ja'])
1712 print(
'pdflatex finished; the PDF files are in {}.'.format(builddir))
1719 return build(
'text',
'The text files are in {}.')
1726 return build(
'man',
'The manual pages are in {}.')
1733 return build(
'texinfo',
'The Texinfo files are in {}.\n' 1734 "Run 'make' in that directory to run these " 1735 "through makeinfo (use the 'info' target to do " 1736 "that automatically).")
1741 Make Texinfo files and run them through makeinfo 1744 print(
'Running Texinfo files through makeinfo...')
1745 builddir = os.path.join(self.
BUILDDIR,
'texinfo')
1746 subprocess.call([
'make',
'-C', builddir,
'info'])
1747 print(
'makeinfo finished; the Info files are in {}.'.format(builddir))
1752 Make PO message catalogs 1754 return build(
'gettext',
'The message catalogs are in {}.', outdir=
'locale',doctrees=
False)
1759 Make an overview of all changed/added/deprecated items 1761 return build(
'changes',
'The overview file is in {}.')
1766 Make Docutils-native XML files 1768 return build(
'xml',
'The XML files are in {}.')
1773 Make pseudoxml-XML files for display purposes 1775 return self.build(
'pseudoxml',
'The pseudo-XML files are in {}.')
1780 Check all external links for integrity 1782 return build(
'linkcheck',
'Look for any errors in the above output or in {}/output.txt.')
1787 Run all doctests embedded in the documentation (if enabled) 1789 return build(
'doctest',
'Look at the results in {}/output.txt.')
1796 print(
"Please use '{} <target>' where <target> is one of" .format(sys.argv[0]))
1797 width = max(len(name)
for name
in self.
BuildOption)
1799 print(
' {name:{width}} {descr}'.format(name=name, width=width, descr=target.__doc__))
1804 args = [
'default']
or sys.argv[1:]
1807 with Utility.TemporaryDirectory(self.
scrtdir):
1809 temp = Utility.PathLeaf(tempfile.NamedTemporaryFile().name)
1811 shutil.copytree(self.
SOURCEDIR, temp, ignore=shutil.ignore_patterns(
".git",
".svn")); self.
SOURCEDIR = temp
1813 if not os.path.exists(os.path.join(temp,
"conf.py")):
1815 copyfile(os.path.join(PyXMakePath,
"Build",
"config",
"stm_conf.py"), os.path.join(temp,
"conf.py"))
1817 if not os.path.exists(os.path.join(temp,
"_static")):
1818 os.mkdir(os.path.join(temp,
'_static')); copyfile(os.path.join(PyXMakePath,
"Build",
"config",
"stm_style.css"), os.path.join(temp,
"_static",
"style.css"))
1820 if not os.path.exists(os.path.join(temp,
"_templates")):
1821 os.mkdir(os.path.join(temp,
'_templates')); copyfile(os.path.join(PyXMakePath,
"Build",
"config",
"stm_layout.html"), os.path.join(temp,
"_templates",
"layout.html"))
1825 if not kwargs.get(
"keep_doctree",
False):
1827 shutil.rmtree(os.path.join(self.
BUILDDIR,
"doctrees"))
1840 Inherited class for all builds using SSH connection. 1844 Initialization of SSH class object. 1846 super(SSH, self).
__init__(*args, **kwargs)
1849 setattr(self, str(Fortran.Wrapper.__name__), MethodType(Fortran.Wrapper, self))
1897 Define output directories for modules and libraries. Output written to the workspace is DELETED. 1900 if modulepath
is None:
1901 modulepath = libpath
1908 def Settings(self, user, key, host='129.247.54.37', port=22):
1910 Define settings to establish a SSH connection. 1915 self.
workspace = posixpath.join(Utility.AsDrive(
'home',posixpath.sep),user)+posixpath.sep
1918 self.
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
1919 self.
ssh_client.connect(hostname=host, port=port, username=user, key_filename=key)
1924 Load an additional environment file prior to execution of all commands. 1927 self.
environment +=
"source " + posixpath.join(path,bash)+
" "+args+
"; " 1932 Assemble command string for the post-build event. 1938 def Build(self, cmdstring, run= "ifort", path="", lib= "", linkedIn=""):
1940 Assemble command strings for the main build event. 1945 self.
libs.append(lib)
1946 self.
libs = list(Utility.ArbitraryFlattening(self.
libs))
1963 c_files = [x
for x
in self.
srcs if os.path.splitext(x)[1].lower()
in (
".for",
".f95",
".f",
".f90")]
1964 cmd +=
' %s ' % (
' '.join(c_files))
1967 if self.
exe in (
"f2py"):
1970 self.
libs.extend([
"mkl_rt",
"iomp5",
"pthread",
"m",
"dl"])
1973 for x
in [
' -l'+x+
' ' for x
in self.
libs]:
1980 if self.
exe not in (
"ifort",
"gcc",
"g++"):
1983 elif self.
exe ==
"ifort":
1988 self.
linkcmd = posixpath.join(
"",
"ar")+
" -rc " 1993 Define settings to establish SSH connection. 1998 includes = [
':"'+x+
'"' for x
in self.
incdirs]
2005 library = [
':"'+x+
'" ' for x
in self.
libdirs]
2013 linklist = [
'ar -x "'+x+
'" && ' for x
in self.
linkedIn]
2025 with Utility.ChangedWorkingDirectory(self.
scrtdir):
2048 for cs
in self.
srcs:
2052 if self.
exe not in (
"ifort",
"gcc",
"g++"):
2053 sftp.put(os.path.join(Path2Config,
".f2py_f2cmap"), posixpath.join(self.
workspace,
".f2py_f2cmap"))
2060 if not kwargs.get(
"combine",
False):
2066 if Utility.IsNotEmpty(target):
2067 self.
command+=
' "'+target+
'"' 2072 if Utility.IsNotEmpty(self.
linkcmd):
2077 sarch = 1; scopy = 0
2088 if Utility.IsNotEmpty(self.
postcmd):
2095 posixpath.join(self.
workspace,
"intel")+
'; rm -f '+
2096 posixpath.join(self.
workspace,
".f2py_f2cmap") +
2097 " rm -f %s " % (
' '.join([posixpath.join(self.
workspace,cs)
for cs
in self.
srcs])))
2102 if kwargs.get(
"combine",
False):
2103 librarian =
'ar'; ext =
'.a'; decomp =
" && "+librarian+
" -x " 2104 mergedid =
"lib"+posixpath.basename(self.
outmodule.rstrip(
"/"))
2106 multi_libs = [x
for x
in [x.rstrip(
"\n")
for x
in stdout.readlines()
if x.startswith(mergedid)]]
2115 self.
postcmd += librarian +
" -x " + decomp.join(multi_libs) +
" && " 2119 for lib
in multi_libs:
2120 _, _, _ = self.
ssh_client.exec_command(
'rm -f '+posixpath.join(self.
outlibs,lib))
2124 with Utility.ChangedWorkingDirectory(self.
scrtdir):
2127 Utility.DeleteFilesbyEnding(self.
temps)
2129 if __name__ ==
'__main__':
outmodule
Output path for module or header files.
linkcmd
Intel Linker command.
MakeObjectKind
String identifier of current instance.
BuildOption
Ordered dictionary containing all available options.
srcdir
Default search directory for source files.
isStatic
Static or dynamic link library flag.
Base class for all PyInstaller build events.
def Settings(self, user, key, host='129.247.54.37', port=22)
Base class for all custom build events inherited from Make.
exe
Executable of Doxygen.
verbose
Level of verbosity of the current build object.
def __init__(self, args, kwargs)
workspace
Remote workspace.
linkcmd
Intel Linker command.
def __init__(self, args, kwargs)
def Postprocessing(self, cmdstring="")
MakeObjectKind
String identifier of current instance.
def FTP(self, user, key, upload_file, host='ftp.dlr.de', path="/public/download/nightly")
buildid
Base string of build object.
libname
Name of library, assembled using BuildID.
def Build(self, cmdstring, run="ifort", path="", lib="", linkedIn="")
def __init__(self, args, kwargs)
ssh_client
Instance of SSHClient to establish a SSH connection.
isStatic
Static or dynamic link library flag.
path2exe
Absolute system path to Python executable.
def __init__(self, args, kwargs)
intelpath
Path to Intel Fortran Compiler (read from Paths.log).
libdirs
List of library directories.
incremental
Define if the input should be compiled exactly as provided.
outlibs
Output path for library files.
def Encryption(self, encrypt, kwargs)
__library_path
Environment variable to be set prior to the execution of the build command.
def OutputPath(self, libpath, modulepath=None)
architecture
Processor architecture.
__old_export
Environment variables to be set prior to the execution of the build command.
def __init__(self, args, kwargs)
def OutputPath(self, libpath=os.getcwd())
def __setstate__(self, _dict)
iniCompiler
Executable batch script (including absolute system path) to set up the Intel Fortran Compiler...
linkedIn
List of libraries which should be statically linked in.
def OutputPath(self, modulepath=None, libpath=os.getcwd())
Base class for all Doxygen build events.
def Build(self, cmdstring)
exe
The executable command used in the main build event.
Base class for all build events requiring a SSH connection.
setarch
Define the architecture for the build directly by using the keyword argument "arch".
environment
Load an additional library prior to execution of all commands.
def Build(self, mode="onefile", kwargs)
def Preprocessing(self, cmdstring='')
temps
Tuple of data to be removed after job completion.
exe
The executable command used in all build events.
Abstract base class for all make objects.
def Wrapper(self, module_name, source_name=None)
linkedIn
List of libraries which should be statically linked in.
def __init__(self, args, kwargs)
libname
Name of library, assembled using BuildID.
msvsc
Default version of Microsoft visual studio used by the Intel Fortran Compiler.
incremental
Define if the input should be compiled exactly as provided.
MakeObjectKind
String identifier of current instance.
ftp_client
Remote workspace.
path2exe
Path to Sphinx executable.
def Settings(self, brief, header, outdir='', kwargs)
def SourcePath(self, path)
MakeObjectKind
String identifier of current instance.
precmd
Command executed during pre-build event.
no_static_mkl
Define whether Intel's MKL should be statically or dynamically linked.
def __init__(self, BuildID, Srcs, scratch=os.getcwd(), msvsc='vs2015', stype='Fortran', verbose=0, args, kwargs)
copyfiles
List of files to be copied to the output directory after finish.
def __init__(self, args, kwargs)
outlibs
Output path for library files.
linkedIn
List of libraries which should be statically linked in.
Base class for all NSIS build events.
def Build(self, cmdstring)
__intel_path
Custom intel path.
compargs
Command line arguments passed in by the user.
incdirs
List of include directories.
path2exe
(Intel Fortran) Compiler Path
def AddDependencyPath(self, dependencies)
libs
List of actual libraries (by name) used during linking.
def AddIncludePath(self, includes)
srcs
Source file or folders.
def __init__(self, args, kwargs)
Base class for all C/C++ build events inherited from Make.
def Environment(self, path="", bash="", args="")
no_append_arch
Define whether the architecture shall be appended to the build name.
def UseLibraries(self, libs)
Base class for all Sphinx build events.
intermediate_wrapper
Wrapper interface file for 3rd party FORTRAN code.
MakeObjectKind
String identifier of current instance.
incremental
Define if the input should be compiled exactly as provided.
linkcmd
Remote Linker command.
MakeObjectKind
String identifier of current instance.
Base class for all Py2X (for now only f2py) build events.
Module containing all relevant modules and scripts associated with the building process.
exe
The executable command used in the main build event.
makecmd
Command executed during build event.
def __init__(self, args, kwargs)
export
Environment variables to be set prior to the execution of the build command.
def Build(self, cmdstring)
outdir
Default search directory for output.
Base class for all Fortran build events.
path2exe
Path to Doxygen executable.
MakeObjectKind
String identifier of current instance.
MakeObjectKind
String identifier of current instance.
def Environment(self, path, script="ifortvars.bat")
intermediate_wrapper
Wrapper interface file for 3rd party FORTRAN code.
MakeObjectKind
String identifier of current instance.
libname
Name of library, assembled using BuildID.
outmodule
Output path for module or header files.
path2exe
Path to NSIS executable.
def Settings(self, kwargs)
scrtdir
Current scratch directory.
outlibs
Output path for library files.
def Postprocessing(self, cmdstring='')
def OutputPath(self, path, files="")
def Build(self, cmdstring)
postcmd
Post build command.