diff --git a/mathics/builtin/directories/system_directories.py b/mathics/builtin/directories/system_directories.py index 4296ead51..1c9df0615 100644 --- a/mathics/builtin/directories/system_directories.py +++ b/mathics/builtin/directories/system_directories.py @@ -6,8 +6,8 @@ from mathics.core.attributes import A_NO_ATTRIBUTES from mathics.core.builtin import Predefined from mathics.core.evaluation import Evaluation -from mathics.core.streams import ROOT_DIR from mathics.eval.directories import INITIAL_DIR, SYS_ROOT_DIR, TMP_DIR +from mathics.settings import ROOT_DIR class BaseDirectory_(Predefined): diff --git a/mathics/builtin/no_meaning.py b/mathics/builtin/no_meaning.py index aea88cf96..b5b0f95c7 100644 --- a/mathics/builtin/no_meaning.py +++ b/mathics/builtin/no_meaning.py @@ -15,24 +15,27 @@ import mathics.core.parser.operators from mathics.core.builtin import ( - OPERATOR_DATA, NoMeaningInfixOperator, NoMeaningPostfixOperator, NoMeaningPrefixOperator, ) +from mathics.core.parser.operators import OPERATOR_DATA # Generate no-meaning Mathics3 Builtin class from the operator name, -# affix, and Operator Unicode values found read from the JSON operators -# file. +# affix, and Operator Unicode values found in OPERATOR_DATA. This +# data ultimately comes from a YAML file in the MathicsScanner project +# which is processed into a JSON file. + for affix, format_fn, operator_base_class in ( ("infix", "Infix", NoMeaningInfixOperator), ("postfix", "Postfix", NoMeaningPostfixOperator), ("prefix", "Prefix", NoMeaningPrefixOperator), ): - for operator_name, operator_string in OPERATOR_DATA[ + for operator_name, operator_tuple in OPERATOR_DATA[ f"no-meaning-{affix}-operators" ].items(): # Create the Mathics3 Builtin class... + operator_string = operator_tuple[0] generated_operator_class = type( operator_name, (operator_base_class,), diff --git a/mathics/core/builtin.py b/mathics/core/builtin.py index 6d2cf208c..975a0a4f9 100644 --- a/mathics/core/builtin.py +++ b/mathics/core/builtin.py @@ -8,7 +8,6 @@ import importlib import importlib.util -import os.path as osp import re from abc import ABC from functools import total_ordering @@ -27,7 +26,6 @@ ) import mpmath -import pkg_resources import sympy # Note: it is important *not* to use: @@ -66,6 +64,7 @@ from mathics.core.interrupt import BreakInterrupt, ContinueInterrupt, ReturnInterrupt from mathics.core.list import ListExpression from mathics.core.number import PrecisionValueError, dps, get_precision, min_prec +from mathics.core.parser.operators import OPERATOR_DATA from mathics.core.parser.util import PyMathicsDefinitions, SystemDefinitions from mathics.core.pattern import BasePattern from mathics.core.rules import BaseRule, FunctionApplyRule, Rule @@ -93,21 +92,6 @@ from mathics.eval.scoping import dynamic_scoping from mathics.eval.sympy import eval_sympy -try: - import ujson -except ImportError: - import json as ujson # type: ignore[no-redef] - -ROOT_DIR = pkg_resources.resource_filename("mathics", "") - -# Load the conversion tables from disk -operator_tables_path = osp.join(ROOT_DIR, "data", "operator-tables.json") -assert osp.exists( - operator_tables_path -), f"Internal error: Operator precedence tables are missing; expected to be in {operator_tables_path}" -with open(operator_tables_path, "r") as f: - OPERATOR_DATA = ujson.load(f) - # Exceptions... class NegativeIntegerException(Exception): diff --git a/mathics/core/convert/op.py b/mathics/core/convert/op.py index 9befa33c4..f682ac118 100644 --- a/mathics/core/convert/op.py +++ b/mathics/core/convert/op.py @@ -5,14 +5,13 @@ import os.path as osp from functools import lru_cache -import pkg_resources +from mathics.settings import ROOT_DIR try: import ujson except ImportError: import json as ujson # type: ignore[no-redef] -ROOT_DIR = pkg_resources.resource_filename("mathics", "") # Load the conversion tables from disk characters_path = osp.join(ROOT_DIR, "data", "op-tables.json") diff --git a/mathics/core/parser/operators.py b/mathics/core/parser/operators.py index d6dffd033..57c6f13f0 100644 --- a/mathics/core/parser/operators.py +++ b/mathics/core/parser/operators.py @@ -2,8 +2,25 @@ # -*- coding: utf-8 -*- +import os.path as osp from collections import defaultdict +from mathics.settings import ROOT_DIR + +try: + import ujson +except ImportError: + import json as ujson # type: ignore[no-redef] + +# Load the conversion tables from disk +operator_tables_path = osp.join(ROOT_DIR, "data", "operator-tables.json") +assert osp.exists( + operator_tables_path +), f"Internal error: Operator precedence tables are missing; expected to be in {operator_tables_path}" +with open(operator_tables_path, "r") as f: + OPERATOR_DATA = ujson.load(f) + + prefix_ops = { "Get": 720, "PreIncrement": 660,