IDE: Allow environment variable override in ThirdPartyPath, and use it also for matiec.
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 19 Nov 2024 23:52:04 +0100
changeset 4042 03df7946c2fa
parent 4041 af7671a9945a
child 4043 b217fb367574
IDE: Allow environment variable override in ThirdPartyPath, and use it also for matiec.
ProjectController.py
util/paths.py
--- a/ProjectController.py	Mon Nov 18 22:42:11 2024 +0100
+++ b/ProjectController.py	Tue Nov 19 23:52:04 2024 +0100
@@ -46,7 +46,7 @@
 
 import features
 import connectors
-import util.paths as paths
+import util.paths as pathutils
 from util.misc import CheckPathPerm, GetClassImporter
 from util.MiniTextControler import MiniTextControler
 from util.ProcessLogger import ProcessLogger
@@ -65,7 +65,6 @@
 from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage
 from POULibrary import UserAddressedException
 
-base_folder = paths.AbsParentDir(__file__)
 
 MATIEC_ERROR_MODEL = re.compile(
     r".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): (?:error)|(?:warning) : (.*)$")
@@ -116,7 +115,7 @@
     def findCmd(self):
         cmd = "iec2c" + (".exe" if os.name == 'nt' else "")
         paths = [
-            os.path.join(base_folder, "matiec")
+            pathutils.ThirdPartyPath("matiec")
         ]
         path = self.findObject(
             paths, lambda p: os.path.isfile(os.path.join(p, cmd)))
@@ -129,7 +128,7 @@
 
     def findLibPath(self):
         paths = [
-            os.path.join(base_folder, "matiec", "lib"),
+            pathutils.ThirdPartyPath("matiec", "lib"),
             "/usr/lib/matiec"
         ]
         path = self.findObject(
--- a/util/paths.py	Mon Nov 18 22:42:11 2024 +0100
+++ b/util/paths.py	Tue Nov 19 23:52:04 2024 +0100
@@ -50,6 +50,10 @@
     """
     Return folder where to find sibling projects like Modbus, CanFestival, BACnet
     """
+    env_name = name.upper() + "_PATH"
+    if env_name in os.environ:
+        return os.path.join(os.environ[env_name], *suffixes)
+    
     return os.path.join(AbsParentDir(__file__, 2), name, *suffixes)
 
 def Bpath(*names):