PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
chocolatey.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Minimum working example for PyXMake.
7
8@note: Compile MCODAC for PYTHON using Mingw64/GFortran on windows.
9Created on 25.03.2021
10
11@version: 1.0
12----------------------------------------------------------------------------------------------
13@requires:
14 - PyXMake
15
16@change:
17 -
18
19@author: garb_ma [DLR-FA,STM Braunschweig]
20----------------------------------------------------------------------------------------------
21"""
22import shutil
23import os, sys
24import tempfile
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 import VTL #@UnresolvedImport
34 from PyXMake.VTL import cmake, py2x #@UnresolvedImport
35
36def run(output=os.getcwd(),verbose=2):
37 """
38 Main function to execute the script.
39 """
40 # Predefined script local variables
41 __arch = Utility.GetArchitecture()
42
43 try:
44 # Import PyCODAC to build library locally during setup.
45 from PyCODAC.Tools.Utility import GetPyCODACPath
46 # Import and set local path to PyCODAC
47 __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
48 except ImportError:
49 # This script is not executed as plug-in
50 __mcd_core_path = ""
51 except:
52 # Something else went wrong.
53 from PyXMake.Tools import ErrorHandling
54 ErrorHandling.InputError(20)
55
56 # Run everything in a temporary directory
57 with Utility.TemporaryDirectory(VTL.Scratch):
58
59 # Create a temporary source code folder.
60 __temp_path = os.path.join(os.getcwd(),Utility.GetTemporaryFileName(extension=""))
61 if not os.path.exists(__temp_path): shutil.copytree(__mcd_core_path, __temp_path, ignore=shutil.ignore_patterns('*.svn', '.git'))
62
63 # Overwrite default paths to reflect temporary directory
64 __mcd_core_path = __temp_path; __mcd_out_path = os.getcwd()
65
66 # Build BoxBeam for current python intepreter using Chocolatey and gfortran on Windows.
67 BuildID = 'bbeam';
68 py2x(BuildID, files=VTL.GetSourceCode(1), source=os.path.join(__mcd_core_path,"external","boxbeam"), libs=[],include=[],dependency=[], scratch = os.getcwd(),
69 verbosity=verbose, output=__mcd_out_path, bash=True)
70
71 # Build Beos for *
72 BuildID = 'beos';
73 py2x(BuildID, files=VTL.GetSourceCode(2), command=VTL.GetBuildCommand(0, _format="free"), source=os.path.join(__mcd_core_path,"external","beos"),
74 libs=[],include=[],dependency=[], scratch = os.getcwd(), output=__mcd_out_path, incremental=True, verbosity=verbose, bash=True)
75
76 ## Build MCODAC for *
77 BuildID = "mcd_core";
78
79 # Compile all dependencies using CMAKE.
80 cmake(BuildID, source=os.path.join(__mcd_core_path,"config"), scratch=os.getcwd(), bash=True)
81 # Build wheel
82 py2x(BuildID, source=os.path.join(__mcd_core_path,"src"),
83 include=[os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)],
84 dependency=os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch), scratch = os.getcwd(),
85 output=__mcd_out_path, verbosity=verbose, bash=True)
86
87 # Copy results to output directory
88 for x in os.listdir(os.getcwd()):
89 if x.endswith((".pyd")): shutil.move(x,os.path.join(output,x))
90
91 # Finish
92 print('==================================')
93 print('Finished')
94 print('==================================')
95
96 pass
97
98def main(python=sys.executable, **kwargs):
99 """
100 Build for a given python executable
101 """
102 from PyCODAC import PyCODACPath as __pyc_src_path
103
104 ## Add this script to the overall system path
105 output_path = os.path.normpath(kwargs.get("output",os.getcwd())).replace(os.sep,os.sep*2)
106 module_file = __file__.split(os.sep)[-1].split(".")[0]
107 file_dir = os.path.dirname(os.path.abspath(__file__)).replace(os.sep,os.sep*2)
108
109 # Create a temporary python script for execution
110 with tempfile.NamedTemporaryFile(mode="w+", suffix=".py", delete=False) as tmp:
111 tmp.writelines("import os; import sys; sys.path.insert(0, os.path.normpath('"+file_dir+"')); import %s; %s.run(output='%s')" % (module_file, module_file, output_path))
112
113 # Create build command
114 command = " ".join([python,os.path.join(__pyc_src_path,"__setenv__.py"),tmp.name])
115
116 # Run the command
117 p = Utility.Popen(command, verbosity=2, collect=False, shell=True)
118
119 # Delete temporary file
120 os.remove(tmp.name)
121
122 # Return error code
123 return getattr(p,"returncode",p)
124
125if __name__ == "__main__":
126 main(); sys.exit()
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
run(output=os.getcwd(), verbose=2)
Definition chocolatey.py:36
main(python=sys.executable, **kwargs)
Definition chocolatey.py:98