From 27bee4900d7122585ac9e243ba47ea6ebf2abd04 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Mon, 25 Mar 2024 18:20:46 +0100 Subject: [PATCH] refactor & add some comments Signed-off-by: Peter Mitri --- patch.py | 27 ++++++++++----------------- patch_utils.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 patch_utils.py diff --git a/patch.py b/patch.py index f222956..e6bff18 100644 --- a/patch.py +++ b/patch.py @@ -1,24 +1,10 @@ from pathlib import Path from typing import List -from dataclasses import dataclass - -def replace_in_file(filepath, search, replace): - with open(filepath, 'r', encoding="utf8") as file: - data = file.read() - data = data.replace(search, replace) - - with open(filepath, 'w', encoding="utf8") as file: - file.write(data) - - -@dataclass -class Addition: - filepath: Path - search: str - add: str +from patch_utils import * full_patch: List[Addition] = [] +# add the USE_SIRIUS configuration flag in CMakeLists.txt full_patch.append(Addition( Path.cwd()/'CMakeLists.txt', '''option(USE_CPLEX "Use the CPLEX solver" OFF) @@ -30,6 +16,8 @@ class Addition: ''')) +# add the USE_SIRIUS configuration flag in cpp.cmake + full_patch.append( Addition( Path.cwd()/'cmake'/'cpp.cmake', @@ -48,6 +36,7 @@ class Addition: endif() ''')) +# add the USE_SIRIUS configuration flag in deps.cmake full_patch.append(Addition( Path.cwd()/'cmake'/'deps.cmake', ''' @@ -65,6 +54,7 @@ class Addition: endif(USE_SIRIUS) ''')) +# add the USE_SIRIUS configuration flag in ortoolsConfig.cmake.in full_patch.append(Addition( Path.cwd()/'cmake'/'ortoolsConfig.cmake.in', ''' @@ -85,7 +75,7 @@ class Addition: endif() ''')) - +# add SIRIUS execution in example files full_patch.append(Addition( Path.cwd()/'examples'/'cpp'/'linear_programming.cc', ' RunLinearProgrammingExample("XPRESS_LP");\n', @@ -111,6 +101,7 @@ class Addition: ' RunLinearExampleCppStyleAPI("XPRESS_LP")\n', ' RunLinearExampleCppStyleAPI("SIRIUS_LP")\n')) +# add the USE_SIRIUS configuration flag in ortools/linear_solver/CMakeLists.txt full_patch.append(Addition( Path.cwd()/'ortools'/'linear_solver'/'CMakeLists.txt', ' $<$:libscip>\n', @@ -129,6 +120,7 @@ class Addition: endif() ''')) +# add the SIRIUS support in ortools/linear_solver/linear_solver.cc & .h full_patch.append(Addition( Path.cwd()/'ortools'/'linear_solver'/'linear_solver.cc', '''extern MPSolverInterface* BuildXpressInterface(bool mip, @@ -187,5 +179,6 @@ class Addition: ' friend class XpressInterface;\n', ' friend class SiriusInterface;\n')) +# run patch for a in full_patch: replace_in_file(a.filepath, a.search, a.search+a.add) diff --git a/patch_utils.py b/patch_utils.py new file mode 100644 index 0000000..d5411b7 --- /dev/null +++ b/patch_utils.py @@ -0,0 +1,17 @@ +from pathlib import Path +from dataclasses import dataclass + +def replace_in_file(filepath, search, replace): + with open(filepath, 'r', encoding="utf8") as file: + data = file.read() + data = data.replace(search, replace) + + with open(filepath, 'w', encoding="utf8") as file: + file.write(data) + + +@dataclass +class Addition: + filepath: Path + search: str + add: str \ No newline at end of file