Skip to content

Commit df81cb5

Browse files
authored
Merge pull request #1344 from mathics/test-and-doc-tweaks
Some tweaks to the doc building. Doc submodules...
2 parents 3b130d3 + d028b25 commit df81cb5

7 files changed

Lines changed: 84 additions & 28 deletions

File tree

mathics/builtin/__init__.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,37 @@ def get_module_doc(module):
8585
return title, text
8686

8787
def import_builtins(module_names: List[str], submodule_name=None) -> None:
88-
for module_name in module_names:
89-
import_name = (
90-
f"mathics.builtin.{submodule_name}.{module_name}"
91-
if submodule_name
92-
else f"mathics.builtin.{module_name}"
93-
)
88+
"""
89+
Imports the list of Mathics Built-in modules so that inside
90+
Mathics we have these Builtin Functions, like Plus[], List[] are defined.
91+
92+
"""
93+
def import_module(module_name: str, import_name: str):
9494
try:
9595
module = importlib.import_module(import_name)
9696
except Exception as e:
9797
print(e)
9898
print(f" Not able to load {module_name}. Check your installation.")
9999
print(f" mathics.builtin loads from {__file__[:-11]}")
100-
continue
100+
return None
101101

102102
if __version__ != module.__version__:
103103
print(
104-
f"Version {module.__version__} in the module do not match with {__version__}"
104+
f"Version {module.__version__} in the module does not match top-level Mathics version {__version__}"
105105
)
106+
if module:
107+
modules.append(module)
106108

107-
modules.append(module)
109+
if submodule_name:
110+
import_module(submodule_name, f"mathics.builtin.{submodule_name}")
111+
112+
for module_name in module_names:
113+
import_name = (
114+
f"mathics.builtin.{submodule_name}.{module_name}"
115+
if submodule_name
116+
else f"mathics.builtin.{module_name}"
117+
)
118+
import_module(module_name, import_name)
108119

109120

110121
def is_builtin(var):
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
"""
22
Graphics, Drawing, and Images
3+
4+
Functions like 'Plot' and 'ListPlot' can be used to draw graphs of functions and data.
5+
6+
Graphics is implemented as a collection of <i>graphics primitives</i>. Primatives are objects like 'Point', 'Line', and 'Polygon' and become elements of a <i>graphics object</i>.
7+
8+
A graphics object can have directives as well such as 'RGBColor', and 'Thickness'.
9+
10+
There are several kinds of graphics objects; each kind has a head which identifies its type.
11+
12+
>> ListPlot[ Table[Prime[n], {n, 20} ]]
13+
= -Graphics-
14+
>> Head[%]
15+
= Graphics
16+
>> Graphics3D[Sphere[]]
17+
= -Graphics3D-
18+
>> Head[%]
19+
= Graphics3D
20+
>>
21+
22+
323
"""
24+
25+
from mathics.version import __version__ # noqa used in loading to check consistency.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
"""
22
Input/Output, Files, and Filesystem
33
"""
4+
5+
from mathics.version import __version__ # noqa used in loading to check consistency.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
"""
22
Integer and Number-Theoretical Functions
33
"""
4+
5+
from mathics.version import __version__ # noqa used in loading to check consistency.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
"""
22
Special Functions
3+
4+
There are a number of functions found in mathematical physics and found in standard handbooks.
5+
6+
One thing to note is that the technical literature often contains several conflicting definitions. So beware and check for conformance with the Mathics documentation.
7+
8+
A number of special functions can be evaluated for arbitrary complex values of their arguments. However defining relations may apply only for some special choices of arguments. Here, the full function corresponds to an extension or "analytic continuation" of the defining relation.
9+
10+
For example, integral representations of functions are only valid when the integral exists, but the functions can usually be defined b by analytic continuation.
11+
312
"""
13+
14+
from mathics.version import __version__ # noqa used in loading to check consistency.

mathics/doc/doc.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22

33
import re
4-
from os import getenv, listdir, path
4+
from os import getenv, listdir
55
import pickle
66
import importlib
77

88
from mathics import settings
9+
from html import escape as html_escape
910

1011
from mathics import builtin
1112
from mathics.builtin import get_module_doc
@@ -255,7 +256,9 @@ def repl_list(match):
255256

256257
def repl_char(match):
257258
char = match.group(1)
258-
return {"^": "$^\wedge$",}[char]
259+
return {
260+
"^": "$^\wedge$",
261+
}[char]
259262

260263
text = LATEX_CHAR_RE.sub(repl_char, text)
261264

@@ -614,7 +617,7 @@ def repl_subsection(match):
614617
text = text.replace("\\" + key, xml)
615618

616619
if not single_line:
617-
text = linebreaks(text)
620+
# text = linebreaks(text)
618621
text = text.replace("<br />", "\n").replace("<br>", "<br />")
619622

620623
text = post_sub(text, post_substitutions)
@@ -654,7 +657,7 @@ def get_prev_next(self):
654657
return prev, next
655658

656659
def get_title_html(self):
657-
return mark_safe(escape_html(self.title, single_line=True))
660+
return html_escape(self.title, single_line=True)
658661

659662

660663
class Documentation(DocElement):
@@ -1167,7 +1170,7 @@ def latex(self, output):
11671170

11681171
def html(self):
11691172
counters = {}
1170-
return mark_safe(
1173+
return escape_html(
11711174
"\n".join(
11721175
item.html(counters) for item in self.items if not item.is_private()
11731176
)

mathics/test.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
from mathics.core.parser import MathicsSingleLineFeeder
1616
from mathics.builtin import builtins_dict
1717

18-
builtins = builtins_dict()
19-
2018
from mathics import version_string
2119
from mathics import settings
2220

23-
21+
builtins = builtins_dict()
2422

2523

2624
class TestOutput(Output):
@@ -47,6 +45,7 @@ def print_and_log(*args):
4745
if logfile:
4846
logfile.write(string)
4947

48+
5049
def compare(result, wanted):
5150
if result == wanted:
5251
return True
@@ -93,16 +92,15 @@ def fail(why):
9392
time_parsing = datetime.now()
9493
query = evaluation.parse_feeder(feeder)
9594
if check_partial_enlapsed_time:
96-
print(" parsing took", datetime.now()-time_parsing)
95+
print(" parsing took", datetime.now() - time_parsing)
9796
if query is None:
9897
# parsed expression is None
9998
result = None
10099
out = evaluation.out
101100
else:
102-
time_evaluating = datetime.now()
103101
result = evaluation.evaluate(query)
104102
if check_partial_enlapsed_time:
105-
print(" evaluation took", datetime.now()-time_parsing)
103+
print(" evaluation took", datetime.now() - time_parsing)
106104
out = result.out
107105
result = result.result
108106
except Exception as exc:
@@ -114,7 +112,7 @@ def fail(why):
114112
time_comparing = datetime.now()
115113
comparison_result = compare(result, wanted)
116114
if check_partial_enlapsed_time:
117-
print(" comparison took ", datetime.now()-time_comparing)
115+
print(" comparison took ", datetime.now() - time_comparing)
118116
if not comparison_result:
119117
print("result =!=wanted")
120118
fail_msg = "Result: %s\nWanted: %s" % (result, wanted)
@@ -132,7 +130,7 @@ def fail(why):
132130
output_ok = False
133131
break
134132
if check_partial_enlapsed_time:
135-
print(" comparing messages took ", datetime.now()-time_comparing)
133+
print(" comparing messages took ", datetime.now() - time_comparing)
136134
if not output_ok:
137135
return fail(
138136
"Output:\n%s\nWanted:\n%s"
@@ -199,7 +197,6 @@ def test_section(sections: set, quiet=False, stop_on_failure=False):
199197
sections |= {"$" + s for s in sections}
200198
for tests in documentation.get_tests():
201199
if tests.section in sections:
202-
found = True
203200
for test in tests.tests:
204201
if test.ignore:
205202
continue
@@ -366,11 +363,19 @@ def main():
366363
"--version", "-v", action="version", version="%(prog)s " + mathics.__version__
367364
)
368365
parser.add_argument(
369-
"--sections", "-s", dest="section", metavar="SECTION", help="only test SECTION(s). "
370-
"You can list multiple sections by adding a comma (and no space) in between section names."
366+
"--sections",
367+
"-s",
368+
dest="section",
369+
metavar="SECTION",
370+
help="only test SECTION(s). "
371+
"You can list multiple sections by adding a comma (and no space) in between section names.",
371372
)
372373
parser.add_argument(
373-
"--logfile", "-f", dest="logfilename", metavar="LOGFILENAME", help="stores the output in [logfilename]. "
374+
"--logfile",
375+
"-f",
376+
dest="logfilename",
377+
metavar="LOGFILENAME",
378+
help="stores the output in [logfilename]. ",
374379
)
375380
parser.add_argument(
376381
"--pymathics",
@@ -418,7 +423,7 @@ def main():
418423
help="create documentation even if there is a test failure",
419424
)
420425
parser.add_argument(
421-
"--stop-on-failure", action="store_true", help="stop on failure"
426+
"--stop-on-failure", "-x", action="store_true", help="stop on failure"
422427
)
423428
parser.add_argument(
424429
"--skip",
@@ -443,7 +448,7 @@ def main():
443448
# If a test for a specific section is called
444449
# just test it
445450
if args.logfilename:
446-
logfile = open(args.logfilename,"wt")
451+
logfile = open(args.logfilename, "wt")
447452

448453
if args.section:
449454
sections = set(args.section.split(","))

0 commit comments

Comments
 (0)