6 API setup example for PyXMake. 8 @note: Run HTML APIs of PyXMake (in a Docker container or locally). 12 ---------------------------------------------------------------------------------------------- 19 @author: garb_ma [DLR-FA,STM Braunschweig] 20 ---------------------------------------------------------------------------------------------- 26 from fastapi
import FastAPI, File, UploadFile, Query
27 from starlette.responses
import RedirectResponse, FileResponse
28 from starlette.staticfiles
import StaticFiles
29 from starlette.requests
import Request
30 from typing
import List
36 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
40 from PyXMake
import VTL
43 __pyx_api_delimn =
"/" 44 __pyx_doc_path = os.path.normpath(os.path.join(os.path.dirname(VTL.__file__),
"doc",
"pyx_core",
"html"))
45 __pyx_url_path = __pyx_api_delimn.join([
"https:",
"",
"fa-jenkins:8080",
"job",
"STM_Routines_ShortTest",
46 "Main_20Documentation",
"_subDocus",
"Tools_Utilities",str(PyXMake.__name__),
47 "documentation.html"])
50 __pyx_interface =
"Interface" 53 app = FastAPI(title=
"PyXMake API",
55 description =
"PyXMake is a python based make tool for daily software builds. This comprises daily library compilation for Python using f2py \ 56 (currently MCODAC, BoxBeam & Beos), daily updated html documentations using Doxygen (currently MCODAC, BoxBeam, PyXMake & PyCODAC) \ 57 and builds of shared & static libraries using Intel Fortran (currently MCODAC, BoxBeam). ",
58 docs_url = __pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"documentation"]))
61 app.mount(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"dev",
"documentation"]), StaticFiles(directory=__pyx_doc_path, html=
True))
66 @app.get(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"documentation"]), tags=[str(__pyx_guide)])
69 Method pointing to the main documentation of the API. 71 return RedirectResponse(url=__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"documentation",
""]))
73 @app.get(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"user",
"documentation"]), tags=[str(__pyx_guide)])
76 Method pointing to the user documentation of the underlying package. 78 return RedirectResponse(url=__pyx_url_path)
80 @app.get(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"dev",
"documentation"]), tags=[str(__pyx_guide)])
83 Method pointing to the developer documentation of the underlying package. 85 return RedirectResponse(url=__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"dev",
"documentation",
""]))
90 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"abaqus",
"{zip}"]), tags=[str(__pyx_interface)])
91 def api_abaqus(BuildID: str, Source: List[str] = Query(
"mcd_astandard"), ZIP: UploadFile = File(...)):
93 API for PyXMake to create an ABAQUS compatible Fortran library for Windows machines by using the Intel Fortran Compiler. 96 if os.path.exists(os.path.join(VTL.Scratch,ZIP.filename)):
97 os.remove(os.path.join(VTL.Scratch,ZIP.filename))
99 with Utility.TemporaryDirectory(VTL.Scratch), Utility.UpdateZIP(ZIP.filename, ZIP.file, VTL.Scratch, update=
False):
101 files = Utility.FileWalk(Source, path=os.getcwd())
103 with Utility.FileOutput(
'result.log'):
104 VTL.abaqus(BuildID, files, source=os.getcwd(), scratch=os.getcwd(), output=os.getcwd(), verbosity=2)
106 return FileResponse(path=os.path.join(VTL.Scratch,ZIP.filename),filename=ZIP.filename)
108 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"cxx",
"{zip}"]), tags=[str(__pyx_interface)])
109 def api_cxx(string_to_channel_through: str) -> dict:
111 Dummy function for showing a quick response 115 return {
"return_code": string}
117 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"doxygen",
"{zip}"]), tags=[str(__pyx_interface)])
118 def api_doxygen(string_to_channel_through: str) -> dict:
120 Dummy function for showing a quick response 124 return {
"return_code": string}
126 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"ifort",
"{zip}"]), tags=[str(__pyx_interface)])
127 def api_ifort(BuildID: str, Source: List[str] = Query([x
for x
in VTL.GetSourceCode(0)]), ZIP: UploadFile = File(...)):
129 API for PyXMake to create a static library for Windows machines by using the Intel Fortran Compiler. 132 if os.path.exists(os.path.join(VTL.Scratch,ZIP.filename)):
133 os.remove(os.path.join(VTL.Scratch,ZIP.filename))
135 with Utility.TemporaryDirectory(VTL.Scratch), Utility.UpdateZIP(ZIP.filename, ZIP.file, VTL.Scratch, update=
False):
137 files = Utility.FileWalk(Source, path=os.getcwd())
139 os.makedirs(
"include",exist_ok=
True); os.makedirs(
"lib",exist_ok=
True)
141 with Utility.FileOutput(
'result.log'):
142 VTL.ifort(BuildID, files, source=os.getcwd(), scratch=os.getcwd(), make=os.getcwd(), verbosity=2)
144 return FileResponse(path=os.path.join(VTL.Scratch,ZIP.filename),filename=ZIP.filename)
146 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"java",
"{zip}"]), tags=[str(__pyx_interface)])
147 def api_java(BuildID: str, Source: List[str] = Query([x
for x
in VTL.GetSourceCode(0)]), ZIP: UploadFile = File(...)):
149 API for PyXMake to create a Java compatible Fortran library for Windows machines by using the Intel Fortran Compiler. 152 if os.path.exists(os.path.join(VTL.Scratch,ZIP.filename)):
153 os.remove(os.path.join(VTL.Scratch,ZIP.filename))
155 with Utility.TemporaryDirectory(VTL.Scratch), Utility.UpdateZIP(ZIP.filename, ZIP.file, VTL.Scratch, update=
False):
157 files = Utility.FileWalk(Source, path=os.getcwd())
159 with Utility.FileOutput(
'result.log'):
160 VTL.java(BuildID, files, source=os.getcwd(), scratch=os.getcwd(), output=os.getcwd(), verbosity=2)
162 return FileResponse(path=os.path.join(VTL.Scratch,ZIP.filename),filename=ZIP.filename)
164 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"f2py",
"{zip}"]), tags=[str(__pyx_interface)])
165 def api_py2x(BuildID: str, Source: List[str] = Query([x
for x
in VTL.GetSourceCode(0)]), ZIP: UploadFile = File(...)):
167 API for PyXMake to create a Python compatible Fortran library for Windows machines by using the Intel Fortran Compiler. 170 if os.path.exists(os.path.join(VTL.Scratch,ZIP.filename)):
171 os.remove(os.path.join(VTL.Scratch,ZIP.filename))
173 with Utility.TemporaryDirectory(VTL.Scratch), Utility.UpdateZIP(ZIP.filename, ZIP.file, VTL.Scratch, update=
False):
175 files = Utility.FileWalk(Source, path=os.getcwd())
177 with Utility.FileOutput(
'result.log'):
178 VTL.py2x(BuildID, files, source=os.getcwd(), scratch=os.getcwd(), output=os.getcwd(), verbosity=2)
180 return FileResponse(path=os.path.join(VTL.Scratch,ZIP.filename),filename=ZIP.filename)
182 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"ssh_f2py",
"{zip}"]), tags=[str(__pyx_interface)])
183 def api_ssh_f2py(time_sleep: int) -> dict:
185 Dummy function for showing a long response time 188 return {
"return_code":str(time_sleep)}
190 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"ssh_ifort",
"{zip}"]), tags=[str(__pyx_interface)])
191 def api_ssh_ifort(time_sleep: int) -> dict:
193 Dummy function for showing a long response time 196 return {
"return_code":str(time_sleep)}
198 @app.patch(__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"ssh_make",
"{zip}"]), tags=[str(__pyx_interface)])
199 def api_ssh_make(time_sleep: int) -> dict:
201 Dummy function for showing a long response time 204 return {
"return_code":str(time_sleep)}
209 @app.get(__pyx_api_delimn.join([
"",
".*"]),include_in_schema=
False)
210 def invalid_request(request: Request) ->
None:
212 Method redirecting invalid responses back to the main window. 214 return RedirectResponse(url=__pyx_api_delimn.join([
"",str(PyXMake.__name__),
"api",
"documentation"]))
216 def main(Hostname=str(platform.node()), PortID=8020):
218 Importable main function of current API. 220 uvicorn.run(app, host=Hostname, port=PortID)
222 if __name__ ==
'__main__':
224 API is initialized and run.
def main(Hostname=str(platform.node()), PortID=8020)