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

Oldnodes parser retrofit #4509

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)