Skip to content

Commit

Permalink
gh-37395: build/pkgs/mathics: Reduce to a pip package
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Our Mathics package is outdated (and also the interface shows test
failures in CI - e.g. in https://github.com/sagemath/sage/actions/runs/7
894201915/job/21638423818#step:14:3279)

Trying to update Mathics reveals more dependencies, include scikit-image
and llvm-lite.

Here we reduce it to a "pip" package to simplify maintenance of the
package on our side.

The latest released version 6.0.4 fails to install in Sage because of
rigid version constraints.

We are using the current HEAD version (7.0.0dev), which includes
- Mathics3/mathics-core#1014
- Mathics3/mathics-core#1034

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #37395
Reported by: Matthias Köppe
Reviewer(s): Matthias Köppe, Sebastian Oehms
  • Loading branch information
Release Manager committed Jul 20, 2024
2 parents 27cfbba + 5ba18ea commit 0c506c2
Show file tree
Hide file tree
Showing 37 changed files with 42 additions and 127 deletions.
4 changes: 0 additions & 4 deletions build/pkgs/mathics/checksums.ini

This file was deleted.

2 changes: 1 addition & 1 deletion build/pkgs/mathics/dependencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| $(PYTHON_TOOLCHAIN) pint palettable mathics_scanner $(PYTHON)
numpy pillow mpmath dateutil requests sympy pyyaml charset_normalizer typing_extensions | $(PYTHON_TOOLCHAIN) $(PYTHON)

----------
All lines of this file are ignored except the first.
1 change: 0 additions & 1 deletion build/pkgs/mathics/package-version.txt

This file was deleted.

3 changes: 3 additions & 0 deletions build/pkgs/mathics/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Mathics3 @ git+https://github.com/Mathics3/mathics-core
mathics-scanner @ git+https://github.com/Mathics3/mathics-scanner
-c ${SAGE_VENV}/var/lib/sage/scripts/numpy/spkg-requirements.txt
2 changes: 0 additions & 2 deletions build/pkgs/mathics/spkg-install.in

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/mathics/version_requirements.txt

This file was deleted.

18 changes: 0 additions & 18 deletions build/pkgs/mathics_scanner/SPKG.rst

This file was deleted.

4 changes: 0 additions & 4 deletions build/pkgs/mathics_scanner/checksums.ini

This file was deleted.

4 changes: 0 additions & 4 deletions build/pkgs/mathics_scanner/dependencies

This file was deleted.

Empty file removed build/pkgs/mathics_scanner/math
Empty file.
1 change: 0 additions & 1 deletion build/pkgs/mathics_scanner/package-version.txt

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/mathics_scanner/spkg-configure.m4

This file was deleted.

2 changes: 0 additions & 2 deletions build/pkgs/mathics_scanner/spkg-install.in

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/mathics_scanner/type

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/mathics_scanner/version_requirements.txt

This file was deleted.

16 changes: 0 additions & 16 deletions build/pkgs/palettable/SPKG.rst

This file was deleted.

4 changes: 0 additions & 4 deletions build/pkgs/palettable/checksums.ini

This file was deleted.

4 changes: 0 additions & 4 deletions build/pkgs/palettable/dependencies

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/palettable/distros/conda.txt

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/palettable/package-version.txt

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/palettable/spkg-configure.m4

This file was deleted.

2 changes: 0 additions & 2 deletions build/pkgs/palettable/spkg-install.in

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/palettable/type

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/palettable/version_requirements.txt

This file was deleted.

18 changes: 0 additions & 18 deletions build/pkgs/pint/SPKG.rst

This file was deleted.

4 changes: 0 additions & 4 deletions build/pkgs/pint/checksums.ini

This file was deleted.

4 changes: 0 additions & 4 deletions build/pkgs/pint/dependencies

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/pint/distros/conda.txt

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/pint/package-version.txt

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/pint/spkg-configure.m4

This file was deleted.

2 changes: 0 additions & 2 deletions build/pkgs/pint/spkg-install.in

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/pint/type

This file was deleted.

1 change: 0 additions & 1 deletion build/pkgs/pint/version_requirements.txt

This file was deleted.

4 changes: 3 additions & 1 deletion src/sage/doctest/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ def external_features():
import sage.features.ffmpeg
yield from sage.features.ffmpeg.all_features()
import sage.features.interfaces
yield from sage.features.interfaces.all_features()
for feature in sage.features.interfaces.all_features():
if feature.name != 'mathics':
yield feature
from sage.features.mip_backends import CPLEX, Gurobi
yield CPLEX()
yield Gurobi()
Expand Down
19 changes: 19 additions & 0 deletions src/sage/features/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ def _is_present(self):
reason=f"Interface {interface} is not functional: {exception}")


class Mathics(InterfaceFeature):
r"""
A :class:`~sage.features.Feature` describing whether :class:`sage.interfaces.mathics.Mathics`
is present and functional.
EXAMPLES::
sage: from sage.features.interfaces import Mathics
sage: Mathics().is_present() # not tested
FeatureTestResult('mathics', False)
"""

@staticmethod
def __classcall__(cls):
return InterfaceFeature.__classcall__(cls, 'mathics', 'sage.interfaces.mathics')


# The following are provided by external software only (no SPKG)

class Magma(InterfaceFeature):
Expand Down Expand Up @@ -223,6 +240,7 @@ def all_features():
[Feature('magma'),
Feature('matlab'),
Feature('mathematica'),
Feature('mathics'),
Feature('maple'),
Feature('macaulay2'),
Feature('octave'),
Expand All @@ -231,6 +249,7 @@ def all_features():
return [Magma(),
Matlab(),
Mathematica(),
Mathics(),
Maple(),
Macaulay2(),
Octave(),
Expand Down
34 changes: 13 additions & 21 deletions src/sage/interfaces/mathics.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
::
sage: mathics('10.^80') # optional - mathics
1.*^80
1.×10^80
sage: mathics('10.^80').sage() # optional - mathics
1.00000000000000e80
Expand Down Expand Up @@ -483,6 +483,7 @@ def __init__(self,
self._seed = seed
self._initialized = False # done lazily
self._session = None
os.environ['MATHICS_CHARACTER_ENCODING'] = 'ASCII' # see :issue:`37395`

def _lazy_init(self):
r"""
Expand Down Expand Up @@ -512,6 +513,8 @@ def _start(self):
"""
if not self._session:
from mathics.session import MathicsSession
from mathics.core.load_builtin import import_and_load_builtins
import_and_load_builtins()
self._session = MathicsSession()
from sage.interfaces.sympy import sympy_init
sympy_init()
Expand Down Expand Up @@ -601,7 +604,7 @@ def get(self, var):
sage: mathics.set('u', '2*x +E') # optional - mathics
sage: mathics.get('u') # optional - mathics
'E + 2 x'
'2 x + E'
"""
return self.eval(var)

Expand Down Expand Up @@ -717,9 +720,9 @@ def _exponent_symbol(self):
sage: bignum = mathics('10.^80') # optional - mathics
sage: repr(bignum) # optional - mathics
'1.*^80'
'1.×10^80'
sage: repr(bignum).replace(mathics._exponent_symbol(), 'e').strip() # optional - mathics
'1.e80'
'1.×10^80'
"""
return '*^'

Expand Down Expand Up @@ -772,34 +775,25 @@ def help(self, cmd, long=False):
EXAMPLES::
sage: mathics.help('Sin') # optional - mathics
"\n 'Sin[z]'\n returns the sine of z.\n"
'sine function\n'
sage: print(_) # optional - mathics
<BLANKLINE>
'Sin[z]'
returns the sine of z.
sine function
<BLANKLINE>
sage: print(mathics.help('Sin', long=True)) # optional - mathics
<BLANKLINE>
'Sin[z]'
returns the sine of z.
sine function
<BLANKLINE>
Attributes[Sin] = {Listable, NumericFunction, Protected}
<BLANKLINE>
sage: print(mathics.Factorial.__doc__) # optional - mathics
<BLANKLINE>
'Factorial[n]'
'n!'
computes the factorial of n.
factorial
<BLANKLINE>
sage: u = mathics('Pi') # optional - mathics
sage: print(u.Cos.__doc__) # optional - mathics
<BLANKLINE>
'Cos[z]'
returns the cosine of z.
cosine function
<BLANKLINE>
"""
if long:
Expand Down Expand Up @@ -852,7 +846,7 @@ class MathicsElement(ExtraTabCompletion, InterfaceElement):
sage: expr = res.last_eval; expr
<Symbol: System`E>
sage: type(expr)
<class 'mathics.core.expression.Symbol'>
<class 'mathics.core.symbols.Symbol'>
Applying Mathics methods::
Expand All @@ -863,8 +857,6 @@ class MathicsElement(ExtraTabCompletion, InterfaceElement):
'System`E'
sage: me.is_inexact()
False
sage: me.is_symbol()
True
Conversion to Sage::
Expand Down
3 changes: 3 additions & 0 deletions src/sage/libs/mpmath/ext_main.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,9 @@ cdef class mpf(mpf_base):
MPF_sqrt(&r.value, &s.value, global_opts)
return r

def __round__(self, *args):
return round(float(self), *args)

def __richcmp__(self, other, int op):
"""
Compares numbers ::
Expand Down

0 comments on commit 0c506c2

Please sign in to comment.