|
2 | 2 | import platform |
3 | 3 | import subprocess |
4 | 4 | import sys |
5 | | -from pathlib import Path |
6 | 5 |
|
7 | 6 | from . import OGS_USE_PATH |
| 7 | +from .binaries_list import binaries_list |
| 8 | +from .get_bin_dir import get_bin_dir |
8 | 9 |
|
9 | | -binaries_list = [ |
10 | | - "addDataToRaster", |
11 | | - "AddElementQuality", |
12 | | - "AddFaultToVoxelGrid", |
13 | | - "AddLayer", |
14 | | - "appendLinesAlongPolyline", |
15 | | - "AssignRasterDataToMesh", |
16 | | - "checkMesh", |
17 | | - "ComputeNodeAreasFromSurfaceMesh", |
18 | | - "computeSurfaceNodeIDsInPolygonalRegion", |
19 | | - "constructMeshesFromGeometry", |
20 | | - "convertGEO", |
21 | | - "convertToLinearMesh", |
22 | | - "convertVtkDataArrayToVtkDataArray", |
23 | | - "CreateAnchors", |
24 | | - "CreateBoundaryConditionsAlongPolylines", |
25 | | - "createIntermediateRasters", |
26 | | - "createLayeredMeshFromRasters", |
27 | | - "createMeshElemPropertiesFromASCRaster", |
28 | | - "createNeumannBc", |
29 | | - "createQuadraticMesh", |
30 | | - "createRaster", |
31 | | - "createTetgenSmeshFromRasters", |
32 | | - "editMaterialID", |
33 | | - "ExtractBoundary", |
34 | | - "ExtractMaterials", |
35 | | - "ExtractSurface", |
36 | | - "generateGeometry", |
37 | | - "generateMatPropsFromMatID", |
38 | | - "generateStructuredMesh", |
39 | | - "geometryToGmshGeo", |
40 | | - "GMSH2OGS", |
41 | | - "GocadSGridReader", |
42 | | - "GocadTSurfaceReader", |
43 | | - "identifySubdomains", |
44 | | - "IntegrateBoreholesIntoMesh", |
45 | | - "ipDataToPointCloud", |
46 | | - "Layers2Grid", |
47 | | - "MapGeometryToMeshSurface", |
48 | | - "mergeMeshToBulkMesh", |
49 | | - "Mesh2Raster", |
50 | | - "MeshMapping", |
51 | | - "MoveGeometry", |
52 | | - "MoveMesh", |
53 | | - "moveMeshNodes", |
54 | | - "mpmetis", |
55 | | - "NodeReordering", |
56 | | - "ogs", |
57 | | - "OGS2VTK", |
58 | | - "partmesh", |
59 | | - "postLIE", |
60 | | - "PVD2XDMF", |
61 | | - "pvtu2vtu", |
62 | | - "queryMesh", |
63 | | - "Raster2ASC", |
64 | | - "Raster2Mesh", |
65 | | - "RemoveGhostData", |
66 | | - "removeMeshElements", |
67 | | - "RemoveUnusedPoints", |
68 | | - "ReorderMesh", |
69 | | - "ResetPropertiesInPolygonalRegion", |
70 | | - "reviseMesh", |
71 | | - "scaleProperty", |
72 | | - "swapNodeCoordinateAxes", |
73 | | - "TecPlotTools", |
74 | | - "TIN2VTK", |
75 | | - "VTK2OGS", |
76 | | - "VTK2TIN", |
77 | | - "vtkdiff", |
78 | | - "Vtu2Grid", |
79 | | - "xdmfdiff", |
80 | | -] |
81 | | - |
82 | | - |
83 | | -def pyproject_get_binaries(): |
84 | | - return { |
85 | | - binary: f"ogs._internal.provide_ogs_cli_tools_via_wheel:{binary}" |
86 | | - for binary in binaries_list |
87 | | - } |
| 10 | +OGS_BIN_DIR = get_bin_dir() |
| 11 | +if platform.system() == "Windows": |
| 12 | + os.add_dll_directory(OGS_BIN_DIR) |
88 | 13 |
|
89 | 14 |
|
90 | 15 | # Not used when OGS_USE_PATH is true! |
@@ -114,31 +39,22 @@ def ogs_with_args(argv): |
114 | 39 | return return_code |
115 | 40 |
|
116 | 41 |
|
117 | | -if "PEP517_BUILD_BACKEND" not in os.environ: |
118 | | - # Here, we assume that this script is installed, e.g., in a virtual environment |
119 | | - # alongside a "bin" directory. |
120 | | - OGS_BIN_DIR = Path(__file__).parent.parent.parent / "bin" # installed wheel |
121 | | - if not OGS_BIN_DIR.exists(): |
122 | | - OGS_BIN_DIR = OGS_BIN_DIR.parent # build directory |
123 | | - |
124 | | - if platform.system() == "Windows": |
125 | | - os.add_dll_directory(OGS_BIN_DIR) |
126 | | - |
127 | | - def _program(name, args): |
128 | | - exe = OGS_BIN_DIR / name |
129 | | - env = None # by default use unmodified environment |
130 | | - if OGS_USE_PATH: |
131 | | - exe = name |
132 | | - env = os.environ.copy() |
133 | | - # prevent infinite recursion if OGS in PATH happens to be this very |
134 | | - # script |
135 | | - env["OGS_USE_PATH"] = "0" |
136 | | - print(f"OGS_USE_PATH is true: {name} from $PATH is used!") |
137 | | - return subprocess.run([exe] + args, env=env).returncode # noqa: PLW1510 |
138 | | - |
139 | | - FUNC_TEMPLATE = """def {0}(): raise SystemExit(_program("{0}", sys.argv[1:]))""" |
140 | | - for f in binaries_list: |
141 | | - if f == "ogs" and not OGS_USE_PATH: |
142 | | - continue # provided by separate function |
143 | | - # When OGS_USE_PATH is true then ogs()-function above is not used! |
144 | | - exec(FUNC_TEMPLATE.format(f)) |
| 42 | +def _program(name, args): |
| 43 | + exe = OGS_BIN_DIR / name |
| 44 | + env = None # by default use unmodified environment |
| 45 | + if OGS_USE_PATH: |
| 46 | + exe = name |
| 47 | + env = os.environ.copy() |
| 48 | + # prevent infinite recursion if OGS in PATH happens to be this very |
| 49 | + # script |
| 50 | + env["OGS_USE_PATH"] = "0" |
| 51 | + print(f"OGS_USE_PATH is true: {name} from $PATH is used!") |
| 52 | + return subprocess.run([exe] + args, env=env).returncode # noqa: PLW1510 |
| 53 | + |
| 54 | + |
| 55 | +FUNC_TEMPLATE = """def {0}(): raise SystemExit(_program("{0}", sys.argv[1:]))""" |
| 56 | +for f in binaries_list: |
| 57 | + if f == "ogs" and not OGS_USE_PATH: |
| 58 | + continue # provided by separate function |
| 59 | + # When OGS_USE_PATH is true then ogs()-function above is not used! |
| 60 | + exec(FUNC_TEMPLATE.format(f)) |
0 commit comments