diff --git a/old_nodes/formula.py b/old_nodes/formula.py index d2196dfd0a..a882cd26cc 100644 --- a/old_nodes/formula.py +++ b/old_nodes/formula.py @@ -16,11 +16,11 @@ # # ##### END GPL LICENSE BLOCK ##### -import parser import bpy from bpy.props import StringProperty +from sverchok.utils.modules.parser_subset import parser from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode from math import cos, sin, pi, tan diff --git a/old_nodes/formula2.py b/old_nodes/formula2.py index 114463e316..f3ff75820e 100644 --- a/old_nodes/formula2.py +++ b/old_nodes/formula2.py @@ -16,7 +16,6 @@ # # ##### END GPL LICENSE BLOCK ##### -import parser from math import ( acos, acosh, asin, asinh, atan, atan2, atanh, ceil, copysign, cos, cosh, degrees, e, @@ -29,6 +28,7 @@ import bpy from bpy.props import BoolProperty, StringProperty +from sverchok.utils.modules.parser_subset import parser from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import ( updateNode, multi_socket, changable_sockets, diff --git a/old_nodes/profile_mk2.py b/old_nodes/profile_mk2.py index 2553963e4c..fcb7b5cb93 100644 --- a/old_nodes/profile_mk2.py +++ b/old_nodes/profile_mk2.py @@ -22,7 +22,7 @@ import json from string import ascii_lowercase -import parser +from sverchok.utils.modules.parser_subset import parser from ast import literal_eval import bpy diff --git a/utils/modules/parser_subset.py b/utils/modules/parser_subset.py new file mode 100644 index 0000000000..dd08172451 --- /dev/null +++ b/utils/modules/parser_subset.py @@ -0,0 +1,26 @@ +""" +in Python 3.10 the parser module has been removed. some old nodes +(namely: formula.py / formula2.py / profile_mk2.py) make light use of that module. + +The main goal of this module is to suppress a startup import exception caused by +the missing parser module, and at the same time offer the basic features of that +module as used by these nodes. +""" + +try: + import parser + +except (ImportError, ModuleNotFoundError) as err: + + from dataclasses import dataclass + + @dataclass + class Expr(str): + str_formula: str + def compile(self): + # print('use mock') + return compile(self.str_formula, '', mode='eval') + + parser = lambda: None + parser.expr = lambda str_formula: Expr(str_formula) +