Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Oct 3, 2021
2 parents 7f2bfd1 + 5e04a85 commit f74f7e9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/sage/doctest/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
except ImportError:
pass

from sage.features.sagemath import sage_optional_tags
auto_optional_tags.update(sage_optional_tags())

class DocTestDefaults(SageObject):
"""
This class is used for doctesting the Sage doctest module.
Expand Down
4 changes: 3 additions & 1 deletion src/sage/doctest/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .external import available_software

float_regex = re.compile(r'\s*([+-]?\s*((\d*\.?\d+)|(\d+\.?))([eE][+-]?\d+)?)')
optional_regex = re.compile(r'(arb216|arb218|py2|py3|long time|not implemented|not tested|known bug)|([^ a-z]\s*optional\s*[:-]*((\s|\w)*))')
optional_regex = re.compile(r'(arb216|arb218|py2|py3|long time|not implemented|not tested|known bug)|([^ a-z]\s*optional\s*[:-]*((\s|\w|[.])*))')
# Version 4.65 of glpk prints the warning "Long-step dual simplex will
# be used" frequently. When Sage uses a system installation of glpk
# which has not been patched, we need to ignore that message.
Expand Down Expand Up @@ -316,6 +316,8 @@ def parse_optional_tags(string):
{''}
sage: sorted(list(parse_optional_tags("sage: #optional -- foo bar, baz")))
['bar', 'foo']
sage: parse_optional_tags("sage: #optional -- foo.bar, baz")
{'foo.bar'}
sage: sorted(list(parse_optional_tags(" sage: factor(10^(10^10) + 1) # LoNg TiME, NoT TeSTED; OptioNAL -- P4cka9e")))
['long time', 'not tested', 'p4cka9e']
sage: parse_optional_tags(" sage: raise RuntimeError # known bug")
Expand Down
56 changes: 56 additions & 0 deletions src/sage/features/sagemath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
r"""
Check for SageMath Python modules
"""
from . import PythonModule


class sage__combinat(PythonModule):

def __init__(self):
# sage.combinat will be a namespace package.
# Testing whether sage.combinat itself can be imported is meaningless.
# Hence, we test a Python module within the package.
PythonModule.__init__(self, 'sage.combinat.combinations')


class sage__graphs(PythonModule):

def __init__(self):
PythonModule.__init__(self, 'sage.graphs.graph')


class sage__rings__real_double(PythonModule):

def __init__(self):
PythonModule.__init__(self, 'sage.rings.real_double')


class sage__symbolic(PythonModule):

def __init__(self):
PythonModule.__init__(self, 'sage.symbolic.expression', spkg="sagemath_symbolics")


def sage_optional_tags():
"""
Return tags for conditionalizing doctests.
These tags are named after Python packages/modules (e.g., :mod:`~sage.symbolic`),
not distribution packages (``sagemath-symbolics``).
This is motivated by a separation of concerns: The author of a module that depends
on some functionality provided by a Python module usually already knows the
name of the Python module, so we do not want to force the author to also
know about the distribution package that provides the Python module.
Instead, we associate distribution packages to Python modules in
:mod:`sage.features.sagemath` via the ``spkg`` parameter of :class:`PythonModule``.
"""
if sage__combinat().is_present():
yield 'sage.combinat'
if sage__graphs().is_present():
yield 'sage.graphs'
if sage__rings__real_double().is_present():
yield 'sage.rings.real_double'
if sage__symbolic().is_present():
yield 'sage.symbolic'

0 comments on commit f74f7e9

Please sign in to comment.