From c18d33770435037c4b1ef7b372ff788a1b928afd Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Fri, 3 Jun 2022 16:17:26 +0200 Subject: [PATCH 1/2] retrofit parser module --- old_nodes/formula.py | 2 +- old_nodes/formula2.py | 2 +- old_nodes/profile_mk2.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 From bbe42dc70900fcf72f1aae0da9be50256711f725 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Fri, 3 Jun 2022 16:45:23 +0200 Subject: [PATCH 2/2] fix module-string --- utils/modules/parser_subset.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 utils/modules/parser_subset.py 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) +