From c4dfd54b646fda4933d07e96f64afbf60b89fba6 Mon Sep 17 00:00:00 2001
From: Paul Dechamps <paul.dechamps@uliege.be>
Date: Fri, 31 Jan 2025 11:50:03 +0100
Subject: [PATCH] (ci) Updated DART import

DART is imported from the submodule if possible or from the blaster install path under blaster/dart. Custom install path can be specified in dartCfg as dart_path.
---
 blast/interfaces/dart/blDartInterface.py | 38 ++++++++++++++++--------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/blast/interfaces/dart/blDartInterface.py b/blast/interfaces/dart/blDartInterface.py
index 49eac1a..68ea7f9 100644
--- a/blast/interfaces/dart/blDartInterface.py
+++ b/blast/interfaces/dart/blDartInterface.py
@@ -15,7 +15,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
 # Dart interface
 # Paul Dechamps
 
@@ -24,6 +23,9 @@ import numpy as np
 from fwk.coloring import ccolors
 from blast.interfaces.blSolversInterface import SolversInterface
 
+dartflo_import_paths = {'local module': 'modules.dartflo.dart.api.core',
+                       'blaster install': 'blaster.dart.api.core'}
+
 class DartInterface(SolversInterface):
     """Interface to the Dart solver.
 
@@ -50,18 +52,30 @@ class DartInterface(SolversInterface):
         _cfg : dict
             Configuration parameters of the VII interface.
         """
-        try:
-            from modules.dartflo.dart.api.core import init_dart
-            self.iobj = init_dart(dartCfg, task=dartCfg['task'], viscous=True)
-            self.solver = self.iobj.get('sol') # Solver
-            self.blw = [self.iobj.get('blwb'), self.iobj.get('blww')]
-            if dartCfg['task'] == 'optimization':
-                self.adjointSolver = self.iobj.get('adj')
-                print('Dart successfully loaded for optimization.')
+        # Load DART module
+        if 'dart_path' in dartCfg:
+            # First try imposed path
+            try:
+                init_dart = __import__(dartCfg['dart_path'], fromlist=['init_dart']).init_dart
+                print(f'DART loaded from specified path {dartCfg["dart_path"]} for {dartCfg["task"]}.')
+            except ImportError:
+                raise ImportError(f'{ccolors.ANSI_RED}Could not load DART from specified path: {dartCfg["dart_path"]}.{ccolors.ANSI_RESET}')
+        else:
+            # Load from known paths
+            for name, path in dartflo_import_paths.items():
+                try:
+                    init_dart = __import__(path, fromlist=['init_dart']).init_dart
+                    print(f'DART loaded from {name} path for {dartCfg["task"]}.')
+                    break
+                except ImportError:
+                    continue
             else:
-                print('Dart successfully loaded for analysis.')
-        except:
-            raise ImportError(ccolors.ANSI_RED, 'Could not load DART.', ccolors.ANSI_RESET)
+                raise ImportError(f'{ccolors.ANSI_RED}Could not load DART.{ccolors.ANSI_RESET}')
+
+        self.iobj = init_dart(dartCfg, task=dartCfg['task'], viscous=True)
+        self.solver = self.iobj.get('sol') # Solver
+        self.blw = [self.iobj.get('blwb'), self.iobj.get('blww')]
+        self.adjointSolver = self.iobj.get('adj')
 
         _cfg['Format'] = dartCfg['Format']
         if 'iMsh' not in _cfg:
-- 
GitLab