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

Tiny changes to tiny changes 2 #995

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 17 additions & 23 deletions mathics/doc/common_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
located in static files and docstrings from
Mathics3 Builtin Modules. Builtin Modules are written in Python and
reside either in the Mathics3 core (mathics.builtin) or are packaged outside,
e.g. pymathics.natlang.
in Mathics3 Modules e.g. pymathics.natlang.

This data is stored in a way that facilitates:
* organizing information to produce a LaTeX file
Expand Down Expand Up @@ -35,7 +35,7 @@
import re
from os import environ, getenv, listdir
from types import ModuleType
from typing import Callable, Iterator, List, Optional, Tuple
from typing import Callable, List, Optional, Tuple

from mathics import settings
from mathics.core.builtin import check_requires_list
Expand Down Expand Up @@ -694,13 +694,9 @@ def get_subsection(self, part_slug, chapter_slug, section_slug, subsection_slug)

return None

def get_tests(self, want_sorting=False):
def get_tests(self):
for part in self.parts:
if want_sorting:
chapter_collection_fn = lambda x: sorted_chapters(x)
else:
chapter_collection_fn = lambda x: x
for chapter in chapter_collection_fn(part.chapters):
for chapter in sorted_chapters(part.chapters):
tests = chapter.doc.get_tests()
if tests:
yield Tests(part.title, chapter.title, "", tests)
Expand Down Expand Up @@ -1046,6 +1042,10 @@ def add_subsection(
section.subsections.append(subsection)

def doc_chapter(self, module, part, builtins_by_module) -> Optional[DocChapter]:
"""
Build documentation structure for a "Chapter" - reference section which
might be a Mathics Module.
"""
modules_seen = set([])

title, text = get_module_doc(module)
Expand Down Expand Up @@ -1130,8 +1130,8 @@ def doc_chapter(self, module, part, builtins_by_module) -> Optional[DocChapter]:

def doc_part(self, title, modules, builtins_by_module, start):
"""
Produce documentation for a "Part" - reference section or
possibly Pymathics modules
Build documentation structure for a "Part" - Reference
section or collection of Mathics3 Modules.
"""

builtin_part = self.part_class(self, title, is_reference=start)
Expand All @@ -1143,20 +1143,9 @@ def doc_part(self, title, modules, builtins_by_module, start):
# packages inside ``mathics.builtin``.
modules_seen = set([])

want_sorting = True
if want_sorting:
module_collection_fn = lambda x: sorted(
modules,
key=lambda module: module.sort_order
if hasattr(module, "sort_order")
else module.__name__,
)
else:
module_collection_fn = lambda x: x

def filter_toplevel_modules(module_list):
"""
Keep just the modules at the top level
Keep just the modules at the top level.
"""
if len(module_list) == 0:
return module_list
Expand All @@ -1176,7 +1165,12 @@ def filter_toplevel_modules(module_list):
# which can be decomposed in the way proposed in #984.

modules = filter_toplevel_modules(modules)
for module in module_collection_fn(modules):
for module in sorted(
modules,
key=lambda module: module.sort_order
if hasattr(module, "sort_order")
else module.__name__,
):
if skip_module_doc(module, modules_seen):
continue
chapter = self.doc_chapter(module, builtin_part, builtins_by_module)
Expand Down
23 changes: 2 additions & 21 deletions mathics/docpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def test_chapters(
stop_on_failure=False,
generate_output=False,
reload=False,
want_sorting=False,
keep_going=False,
):
failed = 0
Expand Down Expand Up @@ -294,7 +293,6 @@ def test_sections(
stop_on_failure=False,
generate_output=False,
reload=False,
want_sorting=False,
keep_going=False,
):
failed = 0
Expand Down Expand Up @@ -354,7 +352,6 @@ def test_all(
texdatafolder=None,
doc_even_if_error=False,
excludes=[],
want_sorting=False,
):
if not quiet:
print(f"Testing {version_string}")
Expand All @@ -371,7 +368,7 @@ def test_all(
total = failed = skipped = 0
failed_symbols = set()
output_data = {}
for tests in documentation.get_tests(want_sorting=want_sorting):
for tests in documentation.get_tests():
sub_total, sub_failed, sub_skipped, symbols, index = test_tests(
tests,
index,
Expand Down Expand Up @@ -608,21 +605,6 @@ def main():
action="store_true",
help="print cache statistics",
)
# FIXME: historically was weird interacting going on with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah!

# mathics when tests in sorted order. Possibly a
# mpmath precsion reset bug.
# We see a noticeable 2 minute delay in processing.
# WHile the problem is in Mathics itself rather than
# sorting, until we get this fixed, use
# sort as an option only. For normal testing we don't
# want it for speed. But for document building which is
# rarely done, we do want sorting of the sections and chapters.
parser.add_argument(
"--want-sorting",
dest="want_sorting",
action="store_true",
help="Sort chapters and sections",
)
global logfile

args = parser.parse_args()
Expand All @@ -635,7 +617,7 @@ def main():
logfile = open(args.logfilename, "wt")

global documentation
documentation = MathicsMainDocumentation(want_sorting=args.want_sorting)
documentation = MathicsMainDocumentation()

# LoadModule Mathics3 modules
if args.pymathics:
Expand Down Expand Up @@ -686,7 +668,6 @@ def main():
count=args.count,
doc_even_if_error=args.keep_going,
excludes=excludes,
want_sorting=args.want_sorting,
)
end_time = datetime.now()
print("Tests took ", end_time - start_time)
Expand Down