From 5431294a7aaccee76dd6417d5e77ea4ff8460456 Mon Sep 17 00:00:00 2001
From: Simon Bjurek <simbj106@student.liu.se>
Date: Mon, 10 Feb 2025 08:19:38 +0000
Subject: [PATCH] Fixes to make pipeline pass for python 3.13

---
 .gitlab-ci.yml                | 12 ++++++++++++
 b_asic/save_load_structure.py | 30 ++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f37ae53d..8c3439a7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -71,6 +71,18 @@ run-test-3.12-pyside6:
   image: python:3.12
   extends: ".run-test"
 
+run-test-3.13-pyqt6:
+  variables:
+    QT_API: pyqt6
+  image: python:3.13
+  extends: ".run-test"
+
+run-test-3.13-pyside6:
+  variables:
+    QT_API: pyside6
+  image: python:3.13
+  extends: ".run-test"
+
 run-vhdl-tests:
   variables:
     QT_API: pyqt6
diff --git a/b_asic/save_load_structure.py b/b_asic/save_load_structure.py
index 58497f4d..8f9622d4 100644
--- a/b_asic/save_load_structure.py
+++ b/b_asic/save_load_structure.py
@@ -150,18 +150,28 @@ def python_to_sfg(path: str) -> Tuple[SFG, Dict[str, Tuple[int, int]]]:
     path : str
         Path to file to read and deserialize.
     """
+    local_vars = {}
+
     with open(path) as file:
         code = compile(file.read(), path, "exec")
-        exec(code, globals(), locals())
-
-    return (
-        (
-            locals()["prop"]["name"]
-            if "prop" in locals()
-            else [v for k, v in locals().items() if isinstance(v, SFG)][0]
-        ),
-        locals()["positions"] if "positions" in locals() else {},
-    )
+        exec(code, globals(), local_vars)
+
+    # access variables from local_vars
+    sfg_object = None
+    if "prop" in local_vars and "name" in local_vars["prop"]:
+        sfg_object = local_vars["prop"]["name"]
+    else:
+        for v in local_vars.values():
+            if isinstance(v, SFG):
+                sfg_object = v
+                break
+
+    positions = local_vars.get("positions", {})
+
+    if sfg_object is None:
+        raise ValueError("No SFG object found in the provided file.")
+
+    return sfg_object, positions
 
 
 def schedule_to_python(schedule: Schedule) -> str:
-- 
GitLab