Skip to content

Commit e715104

Browse files
committed
no-meanin JSON format changes slightly...
Also, move OPERATOR_DATA to mathics.core.parser.operators and pick up ROOT_DIR from mathics.settings
1 parent ad1c8af commit e715104

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

mathics/builtin/directories/system_directories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from mathics.core.attributes import A_NO_ATTRIBUTES
77
from mathics.core.builtin import Predefined
88
from mathics.core.evaluation import Evaluation
9-
from mathics.core.streams import ROOT_DIR
109
from mathics.eval.directories import INITIAL_DIR, SYS_ROOT_DIR, TMP_DIR
10+
from mathics.settings import ROOT_DIR
1111

1212

1313
class BaseDirectory_(Predefined):

mathics/builtin/no_meaning.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@
1515

1616
import mathics.core.parser.operators
1717
from mathics.core.builtin import (
18-
OPERATOR_DATA,
1918
NoMeaningInfixOperator,
2019
NoMeaningPostfixOperator,
2120
NoMeaningPrefixOperator,
2221
)
22+
from mathics.core.parser.operators import OPERATOR_DATA
2323

2424
# Generate no-meaning Mathics3 Builtin class from the operator name,
25-
# affix, and Operator Unicode values found read from the JSON operators
26-
# file.
25+
# affix, and Operator Unicode values found in OPERATOR_DATA. This
26+
# data ultimately comes from a YAML file in the MathicsScanner project
27+
# which is processed into a JSON file.
28+
2729
for affix, format_fn, operator_base_class in (
2830
("infix", "Infix", NoMeaningInfixOperator),
2931
("postfix", "Postfix", NoMeaningPostfixOperator),
3032
("prefix", "Prefix", NoMeaningPrefixOperator),
3133
):
32-
for operator_name, operator_string in OPERATOR_DATA[
34+
for operator_name, operator_tuple in OPERATOR_DATA[
3335
f"no-meaning-{affix}-operators"
3436
].items():
3537
# Create the Mathics3 Builtin class...
38+
operator_string = operator_tuple[0]
3639
generated_operator_class = type(
3740
operator_name,
3841
(operator_base_class,),

mathics/core/builtin.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import importlib
1010
import importlib.util
11-
import os.path as osp
1211
import re
1312
from abc import ABC
1413
from functools import total_ordering
@@ -27,7 +26,6 @@
2726
)
2827

2928
import mpmath
30-
import pkg_resources
3129
import sympy
3230

3331
# Note: it is important *not* to use:
@@ -66,6 +64,7 @@
6664
from mathics.core.interrupt import BreakInterrupt, ContinueInterrupt, ReturnInterrupt
6765
from mathics.core.list import ListExpression
6866
from mathics.core.number import PrecisionValueError, dps, get_precision, min_prec
67+
from mathics.core.parser.operators import OPERATOR_DATA
6968
from mathics.core.parser.util import PyMathicsDefinitions, SystemDefinitions
7069
from mathics.core.pattern import BasePattern
7170
from mathics.core.rules import BaseRule, FunctionApplyRule, Rule
@@ -93,21 +92,6 @@
9392
from mathics.eval.scoping import dynamic_scoping
9493
from mathics.eval.sympy import eval_sympy
9594

96-
try:
97-
import ujson
98-
except ImportError:
99-
import json as ujson # type: ignore[no-redef]
100-
101-
ROOT_DIR = pkg_resources.resource_filename("mathics", "")
102-
103-
# Load the conversion tables from disk
104-
operator_tables_path = osp.join(ROOT_DIR, "data", "operator-tables.json")
105-
assert osp.exists(
106-
operator_tables_path
107-
), f"Internal error: Operator precedence tables are missing; expected to be in {operator_tables_path}"
108-
with open(operator_tables_path, "r") as f:
109-
OPERATOR_DATA = ujson.load(f)
110-
11195

11296
# Exceptions...
11397
class NegativeIntegerException(Exception):

mathics/core/convert/op.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import os.path as osp
66
from functools import lru_cache
77

8-
import pkg_resources
8+
from mathics.settings import ROOT_DIR
99

1010
try:
1111
import ujson
1212
except ImportError:
1313
import json as ujson # type: ignore[no-redef]
1414

15-
ROOT_DIR = pkg_resources.resource_filename("mathics", "")
1615

1716
# Load the conversion tables from disk
1817
characters_path = osp.join(ROOT_DIR, "data", "op-tables.json")

mathics/core/parser/operators.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@
22
# -*- coding: utf-8 -*-
33

44

5+
import os.path as osp
56
from collections import defaultdict
67

8+
from mathics.settings import ROOT_DIR
9+
10+
try:
11+
import ujson
12+
except ImportError:
13+
import json as ujson # type: ignore[no-redef]
14+
15+
# Load the conversion tables from disk
16+
operator_tables_path = osp.join(ROOT_DIR, "data", "operator-tables.json")
17+
assert osp.exists(
18+
operator_tables_path
19+
), f"Internal error: Operator precedence tables are missing; expected to be in {operator_tables_path}"
20+
with open(operator_tables_path, "r") as f:
21+
OPERATOR_DATA = ujson.load(f)
22+
23+
724
prefix_ops = {
825
"Get": 720,
926
"PreIncrement": 660,

0 commit comments

Comments
 (0)