PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
py2x.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Triple-use minimum working example for PyXMake. This script can be
7executed in three different ways in varying levels of accessibility
8
9@note: Compile Fortran source as a shared library for Python
10 using f2py (Py2X in the future).
11Created on 20.03.2018
12
13@version: 1.0
14----------------------------------------------------------------------------------------------
15@requires:
16 - PyXMake, PyCODAC
17
18@change:
19 -
20
21@author: garb_ma [DLR-FA,STM Braunschweig]
22----------------------------------------------------------------------------------------------
23"""
24import os, sys
25
26try:
27 import PyXMake as _ #@UnusedImport
28except ImportError:
29 # Script is executed as a plug-in
30 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
31finally:
32 from PyXMake.Tools import Utility #@UnresolvedImport
33 from PyXMake.Build.Make import Py2X
34 from PyXMake import VTL #@UnresolvedImport
35
36# Predefined script local variables
37__arch = Utility.GetArchitecture()
38
39try:
40 # Import PyCODAC to build library locally during setup.
41 from PyCODAC.Tools.Utility import GetPyCODACPath
42 # Import and set local path to PyCODAC
43 __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
44except ImportError:
45 # This script is not executed as plug-in
46 __mcd_core_path = ""
47except:
48 # Something else went wrong.
49 from PyXMake.Tools import ErrorHandling
51
52def main(
53 BuildID,
54 # Build MCODAC by default
55 files=VTL.GetSourceCode(0),
56 command = VTL.GetBuildCommand(0),
57 libs = VTL.GetLinkDependency(0, 0, __arch),
58 # Resource paths
59 source=os.path.join(__mcd_core_path,"src"),
60 include=[os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, x)
61 for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)],
62 dependency=os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch),
63 output=os.path.join(__mcd_core_path,"bin",Utility.GetPlatform(),__arch),
64 # Architecture, verbose and scratch directory
65 architecture=__arch,scratch=VTL.Scratch, verbosity=(2 if not Utility.IsDockerContainer() else 2),
66 # Activate / deactivate incremental compilation. Does deactivate preprocessing.
67 incremental = False, **kwargs):
68 """
69 Main function to execute the script.
70 """
71 # Build .pyd using f2py (for now!)
72 P2XBuild = Py2X(BuildID, files, scratch=scratch, msvsc=kwargs.pop("msvsc","vs2015"), verbose=verbosity, incremental=incremental,
73 no_append_arch=kwargs.pop("no_arch",False), **kwargs)
74 P2XBuild.AddIncludePath(include)
75 P2XBuild.SourcePath(source)
76
77 # Activate / deactivate incremental compilation & linking
78 if not incremental:
79 # Set default preprocessor command
80 Preprocessing = VTL.GetPreprocessingCommand(0)
81 # Use alternative FOSS implementation in Docker container.
82 if Utility.IsDockerContainer and Utility.GetPlatform() in ["linux"]: Preprocessing= VTL.GetPreprocessingCommand(1)
83 P2XBuild.Preprocessing(Preprocessing+' -DPYD', inend='.for', outend='.fpp')
84 else:
85 P2XBuild.Preprocessing(copyfiles=files)
86
87 P2XBuild.OutputPath(output)
88 P2XBuild.Build(command)
89 P2XBuild.AddDependencyPath(dependency)
90 P2XBuild.UseLibraries(libs)
91 P2XBuild.create()
92
93if __name__ == "__main__":
94# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95# % Access command line inputs %
96# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 # Execute CLI command
98 Py2X.run()
99 # Finish
100 print("==================================")
101 print("Finished build for Python")
102 print("==================================")
103 sys.exit()
Base class for all Py2X (for now only f2py) build events.
Base class for all input errors.
Create a make object to define the building environment.
Definition Make.py:1
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
main(BuildID, files=VTL.GetSourceCode(0), command=VTL.GetBuildCommand(0), libs=VTL.GetLinkDependency(0, 0, __arch), source=os.path.join(__mcd_core_path,"src"), include=[os.path.join(__mcd_core_path,"include", Utility.GetPlatform(), __arch, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)], dependency=os.path.join(__mcd_core_path,"lib", Utility.GetPlatform(), __arch), output=os.path.join(__mcd_core_path,"bin", Utility.GetPlatform(), __arch), architecture=__arch, scratch=VTL.Scratch, verbosity=(2 if not Utility.IsDockerContainer() else 2), incremental=False, **kwargs)
Definition py2x.py:67