PyXMake Developer Guide: D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/ssh_f2py.py Source File

| PyXMake Developer Guide 1.0 PyXMake

D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/ssh_f2py.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 for PYTHON remotely
10 on the institute cluster. Uses main function.
11
12 @version: 1.0
13 ----------------------------------------------------------------------------------------------
14 @requires:
15 - PyXMake
16 - SSH key
17
18 @date:
19 - 24.07.2019
20
21 @author: garb_ma [DLR-FA,STM Braunschweig]
22 ----------------------------------------------------------------------------------------------
23 """
24 import os, sys
25 import argparse
26 import posixpath
27
28 try:
29 import PyXMake as _
30 except ImportError:
31 # Script is executed as a plug-in
32 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
33 finally:
34 from PyXMake.Build import Make as pyx
35 from PyXMake.Tools import Utility
36 from PyXMake import VTL
37
38 # Predefined script local variables
39 __user = os.getenv("username")
40 __mcd_cluster_dev = posixpath.join(Utility.AsDrive("home",posixpath.sep),__user,"mcodac")
41 __mcd_cluster_stable = posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","mcodac","stable")
42 __mcd_cluster_incpath = posixpath.join(__mcd_cluster_stable,"include")
43
44 try:
45 # Import PyCODAC to build library locally during setup.
46 from PyCODAC.Tools.Utility import GetPyCODACPath
47 # Import and set local path to PyCODAC
48 __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
49 except ImportError:
50 # This script is not executed as plug-in
51 __mcd_core_path = ""
52 except:
53 # Something else went wrong.
54 from PyXMake.Tools import ErrorHandling
55 ErrorHandling.InputError(20)
56
57 def main(
58 # Mandatory arguments
59 BuildID, user, key,
60 # Build MCODAC by default
61 files=VTL.GetSourceCode(0),
62 command=VTL.GetBuildCommand(4),
63 lib=VTL.GetLinkDependency(0, 4,"x64"),
64 # Resource paths
65 source=os.path.join(__mcd_core_path,"src"),
66 include=[posixpath.join(__mcd_cluster_incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")],
67 dependency=posixpath.join(__mcd_cluster_stable,"lib"),
68 output=posixpath.join(__mcd_cluster_dev,"bin"),
69 # Bash environment scripts
70 environment = VTL.GetEnvironment(2),
71 # Architecture, verbose and scratch directory (on host)
72 architecture="x64", scratch=VTL.Scratch, verbosity=2,
73 # Activate / deactivate incremental compilation. Does deactivate pre-processing.
74 incremental=False,
75 # Host and port number. Access DLR's institute cluster by default.
76 host="129.247.54.37", port=22):
77 """
78 Main function to execute the script.
79 """
80 envlist = list([]); envlist.append(environment); envlist = list(Utility.ArbitraryFlattening(envlist))
81 # Remote build using SSH connection.
82 SSHBuild = pyx.SSH(BuildID, files, msvsc='vs2015', scratch=scratch, arch=architecture,
83 verbose=verbosity, incremental=incremental)
84 SSHBuild.SourcePath(source)
85 SSHBuild.AddIncludePath(include)
86 SSHBuild.AddDependencyPath(dependency)
87 # Load environments successively (if given)
88 for x in envlist:
89 SSHBuild.Environment(bash=x)
90
91 # Activate / deactivate incremental compilation & linking
92 if not incremental:
93 SSHBuild.Preprocessing('fpp -P -e -DPYD', inend='.for', outend='.f90')
94 else:
95 SSHBuild.Preprocessing(copyfiles=files)
96
97 SSHBuild.OutputPath(libpath=output)
98 SSHBuild.Build(command, run="f2py", lib=lib)
99 SSHBuild.Settings(user, key, host, port)
100 SSHBuild.create()
101
102 if __name__ == "__main__":
103 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 # % Access command line inputs %
105 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 parser = argparse.ArgumentParser(description="Build shared Fortran libraries for Python remotely on the institute cluster.")
107 parser.add_argument("user", metavar="user", nargs=1, help="Current user for SSH connection")
108 parser.add_argument("key", metavar="key", nargs=1, help="Path to private SSH key")
109
110 try:
111 _ = sys.argv[1]
112 args, _ = parser.parse_known_args()
113 except:
114 pass
115
116 try:
117 # SSH key informations
118 user = args.user[0]
119 key = args.key[0]
120 except:
121 user = __user
122 key = os.path.join(Utility.AsDrive("C"),"Users",user,"Keys","Putty","id_rsa")
123
124 # Remotely build BEOS for Python (2.7, 3.5, 3.6) using SSH cluster connection.
125 for i in range(1,4):
126 # Build settings
127 BuildID = "beos"; env = VTL.GetEnvironment(i)
128 files=VTL.GetSourceCode(2); command=VTL.GetBuildCommand(4,"free")
129 lib = []; include = []; dependency = []
130 # Resource paths
131 source=os.path.join(__mcd_core_path,"external","beos")
132 # Execute make function obtained from virtual test lab.
133 main(BuildID, user, key, files, command, lib, source, include, dependency, environment=env, verbosity=0, incremental=True)
134
135 # Remotely build BoxBeam for Python (2.7, 3.5, 3.6) using SSH cluster connection.
136 for i in range(1,4):
137 # Build settings
138 BuildID = "bbeam"; env = VTL.GetEnvironment(i)
139 files=VTL.GetSourceCode(1); command=VTL.GetBuildCommand(4)
140 lib = []; include = []; dependency = []
141 # Resource paths
142 source=os.path.join(__mcd_core_path,"external","boxbeam")
143 # Execute make function obtained from virtual test lab.
144 main(BuildID, user, key, files, command, lib, source, include, dependency, environment=env, verbosity=0)
145
146 # Remotely build MCODAC for Python (2.7, 3.5, 3.6) using SSH cluster connection (default settings).
147 for i in range(1,4):
148 # Build settings
149 BuildID = "mcd_core"; env = VTL.GetEnvironment(i)
150 # Execute make function obtained from virtual test lab with default settings (builds MCODAC).
151 main(BuildID, user, key, environment=env)
152
153 else:
154 # This is not implemented yet.
155 raise NotImplementedError
156
157 # Finish
158 print("==================================")
159 print("Finished build for Python")
160 print("==================================")
161 sys.exit()
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition: __init__.py:1
PyXMake.VTL.ssh_f2py.main
def main(BuildID, user, key, files=VTL.GetSourceCode(0), command=VTL.GetBuildCommand(4), lib=VTL.GetLinkDependency(0, 4,"x64"), source=os.path.join(__mcd_core_path,"src"), include=[posixpath.join(__mcd_cluster_incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")], dependency=posixpath.join(__mcd_cluster_stable,"lib"), output=posixpath.join(__mcd_cluster_dev,"bin"), environment=VTL.GetEnvironment(2), architecture="x64", scratch=VTL.Scratch, verbosity=2, incremental=False, host="129.247.54.37", port=22)
Definition: ssh_f2py.py:76
PyXMake.Build
Module containing all relevant modules and scripts associated with the building process.
Definition: __init__.py:1