Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build/pkgs/mathics: Reduce to a pip package #37395

Merged
merged 16 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion src/sage/libs/mpmath/ext_main.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ cdef class mpf_base(mpnumber):
sage: X().to_fixed(30)
3489660928
"""
return libmp.to_fixed(self._mpf_, prec)
return libmp.to_fixed(self._mpf_, prec)
mkoeppe marked this conversation as resolved.
Show resolved Hide resolved

def __getstate__(self):
return libmp.to_pickable(self._mpf_)
Expand Down 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)
mkoeppe marked this conversation as resolved.
Show resolved Hide resolved

mkoeppe marked this conversation as resolved.
Show resolved Hide resolved
def __richcmp__(self, other, int op):
"""
Compares numbers ::
Expand Down
Loading