From 6d2069355873035011ea4fed15376c8ac21581f9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 20 Feb 2024 21:29:45 -0800 Subject: [PATCH 01/17] pyproject.toml: Move metadata here from setup.py --- pyproject.toml | 78 ++++++++++++++++++++++++++++++++++++++++ setup.py | 98 -------------------------------------------------- 2 files changed, 78 insertions(+), 98 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..ee34d27f2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,78 @@ +[build-system] +requires = [ + "setuptools>=61.2", + "cython>=0.15.1; implementation_name!='pypy'" +] + +[project] +name = "Mathics3" +description = "A general-purpose computer algebra system." +dependencies = [ + "Mathics-Scanner >= 1.3.0", + "llvmlite", + "mpmath>=1.2.0", + "numpy<1.27", + "palettable", + # Pillow 9.1.0 supports BigTIFF with big-endian byte order. + # ExampleData image hedy.tif is in this format. + # Pillow 9.2 handles sunflowers.jpg + "pillow >= 9.2", + "pint", + "python-dateutil", + "requests", + "setuptools", + "sympy>=1.8", +] +requires-python = ">=3.7" +readme = "README.rst" +license = {text = "GPL"} +keywords = ["Mathematica", "Wolfram", "Interpreter", "Shell", "Math", "CAS"] +maintainers = [ + {name = "Mathics Group", email = "mathics-devel@googlegroups.com"}, +] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Physics", + "Topic :: Software Development :: Interpreters", +] +dynamic = ["version"] + +[project.urls] +Homepage = "https://mathics.org/" +Downloads = "https://github.com/Mathics3/mathics-core/releases" + +[project.optional-dependencies] +dev = [ + "pexpect", + "pytest", +] +full = [ + "ipywidgets", + "lxml", + "psutil", + "pyocr", + "scikit-image >= 0.17", + "unidecode", + "wordcloud >= 1.9.3", +] +cython = [ + "cython", +] + +[project.scripts] +mathics = "mathics.main:main" + +[tool.setuptools.dynamic] +version = {attr = "mathics.version.__version__"} diff --git a/setup.py b/setup.py index 6fdeb127d..4158aa168 100644 --- a/setup.py +++ b/setup.py @@ -39,54 +39,11 @@ sys, "pypy_version_info" ) -INSTALL_REQUIRES = [ - "Mathics-Scanner >= 1.3.0", -] - -# Ensure user has the correct Python version -# Address specific package dependencies based on Python version -if sys.version_info < (3, 7): - print("Mathics does not support Python %d.%d" % sys.version_info[:2]) - sys.exit(-1) - -INSTALL_REQUIRES += [ - "numpy<1.27", - "llvmlite", - "sympy>=1.8", - # Pillow 9.1.0 supports BigTIFF with big-endian byte order. - # ExampleData image hedy.tif is in this format. - # Pillow 9.2 handles sunflowers.jpg - "pillow >= 9.2", -] - -# if not is_PyPy: -# INSTALL_REQUIRES += ["recordclass"] - - def get_srcdir(): filename = osp.normcase(osp.dirname(osp.abspath(__file__))) return osp.realpath(filename) -def read(*rnames): - return open(osp.join(get_srcdir(), *rnames)).read() - - -long_description = read("README.rst") + "\n" - -# stores __version__ in the current namespace -exec(compile(open("mathics/version.py").read(), "mathics/version.py", "exec")) - -EXTRAS_REQUIRE = {} -for kind in ("dev", "full", "cython"): - extras_require = [] - requirements_file = f"requirements-{kind}.txt" - for line in open(requirements_file).read().split("\n"): - if line and not line.startswith("#"): - requires = re.sub(r"([^#]+)(\s*#.*$)?", r"\1", line) - extras_require.append(requires) - EXTRAS_REQUIRE[kind] = extras_require - DEPENDENCY_LINKS = [] # "http://github.com/Mathics3/mathics-scanner/tarball/master#egg=Mathics_Scanner-1.0.0.dev" # ] @@ -134,31 +91,11 @@ def read(*rnames): # for module in modules # ) CMDCLASS = {"build_ext": build_ext} - INSTALL_REQUIRES += ["cython>=0.15.1"] - -# General Requirements -INSTALL_REQUIRES += [ - "mpmath>=1.2.0", - "palettable", - "pint", - "python-dateutil", - "requests", - "setuptools", -] - -print(f'Installation requires "{", ".join(INSTALL_REQUIRES)}') - - -def subdirs(root, file="*.*", depth=10): - for k in range(depth): - yield root + "*/" * k + file setup( - name="Mathics3", cmdclass=CMDCLASS, ext_modules=EXTENSIONS, - version=__version__, packages=[ "mathics", "mathics.algorithm", @@ -199,8 +136,6 @@ def subdirs(root, file="*.*", depth=10): "mathics.doc", "mathics.format", ], - install_requires=INSTALL_REQUIRES, - extras_require=EXTRAS_REQUIRE, dependency_links=DEPENDENCY_LINKS, package_data={ "mathics": [ @@ -225,39 +160,6 @@ def subdirs(root, file="*.*", depth=10): "mathics.builtin.pymimesniffer": ["mimetypes.xml"], "pymathics": ["doc/documentation/*.mdoc", "doc/xml/data"], }, - entry_points={ - "console_scripts": [ - "mathics = mathics.main:main", - ], - }, - long_description=long_description, - long_description_content_type="text/x-rst", # don't pack Mathics in egg because of media files, etc. zip_safe=False, - # metadata for upload to PyPI - maintainer="Mathics Group", - maintainer_email="mathics-devel@googlegroups.com", - description="A general-purpose computer algebra system.", - license="GPL", - url="https://mathics.org/", - download_url="https://github.com/Mathics3/mathics-core/releases", - keywords=["Mathematica", "Wolfram", "Interpreter", "Shell", "Math", "CAS"], - classifiers=[ - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Scientific/Engineering", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Scientific/Engineering :: Physics", - "Topic :: Software Development :: Interpreters", - ], - # TODO: could also include long_description, download_url, ) From 5d141b9606f2db7ad840a3b9e08df46e2ce6b300 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 21 Feb 2024 09:49:16 -0800 Subject: [PATCH 02/17] setup.py: Reformat with black --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 4158aa168..da959da43 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ sys, "pypy_version_info" ) + def get_srcdir(): filename = osp.normcase(osp.dirname(osp.abspath(__file__))) return osp.realpath(filename) From 020e7699944af6a662616be8d00bf15cda9b95fd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 24 Feb 2024 09:51:22 -0800 Subject: [PATCH 03/17] setup.py: Use logging instead of print --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index da959da43..ccab73c00 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ """ +import logging import os import os.path as osp import platform @@ -35,6 +36,9 @@ from setuptools import Extension, setup +log = logging.getLogger(__name__) + + is_PyPy = platform.python_implementation() == "PyPy" or hasattr( sys, "pypy_version_info" ) @@ -61,7 +65,7 @@ def get_srcdir(): pass else: if os.environ.get("USE_CYTHON", False): - print("Running Cython over code base") + log.info("Running Cython over code base") EXTENSIONS_DICT = { "core": ( "expression", From 0d4350daefa8a965700fd2cec4690ed715c2b7b4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 25 Feb 2024 20:48:09 -0800 Subject: [PATCH 04/17] pyproject.toml: Move packages, package-data here from setup.py --- pyproject.toml | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 63 ---------------------------------------------- 2 files changed, 68 insertions(+), 63 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ee34d27f2..92b5262ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,5 +74,73 @@ cython = [ [project.scripts] mathics = "mathics.main:main" +[tool.setuptools] +include-package-data = false +packages = [ + "mathics", + "mathics.algorithm", + "mathics.compile", + "mathics.core", + "mathics.core.convert", + "mathics.core.parser", + "mathics.builtin", + "mathics.builtin.arithfns", + "mathics.builtin.assignments", + "mathics.builtin.atomic", + "mathics.builtin.binary", + "mathics.builtin.box", + "mathics.builtin.colors", + "mathics.builtin.distance", + "mathics.builtin.exp_structure", + "mathics.builtin.drawing", + "mathics.builtin.fileformats", + "mathics.builtin.files_io", + "mathics.builtin.forms", + "mathics.builtin.functional", + "mathics.builtin.image", + "mathics.builtin.intfns", + "mathics.builtin.list", + "mathics.builtin.matrices", + "mathics.builtin.numbers", + "mathics.builtin.numpy_utils", + "mathics.builtin.pymimesniffer", + "mathics.builtin.pympler", + "mathics.builtin.quantum_mechanics", + "mathics.builtin.scipy_utils", + "mathics.builtin.specialfns", + "mathics.builtin.statistics", + "mathics.builtin.string", + "mathics.builtin.testing_expressions", + "mathics.builtin.vectors", + "mathics.eval", + "mathics.doc", + "mathics.format", +] + +[tool.setuptools.package-data] +"mathics" = [ + "data/*.csv", + "data/*.json", + "data/*.yml", + "data/*.yaml", + "data/*.pcl", + "data/ExampleData/*", + "doc/xml/data", + "doc/tex/data", + "autoload/*.m", + "autoload-cli/*.m", + "autoload/formats/*/Import.m", + "autoload/formats/*/Export.m", + "packages/*/*.m", + "packages/*/Kernel/init.m", +] +"mathics.doc" = [ + "documentation/*.mdoc", + "xml/data", +] +"mathics.builtin.pymimesniffer" = [ + "mimetypes.xml", +] + [tool.setuptools.dynamic] version = {attr = "mathics.version.__version__"} diff --git a/setup.py b/setup.py index ccab73c00..19c281690 100644 --- a/setup.py +++ b/setup.py @@ -101,70 +101,7 @@ def get_srcdir(): setup( cmdclass=CMDCLASS, ext_modules=EXTENSIONS, - packages=[ - "mathics", - "mathics.algorithm", - "mathics.compile", - "mathics.core", - "mathics.core.convert", - "mathics.core.parser", - "mathics.builtin", - "mathics.builtin.arithfns", - "mathics.builtin.assignments", - "mathics.builtin.atomic", - "mathics.builtin.binary", - "mathics.builtin.box", - "mathics.builtin.colors", - "mathics.builtin.distance", - "mathics.builtin.exp_structure", - "mathics.builtin.drawing", - "mathics.builtin.fileformats", - "mathics.builtin.files_io", - "mathics.builtin.forms", - "mathics.builtin.functional", - "mathics.builtin.image", - "mathics.builtin.intfns", - "mathics.builtin.list", - "mathics.builtin.matrices", - "mathics.builtin.numbers", - "mathics.builtin.numpy_utils", - "mathics.builtin.pymimesniffer", - "mathics.builtin.pympler", - "mathics.builtin.quantum_mechanics", - "mathics.builtin.scipy_utils", - "mathics.builtin.specialfns", - "mathics.builtin.statistics", - "mathics.builtin.string", - "mathics.builtin.testing_expressions", - "mathics.builtin.vectors", - "mathics.eval", - "mathics.doc", - "mathics.format", - ], dependency_links=DEPENDENCY_LINKS, - package_data={ - "mathics": [ - "data/*.csv", - "data/*.json", - "data/*.yml", - "data/*.yaml", - "data/*.pcl", - "data/ExampleData/*", - "doc/xml/data", - "doc/tex/data", - "autoload/*.m", - "autoload-cli/*.m", - "autoload/formats/*/Import.m", - "autoload/formats/*/Export.m", - "packages/*/*.m", - "packages/*/Kernel/init.m", - "requirements-cython.txt", - "requirements-full.txt", - ], - "mathics.doc": ["documentation/*.mdoc", "xml/data"], - "mathics.builtin.pymimesniffer": ["mimetypes.xml"], - "pymathics": ["doc/documentation/*.mdoc", "doc/xml/data"], - }, # don't pack Mathics in egg because of media files, etc. zip_safe=False, ) From a42d5abb37f9549d04673beb00b6ba039ef445f8 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 12:46:45 -0400 Subject: [PATCH 05/17] Fix mismatched parameter type... Cython is fussier about this? --- mathics/core/pattern.py | 6 +++--- setup.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mathics/core/pattern.py b/mathics/core/pattern.py index 74f81fb9f..581be27fa 100644 --- a/mathics/core/pattern.py +++ b/mathics/core/pattern.py @@ -434,7 +434,7 @@ def yield_choice(pre_vars): self.match_element( yield_func, next_element, - next_elements, + tuple(next_elements), ([], expression.elements), pre_vars, expression, @@ -642,7 +642,7 @@ def yield_next(next): # for setting in per_name(groups.items(), vars): # def yield_name(setting): # yield_func(setting) - per_name(yield_choice, list(groups.items()), vars) + per_name(yield_choice, tuple(groups.items()), vars) else: yield_choice(vars) @@ -861,7 +861,7 @@ def yield_wrapping(item): self.get_wrappings( yield_wrapping, - items, + tuple(items), match_count[1], expression, attributes, diff --git a/setup.py b/setup.py index 19c281690..c57d0b45f 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,6 @@ import os import os.path as osp import platform -import re import sys from setuptools import Extension, setup From 7224dca510d93760cc95ed8f83e4e7300a754de7 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 13:15:32 -0400 Subject: [PATCH 06/17] More tuple declarations/conversions --- mathics/builtin/patterns.py | 2 +- mathics/core/builtin.py | 6 +++--- mathics/core/pattern.py | 4 ++-- mathics/core/util.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mathics/builtin/patterns.py b/mathics/builtin/patterns.py index 0b5f4db25..46a8c433f 100644 --- a/mathics/builtin/patterns.py +++ b/mathics/builtin/patterns.py @@ -1030,7 +1030,7 @@ def match(self, yield_func, expression, vars, evaluation, **kwargs): yield_func(vars, None) def get_match_candidates( - self, elements, expression, attributes, evaluation, vars={} + self, elements: tuple, expression, attributes, evaluation, vars={} ): existing = vars.get(self.varname, None) if existing is None: diff --git a/mathics/core/builtin.py b/mathics/core/builtin.py index 3e26f3a71..bc0dfa928 100644 --- a/mathics/core/builtin.py +++ b/mathics/core/builtin.py @@ -10,7 +10,7 @@ import re from functools import lru_cache, total_ordering from itertools import chain -from typing import Any, Callable, Dict, Iterable, List, Optional, Union, cast +from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union, cast import mpmath import sympy @@ -1122,8 +1122,8 @@ def get_lookup_name(self) -> str: return self.get_name() def get_match_candidates( - self, elements, expression, attributes, evaluation, vars={} - ): + self, elements: Tuple[BaseElement], expression, attributes, evaluation, vars={} + ) -> Tuple[BaseElement]: return elements def get_match_count(self, vars={}): diff --git a/mathics/core/pattern.py b/mathics/core/pattern.py index 581be27fa..8818da1d0 100644 --- a/mathics/core/pattern.py +++ b/mathics/core/pattern.py @@ -261,7 +261,7 @@ def get_match_candidates( evaluation: Evaluation, vars: dict = {}, ): - return [] + return tuple() def get_match_candidates_count( self, @@ -715,7 +715,7 @@ def match_element( match_count = element.get_match_count(vars) element_candidates = element.get_match_candidates( - rest_expression[1], # element.candidates, + tuple(rest_expression[1]), # element.candidates, expression, attributes, evaluation, diff --git a/mathics/core/util.py b/mathics/core/util.py index d8f00f973..4a1be908f 100644 --- a/mathics/core/util.py +++ b/mathics/core/util.py @@ -40,7 +40,7 @@ def permutations(items): item = items[index] # if item not in already_taken: for sub in permutations(items[:index] + items[index + 1 :]): - yield [item] + sub + yield [item] + list(sub) # already_taken.add(item) From 6db7e7e007d39c3f086b68fc61306e2c017e9c28 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 18:02:32 -0400 Subject: [PATCH 07/17] Correct return type annotaation --- mathics/core/atoms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathics/core/atoms.py b/mathics/core/atoms.py index ec70b549b..d5c717c3a 100644 --- a/mathics/core/atoms.py +++ b/mathics/core/atoms.py @@ -428,7 +428,7 @@ def __neg__(self) -> "MachineReal": def do_copy(self) -> "MachineReal": return MachineReal(self._value) - def get_precision(self) -> float: + def get_precision(self) -> int: """Returns the default specification for precision in N and other numerical functions.""" return FP_MANTISA_BINARY_DIGITS From 4dd2f0e8ba7d7863c8956f3ff3cd973e76f7f4b8 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 18:49:09 -0400 Subject: [PATCH 08/17] Fix one more erroneous return type --- mathics/core/number.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathics/core/number.py b/mathics/core/number.py index 4103a5d8b..a0ac12fdd 100644 --- a/mathics/core/number.py +++ b/mathics/core/number.py @@ -136,7 +136,7 @@ def prec(dps) -> int: return max(1, int(round((int(dps) + 1) * LOG2_10))) -def min_prec(*args: BaseElement) -> Optional[float]: +def min_prec(*args: BaseElement) -> Optional[int]: """ Returns the precision of the expression with the minimum precision. If all the expressions are exact or non numeric, return None. From ca74bafc0475744a284ba99a56a589e123960025 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 19:46:36 -0400 Subject: [PATCH 09/17] Use 3.10 with cython 3.11 seems to use to require more stringent cython. While this is a good thing. Right now we should focus on one issue at a time. The issue here is TOM, not 3.11 Cython stringencies --- .github/workflows/ubuntu-cython.yml | 2 +- mathics/core/atoms.py | 7 ++++--- mathics/core/number.py | 2 +- mathics/core/symbols.py | 8 ++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ubuntu-cython.yml b/.github/workflows/ubuntu-cython.yml index eb7cb82b0..c98d9d57d 100644 --- a/.github/workflows/ubuntu-cython.yml +++ b/.github/workflows/ubuntu-cython.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: ['3.11'] + python-version: ['3.10'] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/mathics/core/atoms.py b/mathics/core/atoms.py index d5c717c3a..f55abb451 100644 --- a/mathics/core/atoms.py +++ b/mathics/core/atoms.py @@ -545,9 +545,9 @@ def __neg__(self) -> "PrecisionReal": def do_copy(self) -> "PrecisionReal": return PrecisionReal(self.value) - def get_precision(self) -> float: + def get_precision(self) -> int: """Returns the default specification for precision (in binary digits) in N and other numerical functions.""" - return self.value._prec + 1.0 + return self.value._prec + 1 @property def is_zero(self) -> bool: @@ -801,6 +801,7 @@ def is_machine_precision(self) -> bool: return True return False + # FIXME: funny name get_float_value returns complex? def get_float_value(self, permit_complex=False) -> Optional[complex]: if permit_complex: real = self.real.get_float_value() @@ -810,7 +811,7 @@ def get_float_value(self, permit_complex=False) -> Optional[complex]: else: return None - def get_precision(self) -> Optional[float]: + def get_precision(self) -> Optional[int]: """Returns the default specification for precision in N and other numerical functions. When `None` is be returned no precision is has been defined and this object's value is exact. diff --git a/mathics/core/number.py b/mathics/core/number.py index a0ac12fdd..29439db24 100644 --- a/mathics/core/number.py +++ b/mathics/core/number.py @@ -70,7 +70,7 @@ def _get_float_inf(value, evaluation) -> Optional[float]: def get_precision( value: BaseElement, evaluation, show_messages: bool = True -) -> Optional[float]: +) -> Optional[int]: """ Returns the ``float`` in the interval [``$MinPrecision``, ``$MaxPrecision``] closest to ``value``. diff --git a/mathics/core/symbols.py b/mathics/core/symbols.py index fca9cbd27..c2b122d86 100644 --- a/mathics/core/symbols.py +++ b/mathics/core/symbols.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- import time -from typing import Any, FrozenSet, List, Optional +from typing import Any, FrozenSet, List, Optional, Union from mathics.core.element import ( BaseElement, @@ -830,7 +830,11 @@ def __floordiv__(self, other) -> BaseElement: def __pow__(self, other) -> BaseElement: return self.create_expression(SymbolPower, self, other) - def round_to_float(self, evaluation=None, permit_complex=False) -> Optional[float]: + # FIXME: The name "round_to_float" is misleading when + # permit_complex is True. + def round_to_float( + self, evaluation=None, permit_complex=False + ) -> Optional[Union[complex | float]]: """ Round to a Python float. Return None if rounding is not possible. This can happen if self or evaluation is NaN. From cb7424ed08ba0c31e43aada5534ba3c1f21ee491 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 20:00:37 -0400 Subject: [PATCH 10/17] Small Lint fix to kick CI --- mathics/core/symbols.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mathics/core/symbols.py b/mathics/core/symbols.py index c2b122d86..e5595c5fb 100644 --- a/mathics/core/symbols.py +++ b/mathics/core/symbols.py @@ -666,6 +666,9 @@ class SymbolConstant(Symbol): # We use __new__ here to unsure that two Integer's that have the same value # return the same object. + + _value = None + def __new__(cls, name, value): name = ensure_context(name) self = cls._symbol_constants.get(name) From e96be317b05e3bd2474cd53666bb624e11536aa3 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 20:02:55 -0400 Subject: [PATCH 11/17] 3.8 tolerance --- mathics/core/symbols.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathics/core/symbols.py b/mathics/core/symbols.py index e5595c5fb..1be4ce772 100644 --- a/mathics/core/symbols.py +++ b/mathics/core/symbols.py @@ -837,7 +837,7 @@ def __pow__(self, other) -> BaseElement: # permit_complex is True. def round_to_float( self, evaluation=None, permit_complex=False - ) -> Optional[Union[complex | float]]: + ) -> Optional[Union[complex, float]]: """ Round to a Python float. Return None if rounding is not possible. This can happen if self or evaluation is NaN. From 82e31baf9934acbb9a013e447787a1d63374047c Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 20:11:24 -0400 Subject: [PATCH 12/17] Try a pinned version of Cython --- .github/workflows/ubuntu-cython.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu-cython.yml b/.github/workflows/ubuntu-cython.yml index c98d9d57d..eb7cb82b0 100644 --- a/.github/workflows/ubuntu-cython.yml +++ b/.github/workflows/ubuntu-cython.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: ['3.10'] + python-version: ['3.11'] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/pyproject.toml b/pyproject.toml index 92b5262ac..71f976024 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ full = [ "wordcloud >= 1.9.3", ] cython = [ - "cython", + "cython == 3.0.8", ] [project.scripts] From 712ca8c3a230225544fb1bcd85a836bcb03889b2 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 22:19:48 -0400 Subject: [PATCH 13/17] Try another yet older version of cython --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 71f976024..ce796d0a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ full = [ "wordcloud >= 1.9.3", ] cython = [ - "cython == 3.0.8", + "cython < 3.0.0", ] [project.scripts] From fb579df2930b42836f037985924d9ee5d945b232 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 11 Mar 2024 22:26:23 -0400 Subject: [PATCH 14/17] Revert Cython and address one more return type sig --- mathics/core/element.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mathics/core/element.py b/mathics/core/element.py index 23b6ba8c7..4bac5dd7c 100644 --- a/mathics/core/element.py +++ b/mathics/core/element.py @@ -307,7 +307,7 @@ def get_name(self): def get_option_values(self, evaluation, allow_symbols=False, stop_on_error=True): pass - def get_precision(self) -> Optional[float]: + def get_precision(self) -> Optional[int]: """Returns the default specification for precision in N and other numerical functions. It is expected to be redefined in those classes that provide inexact arithmetic like PrecisionReal. diff --git a/pyproject.toml b/pyproject.toml index ce796d0a1..92b5262ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ full = [ "wordcloud >= 1.9.3", ] cython = [ - "cython < 3.0.0", + "cython", ] [project.scripts] From 5f98ae0bb757ac3c8204e8a9093339f15bb2a83a Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 12 Mar 2024 03:49:15 -0400 Subject: [PATCH 15/17] Another return type correction --- mathics/core/number.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathics/core/number.py b/mathics/core/number.py index 29439db24..0a075b2a6 100644 --- a/mathics/core/number.py +++ b/mathics/core/number.py @@ -4,7 +4,7 @@ import string from math import ceil, log from sys import float_info -from typing import List, Optional +from typing import List, Optional, Union import mpmath import sympy @@ -70,7 +70,7 @@ def _get_float_inf(value, evaluation) -> Optional[float]: def get_precision( value: BaseElement, evaluation, show_messages: bool = True -) -> Optional[int]: +) -> Optional[Union[int, float]]: """ Returns the ``float`` in the interval [``$MinPrecision``, ``$MaxPrecision``] closest to ``value``. From 9a6704cbc1cabebbc734a3697a2a19f6953da675 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 12 Mar 2024 04:09:50 -0400 Subject: [PATCH 16/17] Another paramter type annotation correction --- mathics/eval/makeboxes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mathics/eval/makeboxes.py b/mathics/eval/makeboxes.py index 32213fcfc..1ed651c34 100644 --- a/mathics/eval/makeboxes.py +++ b/mathics/eval/makeboxes.py @@ -7,7 +7,7 @@ import typing -from typing import Any, Dict, Type +from typing import Any, Dict, Optional, Type from mathics.core.atoms import Complex, Integer, Rational, Real, String, SymbolI from mathics.core.convert.expression import to_expression_with_specialization @@ -392,7 +392,10 @@ def do_format_expression( def parenthesize( - precedence: int, element: Type[BaseElement], element_boxes, when_equal: bool + precedence: Optional[int], + element: Type[BaseElement], + element_boxes, + when_equal: bool, ) -> Type[Expression]: """ "Determines if ``element_boxes`` needs to be surrounded with parenthesis. From 1a6c757b153ffda8b9915ca535b163be237da5d0 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 12 Mar 2024 04:38:10 -0400 Subject: [PATCH 17/17] Another type annotation correction for Cython --- mathics/core/expression.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mathics/core/expression.py b/mathics/core/expression.py index f8c93fc9a..f407f9957 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -5,7 +5,7 @@ import time from bisect import bisect_left from itertools import chain -from typing import Any, Callable, Iterable, List, Optional, Tuple, Type +from typing import Any, Callable, Iterable, List, Optional, Tuple, Type, Union import sympy @@ -1356,7 +1356,9 @@ def rules(): # Expr8: to_expression("Plus", n1,..., n1) (nontrivial evaluation to a long expression, with just undefined symbols) # - def round_to_float(self, evaluation=None, permit_complex=False) -> Optional[float]: + def round_to_float( + self, evaluation=None, permit_complex=False + ) -> Optional[Union[float, complex]]: """ Round to a Python float. Return None if rounding is not possible. This can happen if self or evaluation is NaN.