Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BSK not yet compatible with python 3.12 #765

Open
schaubh opened this issue Aug 17, 2024 · 2 comments
Open

BSK not yet compatible with python 3.12 #765

schaubh opened this issue Aug 17, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@schaubh
Copy link
Contributor

schaubh commented Aug 17, 2024

Describe your use case
Python 3.12 is not yet supported. Need to work out updates to make Basilisk compatible with 3.12 and retain prior python compatibility.

@schaubh schaubh added the enhancement New feature or request label Aug 17, 2024
@schaubh schaubh self-assigned this Aug 17, 2024
@schaubh schaubh added this to Basilisk Aug 17, 2024
@sassy-asjp
Copy link
Contributor

I suspected the segfault under python3.12 was related to how SysModel is set up in SWIG separately for cSysModel and sysModel modules and hacked something together to test my suspicion. This diff fixes the segfault in python3.12, but isn't a proper thing that can be merged.

I'm not actively working on python3.12 support, but if anyone is, I'm sharing this snippet in case it is useful.

diff --git a/pyproject.toml b/pyproject.toml
index fe1a90f27..811e56264 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -14,7 +14,7 @@ requires = [
 [project]
 name        = 'Basilisk'
 dynamic     = ["version", "dependencies", "optional-dependencies"]
-requires-python = ">=3.8, <3.12"
+requires-python = ">=3.8, <3.13"
 
 readme      = "README.md"
 license     = {file = "LICENSE"}
diff --git a/src/architecture/_GeneralModuleFiles/py_sys_model.i b/src/architecture/_GeneralModuleFiles/py_sys_model.i
deleted file mode 100644
index 71b4a0b5e..000000000
--- a/src/architecture/_GeneralModuleFiles/py_sys_model.i
+++ /dev/null
@@ -1,57 +0,0 @@
-
-%module(directors="1") sysModel
-%{
-   #include "sys_model.h"
-%}
-
-%pythoncode %{
-import sys
-import traceback
-from Basilisk.architecture.swig_common_model import *
-%}
-%include "std_string.i"
-%include "swig_conly_data.i"
-%include "architecture/utilities/bskLogging.h"
-
-%feature("director") SysModel;
-%feature("pythonappend") SysModel::SysModel %{
-    self.__super_init_called__ = True%}
-%rename("_SysModel") SysModel;
-%include "sys_model.i"
-
-%pythoncode %{
-class SuperInitChecker(type):
-
-    def __call__(cls, *a, **kw):
-        rv = super(SuperInitChecker, cls).__call__(*a, **kw)
-        if not getattr(rv, "__super_init_called__", False):
-            error_msg = (
-               "Need to call parent __init__ in SysModel subclasses:\n"
-               f"class {cls.__name__}(sysModel.SysModel):\n"
-               "    def __init__(...):\n"
-               "        super().__init__()"
-            )
-            raise SyntaxError(error_msg)
-        return rv
-
-def logError(func):
-    """Decorator that prints any exceptions that happen when
-    the original function is called, and then raises them again."""
-    def inner(*arg, **kwargs):
-        try:
-            return func(*arg, **kwargs)
-        except Exception:
-            traceback.print_exc()
-            raise
-    return inner
-
-class SysModel(_SysModel, metaclass=SuperInitChecker):
-    bskLogger: BSKLogger = None
-
-    def __init_subclass__(cls):
-        # Make it so any exceptions in UpdateState and Reset
-        # print any exceptions before returning control to
-        # C++ (at which point exceptions will crash the program)
-        cls.UpdateState = logError(cls.UpdateState)
-        cls.Reset = logError(cls.Reset)
-%}
diff --git a/src/architecture/_GeneralModuleFiles/sys_model.i b/src/architecture/_GeneralModuleFiles/sys_model.i
index 63cf55ed7..639ea34cc 100644
--- a/src/architecture/_GeneralModuleFiles/sys_model.i
+++ b/src/architecture/_GeneralModuleFiles/sys_model.i
@@ -1,5 +1,5 @@
 
-%module cSysModel
+%module(directors="1") sysModel
 %{
    #include "sys_model.h"
 %}
@@ -18,6 +18,8 @@ from Basilisk.architecture.swig_common_model import *
 from typing import Union, Iterable
 %}
 
+%feature("director") SysModel;
+
 %extend SysModel
 {
     %pythoncode %{

@schaubh
Copy link
Contributor Author

schaubh commented Oct 17, 2024

Thanks for sharing your insight @sassy-asjp .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants