From 45bbc3be850ee14ef78f091a83c8d4b0d6e42a6c Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 18 Jan 2024 19:09:31 -0500 Subject: [PATCH 1/3] Convert % to fstrings via flynt --- mathics/core/evaluation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mathics/core/evaluation.py b/mathics/core/evaluation.py index a45b172f3..af4401a7e 100644 --- a/mathics/core/evaluation.py +++ b/mathics/core/evaluation.py @@ -471,7 +471,7 @@ def message(self, symbol_name: str, tag, *msgs) -> "Message": symbol_shortname = self.definitions.shorten_name(symbol) if settings.DEBUG_PRINT: - print("MESSAGE: %s::%s (%s)" % (symbol_shortname, tag, msgs)) + print(f"MESSAGE: {symbol_shortname}::{tag} ({msgs})") text = self.definitions.get_value(symbol, "System`Messages", pattern, self) if text is None: @@ -481,7 +481,7 @@ def message(self, symbol_name: str, tag, *msgs) -> "Message": ) if text is None: - text = String("Message %s::%s not found." % (symbol_shortname, tag)) + text = String(f"Message {symbol_shortname}::{tag} not found.") text = self.format_output( Expression(SymbolStringForm, text, *(from_python(arg) for arg in msgs)), @@ -587,8 +587,9 @@ def __init__(self, symbol: Union[Symbol, str], tag: str, text: str) -> None: use a string. tag: a short slug string that indicates the kind of message - In Django we need to use a string for symbol, since we need something that is JSON serializable - and a Mathics3 Symbol is not like this. + In Django we need to use a string for symbol, since we need + something that is JSON serializable and a Mathics3 Symbol is not + like this. """ super(Message, self).__init__() self.is_message = True # Why do we need this? @@ -607,7 +608,7 @@ def get_data(self): "message": True, "symbol": self.symbol, "tag": self.tag, - "prefix": "%s::%s" % (self.symbol, self.tag), + "prefix": f"{self.symbol}::{self.tag}", "text": self.text, } From 633fd20d040b1d93b3d676c956643e1a770cb75d Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 18 Jan 2024 20:34:00 -0500 Subject: [PATCH 2/3] Administrivia and lint items... graphics3d.py: lint complains about imports not being at the top. exceptions.py: add a couple of docstrings requirements-full.txt. We need 1.9.3 or later. Pre 1.9.3 image.textsize is used and that is not supported by new image routines (image.textbbox is) --- mathics/builtin/box/graphics.py | 3 +- mathics/builtin/box/graphics3d.py | 5 ++- mathics/builtin/colors/color_directives.py | 3 -- mathics/builtin/graphics.py | 52 +--------------------- mathics/core/exceptions.py | 6 +++ requirements-full.txt | 2 +- 6 files changed, 14 insertions(+), 57 deletions(-) diff --git a/mathics/builtin/box/graphics.py b/mathics/builtin/box/graphics.py index 3adcec70e..b52d03d15 100644 --- a/mathics/builtin/box/graphics.py +++ b/mathics/builtin/box/graphics.py @@ -1097,7 +1097,8 @@ def init(self, graphics, style, item=None): if item is not None: if len(item.elements) != 1: - raise BoxExpressionError(item) + print("item:", item) + raise BoxExpressionError points = item.elements[0] if points.has_form("List", None) and len(points.elements) != 0: if all( diff --git a/mathics/builtin/box/graphics3d.py b/mathics/builtin/box/graphics3d.py index df8b53c67..f5564102c 100644 --- a/mathics/builtin/box/graphics3d.py +++ b/mathics/builtin/box/graphics3d.py @@ -2,8 +2,6 @@ """ Boxing Symbols for 3D Graphics """ -# Docs are not yet ready for prime time. Maybe after release 6.0.0. -no_doc = True import json import numbers @@ -27,6 +25,9 @@ from mathics.core.symbols import Symbol, SymbolTrue from mathics.eval.nevaluator import eval_N +# Docs are not yet ready for prime time. Maybe after release 6.0.0. +no_doc = True + class Graphics3DBox(GraphicsBox): """ diff --git a/mathics/builtin/colors/color_directives.py b/mathics/builtin/colors/color_directives.py index 0fbfcd1e7..e8063dc37 100644 --- a/mathics/builtin/colors/color_directives.py +++ b/mathics/builtin/colors/color_directives.py @@ -156,9 +156,6 @@ class _ColorObject(_GraphicsDirective, ImmutableValueMixin): components_sizes = [] default_components = [] - def __repr__(self): - return f"Color object of type {type(self)} with components:{ self.components}" - def init(self, item=None, components=None): super(_ColorObject, self).init(None, item) if item is not None: diff --git a/mathics/builtin/graphics.py b/mathics/builtin/graphics.py index 07eee791a..cadc86314 100644 --- a/mathics/builtin/graphics.py +++ b/mathics/builtin/graphics.py @@ -26,11 +26,10 @@ get_class, ) from mathics.builtin.options import options_to_rules -from mathics.core.atoms import Integer, Integer0, Integer1, Rational, Real +from mathics.core.atoms import Integer, Rational, Real from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED from mathics.core.builtin import Builtin from mathics.core.convert.expression import to_expression, to_mathics_list -from mathics.core.convert.python import from_python from mathics.core.exceptions import BoxExpressionError from mathics.core.expression import Expression from mathics.core.formatter import lookup_method @@ -1089,7 +1088,6 @@ def stylebox_style(style, specs): return new_style def convert(content, style): - failed = [] if content.has_form("List", None): items = content.elements else: @@ -1110,9 +1108,6 @@ def convert(content, style): yield element elif head.name[-3:] == "Box": # and head[:-3] in element_heads: element_class = get_class(head) - if element_class is None: - failed.append(head) - yield None options = get_options(head.name[:-3]) if options: data, options = _data_and_options(item.elements, options) @@ -1125,52 +1120,9 @@ def convert(content, style): for element in convert(item, style): yield element else: - failed.append(head) - - if failed: - messages = "\n".join( - [ - f"str(h) is not a valid primitive or directive." - for h in failed - ] - ) - style = style.klass( - style.graphics, - edge=RGBColor(components=(1, 0, 0)), - face=RGBColor(components=(1, 0, 0, 0.25)), - ) - if isinstance(self, GraphicsElements): - error_primitive_head = Symbol("PolygonBox") - error_primitive_expression = Expression( - error_primitive_head, - from_python([(-1, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)]), - ) - else: - error_primitive_head = Symbol("Polygon3DBox") - error_primitive_expression = Expression( - error_primitive_head, - from_python( - [ - (-1, 0, -1), - (1, 0, -1), - (1, 0.01, 1), - (-1, 0.01, 1), - (-1, 0, -1), - ] - ), - ) - error_box = get_class(error_primitive_head)( - self, style=style, item=error_primitive_expression - ) - error_box.face_color = RGBColor(components=(1, 0, 0, 0.25)) - error_box.edge_color = RGBColor(components=(1, 0, 0)) - yield error_box - - # print("I am a ", type(self)) - # raise BoxExpressionError(messages) + raise BoxExpressionError self.elements = list(convert(content, self.style_class(self))) - print("elements:", tuple(e for e in self.elements)) def create_style(self, expr): style = self.style_class(self) diff --git a/mathics/core/exceptions.py b/mathics/core/exceptions.py index 06a0e2ff3..e1c7cb179 100644 --- a/mathics/core/exceptions.py +++ b/mathics/core/exceptions.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +""" +Various Exception objects used in Mathics3. +""" class BoxExpressionError(Exception): @@ -35,4 +38,7 @@ def __init__(self, *message): self._message = message def message(self, evaluation): + """ + Transfer this exception to evaluation's ``message`` method. + """ evaluation.message(*self._message) diff --git a/requirements-full.txt b/requirements-full.txt index 4514496f2..529cc51b7 100644 --- a/requirements-full.txt +++ b/requirements-full.txt @@ -5,4 +5,4 @@ psutil # SystemMemory and MemoryAvailable pyocr # Used for TextRecognize scikit-image >= 0.17 # FindMinimum can use this; used by Image as well unidecode # Used in Transliterate -wordcloud # Used in builtin/image.py by WordCloud() +wordcloud >= 1.9.3 # Used in builtin/image.py by WordCloud(). Previous versions assume "image.textsize" which no longer exists From 801cc98c197e2f3c5912b2628a0f2a3f925f088f Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 19 Jan 2024 04:43:10 -0500 Subject: [PATCH 3/3] Docs deferred after 7.0 release now. --- mathics/builtin/box/graphics3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathics/builtin/box/graphics3d.py b/mathics/builtin/box/graphics3d.py index f5564102c..03f3ac8ec 100644 --- a/mathics/builtin/box/graphics3d.py +++ b/mathics/builtin/box/graphics3d.py @@ -25,7 +25,7 @@ from mathics.core.symbols import Symbol, SymbolTrue from mathics.eval.nevaluator import eval_N -# Docs are not yet ready for prime time. Maybe after release 6.0.0. +# Docs are not yet ready for prime time. Maybe after release 7.0.0. no_doc = True