Skip to content

Commit

Permalink
Oldnodes parser retrofit (#4509)
Browse files Browse the repository at this point in the history
* retrofit parser module

* fix module-string
  • Loading branch information
zeffii authored Jun 3, 2022
1 parent 003860d commit 756efd2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion old_nodes/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion old_nodes/formula2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion old_nodes/profile_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions utils/modules/parser_subset.py
Original file line number Diff line number Diff line change
@@ -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, '<string>', mode='eval')

parser = lambda: None
parser.expr = lambda str_formula: Expr(str_formula)

0 comments on commit 756efd2

Please sign in to comment.