Skip to content

Commit 4bb4149

Browse files
committed
Get Mathics3 Modules to loading properly ...
This needs the doc-code-rebased-rebased branch of Mathics core.
1 parent a2be2e0 commit 4bb4149

File tree

6 files changed

+42
-54
lines changed

6 files changed

+42
-54
lines changed

.github/workflows/osx.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
# For testing 3.11 we need to do something like the below until the next Mathics3 is released
3131
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
3232
# python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
33-
git clone https://github.com/Mathics3/mathics-core
33+
git clone --branch doc-code-rebased-rebased https://github.com/Mathics3/mathics-core
3434
(cd mathics-core && pip3 install -e .[full])
3535
(cd mathics-core && bash ./admin-tools/make-op-tables.sh)
3636
- name: Install Mathics3 Django

.github/workflows/ubuntu.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# For testing 3.11 we need to do something like the below until the next Mathics3 is released
3030
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
3131
# python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
32-
git clone https://github.com/Mathics3/mathics-core
32+
git clone --branch clone doc-code-rebased-rebased https://github.com/Mathics3/mathics-core
3333
(cd mathics-core && pip3 install -e .[full])
3434
(cd mathics-core && bash ./admin-tools/make-op-tables.sh)
3535
- name: Install Mathics3 Django

.github/workflows/windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# For testing 3.11 we need to do something like the below until the next Mathics3 is released
3333
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
3434
# python -m pip install -e git+https://github.com/Mathics3/mathics-core#egg=Mathics3[full]
35-
git clone https://github.com/Mathics3/mathics-core
35+
git clone --branch doc-code-rebased-rebased https://github.com/Mathics3/mathics-core
3636
bash -c '(cd mathics-core && pip3 install -e .[full])'
3737
bash -c '(cd mathics-core && bash ./admin-tools/make-op-tables.sh)'
3838
- name: Install Mathics3 Django

mathics_django/doc/django_doc.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
DocTests,
1919
DocText,
2020
Documentation,
21-
XMLDoc,
21+
DocumentationEntry,
2222
gather_tests,
2323
get_results_by_test,
2424
sorted_chapters,
@@ -80,7 +80,7 @@ def __init__(self):
8080
self.section_class = DjangoDocSection
8181
self.subsection_class = DjangoDocSubsection
8282

83-
self.gather_doctest_data()
83+
self.load_documentation_sources()
8484
self.doctest_latex_pcl_path = settings.DOCTEST_LATEX_DATA_PCL
8585
self.pymathics_doc_loaded = False
8686
self.doc_data_file = settings.get_doctest_latex_data_path(
@@ -148,7 +148,7 @@ def search_sections(section, result):
148148
return sorted_results
149149

150150

151-
class DjangoDoc(XMLDoc):
151+
class DjangoDoc(DocumentationEntry):
152152
def __init__(self, doc, title, section, key_prefix=None):
153153
self.title = title
154154
if key_prefix is None:

mathics_django/docpipeline.py

+3-17
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717
import mathics
1818
import mathics.docpipeline as md
1919
from mathics.core.definitions import Definitions
20-
from mathics.core.load_builtin import (
21-
builtins_by_module,
22-
builtins_dict,
23-
import_and_load_builtins,
24-
)
20+
from mathics.core.load_builtin import import_and_load_builtins
21+
from mathics.doc.utils import open_ensure_dir
2522
from mathics.docpipeline import (
2623
MAX_TESTS,
27-
create_output,
28-
open_ensure_dir,
29-
print_and_log,
3024
test_all,
3125
test_chapters,
3226
test_sections,
@@ -38,13 +32,6 @@
3832
from mathics_django.settings import get_doctest_html_data_path
3933

4034

41-
def load_doc_data():
42-
doc_html_data_path = get_doctest_html_data_path(should_be_readable=True)
43-
print(f"Loading internal document data from {doc_html_data_path}")
44-
with open_ensure_dir(doc_html_data_path, "rb") as doc_data_file:
45-
return pickle.load(doc_data_file)
46-
47-
4835
def save_doctest_data(output_data):
4936
"""
5037
Save doctest tests and test results to a Python PCL file.
@@ -207,7 +194,7 @@ def main():
207194
else:
208195
print(f"Mathics3 Module {module_name} loaded")
209196

210-
md.DOCUMENTATION.gather_doctest_data()
197+
# md.DOCUMENTATION.load_documentation_sources()
211198

212199
start_time = None
213200
total = 0
@@ -244,7 +231,6 @@ def main():
244231
generate_output=args.output,
245232
stop_on_failure=args.stop_on_failure,
246233
start_at=start_at,
247-
count=args.count,
248234
doc_even_if_error=args.keep_going,
249235
excludes=excludes,
250236
)

mathics_django/web/controllers/doc.py

+33-31
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from django.core.handlers.wsgi import WSGIRequest
99
from django.http import Http404, HttpResponse
1010
from django.shortcuts import render
11-
from mathics.doc.common_doc import get_module_doc, mathics3_module_part
11+
from mathics.doc.common_doc import MATHICS3_MODULES_TITLE
12+
from mathics.doc.utils import slugify
1213
from mathics.eval.pymathics import pymathics_builtins_by_module, pymathics_modules
1314

1415
from mathics_django.doc import documentation
@@ -23,37 +24,38 @@
2324

2425
seen_pymathics_modules = copy(pymathics_modules)
2526

27+
MATHICS3_MODULES_SLUG = slugify(MATHICS3_MODULES_TITLE)
2628

27-
def check_for_pymathics_load():
29+
30+
def check_for_new_load_modules():
31+
"""
32+
See if we have laoded any new Mathics3 modules since the last time
33+
we checked. If so get an add the documenation for that.
34+
"""
2835
global seen_pymathics_modules
2936
if seen_pymathics_modules != pymathics_modules:
30-
print("XXX refresh pymathics doc", pymathics_modules)
31-
new_modules = pymathics_modules - seen_pymathics_modules
32-
for new_module in new_modules:
33-
title, _ = get_module_doc(new_module)
34-
chapter = mathics3_module_part.doc.gather_chapter_doc_fn(
35-
mathics3_module_part,
36-
title,
37-
mathics3_module_part.doc,
38-
)
39-
from trepan.api import debug
40-
41-
debug()
42-
submodule_names_seen = set()
43-
chapter.doc.doc_chapter(
44-
new_module,
45-
mathics3_module_part,
46-
pymathics_builtins_by_module,
47-
seen_pymathics_modules,
48-
submodule_names_seen,
49-
)
50-
chapter.get_tests()
37+
mathics3_module_part = documentation.parts_by_slug.get(
38+
MATHICS3_MODULES_SLUG, None
39+
)
40+
if mathics3_module_part is None:
41+
print("Something is wrong: mathics3_module variable should not be None")
42+
return
43+
else:
44+
# The "Mathics3 modules" part already exists; add the new chapters.
45+
new_modules = pymathics_modules - seen_pymathics_modules
46+
for new_module in new_modules:
47+
chapter = documentation.doc_chapter(
48+
new_module, mathics3_module_part, pymathics_builtins_by_module
49+
)
50+
mathics3_module_part.chapters.append(chapter)
51+
pass
52+
pass
5153
seen_pymathics_modules = copy(pymathics_modules)
52-
pass
54+
return
5355

5456

5557
def doc(request: WSGIRequest, ajax: bool = False) -> DocResponse:
56-
check_for_pymathics_load()
58+
check_for_new_load_modules()
5759
return render_doc(
5860
request,
5961
"overview.html",
@@ -73,7 +75,7 @@ def doc_chapter(request: WSGIRequest, part, chapter, ajax: bool = False) -> DocR
7375
* Introduction (in part Manual)
7476
* Procedural Programming (in part Reference of Built-in Symbols)
7577
"""
76-
check_for_pymathics_load()
78+
check_for_new_load_modules()
7779
chapter = documentation.get_chapter(part, chapter)
7880
if not chapter:
7981
raise Http404
@@ -96,7 +98,7 @@ def doc_part(request: WSGIRequest, part, ajax: bool = False) -> DocResponse:
9698
* Manual
9799
* Reference of Built-in Symbols
98100
"""
99-
check_for_pymathics_load()
101+
check_for_new_load_modules()
100102
part = documentation.get_part(part)
101103
if not part:
102104
raise Http404
@@ -113,7 +115,7 @@ def doc_part(request: WSGIRequest, part, ajax: bool = False) -> DocResponse:
113115

114116

115117
def doc_search(request: WSGIRequest) -> DocResponse:
116-
check_for_pymathics_load()
118+
check_for_new_load_modules()
117119
query = request.GET.get("query", "")
118120
result = documentation.search(query)
119121
if len([item for exact, item in result if exact]) <= 1:
@@ -170,7 +172,7 @@ def doc_section(
170172
* A list of builtin-functions under a Guide Section. For example: Color Directives.
171173
The guide section here would be Colors.
172174
"""
173-
check_for_pymathics_load()
175+
check_for_new_load_modules()
174176
section_obj = documentation.get_section(part, chapter, section)
175177
if not section_obj:
176178
raise Http404
@@ -204,7 +206,7 @@ def doc_subsection(
204206
organized in a guide section are tagged as a section rather than a
205207
subsection.)
206208
"""
207-
check_for_pymathics_load()
209+
check_for_new_load_modules()
208210
subsection_obj = documentation.get_subsection(part, chapter, section, subsection)
209211
if not subsection_obj:
210212
raise Http404
@@ -240,7 +242,7 @@ def render_doc(
240242
If ``ajax`` is True the should the ajax URI prefix, e.g. " it we pass the result
241243
242244
"""
243-
check_for_pymathics_load()
245+
check_for_new_load_modules()
244246
object = context.get("object")
245247
context.update(
246248
{

0 commit comments

Comments
 (0)