PyXMake Developer Guide  1.0
PyXMake
D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/py2x.py
1 # -*- coding: utf-8 -*-
2 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 # % PyXMake - Build environment for PyXMake %
4 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 """
6 Triple-use minimum working example for PyXMake. This script can be
7 executed 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).
11 Created 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 """
24 import os, sys
25 import argparse
26 
27 try:
28  import PyXMake as _
29 except ImportError:
30  # Script is executed as a plug-in
31  sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
32 finally:
33  from PyXMake.Tools import Utility #@UnresolvedImport
34  from PyXMake.Build import Make as pyx #@UnresolvedImport
35  from PyXMake import VTL #@UnresolvedImport
36 
37 # Predefined script local variables
38 __arch = Utility.GetArchitecture()
39 
40 try:
41  # Import PyCODAC to build library locally during setup.
42  from PyCODAC.Tools.Utility import GetPyCODACPath
43  # Import and set local path to PyCODAC
44  __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
45 except ImportError:
46  # This script is not executed as plug-in
47  __mcd_core_path = ""
48 except:
49  # Something else went wrong.
50  from PyXMake.Tools import ErrorHandling
51  ErrorHandling.InputError(20)
52 
53 def main(
54  BuildID,
55  # Build MCODAC by default
56  files=VTL.GetSourceCode(0),
57  command = VTL.GetBuildCommand(0),
58  libs = VTL.GetLinkDependency(0, 0, __arch),
59  # Resource paths
60  source=os.path.join(__mcd_core_path,"src"),
61  include=[os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, x)
62  for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)],
63  dependency=os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch),
64  output=os.path.join(__mcd_core_path,"bin",Utility.GetPlatform(),__arch),
65  # Architecture, verbose and scratch directory
66  architecture=__arch,scratch=VTL.Scratch, verbosity=0,
67  # Activate / deactivate incremental compilation. Does deactivate preprocessing.
68  incremental = False, **kwargs):
69  """
70  Main function to execute the script.
71  """
72  # Build .pyd using f2py (for now!)
73  P2XBuild = pyx.Py2X(BuildID, files, scratch=scratch, msvsc=kwargs.get("msvsc","vs2015"), verbose=verbosity, incremental=incremental)
74  P2XBuild.AddIncludePath(include)
75  P2XBuild.SourcePath(source)
76 
77  # Activate / deactivate incremental compilation & linking
78  if not incremental:
79  P2XBuild.Preprocessing('fpp -P -e -DPYD', inend='.for', outend='.fpp')
80  else:
81  P2XBuild.Preprocessing(copyfiles=files)
82 
83  P2XBuild.OutputPath(output)
84  P2XBuild.Build(command)
85  P2XBuild.AddDependencyPath(dependency)
86  P2XBuild.UseLibraries(libs)
87  P2XBuild.create()
88 
89 if __name__ == "__main__":
90 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 # % Access command line inputs %
92 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93  parser = argparse.ArgumentParser(description="Build a shared Fortran library for current Python executable")
94  parser.add_argument("make", metavar="make", nargs=1, help="Integer value selecting a predefined make operation")
95 
96  try:
97  _ = sys.argv[1]
98  args, _ = parser.parse_known_args()
99  # Extract command line option to identify the requested make operation
100  make_opt = args.make[0]
101  except:
102  # This is the default build option
103  make_opt = -1
104  # Build all supported features for current Python version (default options)
105  if make_opt == -1:
106 
107  # Build Beos
108  BuildID = 'beos'
109  main(BuildID,
110  files=VTL.GetSourceCode(2),
111  command=VTL.GetBuildCommand(0, _format="free"),
112  source=os.path.join(__mcd_core_path,"external","beos"),
113  libs=[],include=[],dependency=[],
114  # Beos binary is referenced in PyOCDAC. Updated is performed there
115  output=os.path.join(os.path.join(__mcd_core_path,"bin",Utility.GetPlatform(),__arch)), incremental=True)
116 
117  # Build BoxBeam
118  BuildID = 'bbeam'
119  main(BuildID,
120  files=VTL.GetSourceCode(1),
121  source=os.path.join(__mcd_core_path,"external","boxbeam"),
122  libs=[],include=[],dependency=[],
123  # BoxBeam binary is referenced in PyOCDAC. Updated is performed there
124  output=os.path.join(os.path.join(__mcd_core_path,"bin",Utility.GetPlatform(),__arch)))
125 
126  # Build MCODAC (default settings)
127  BuildID = "mcd_core"; main(BuildID)
128  else:
129  # This is not implemented yet
130  raise NotImplementedError
131 
132  # Finish
133  print("==================================")
134  print("Finished build for Python")
135  print("==================================")
136  sys.exit()
Module containing basic functionalities defined for convenience.
Definition: __init__.py:1
def 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=0, incremental=False, kwargs)
Definition: py2x.py:68
Module containing all relevant modules and scripts associated with the building process.
Definition: __init__.py:1