Skip to content

Commit 9572a48

Browse files
committed
some of the rocky's changes in #202
1 parent bcd523c commit 9572a48

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed

mathics_django/doc/django_doc.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
from mathics_django.settings import get_doctest_html_data_path
3232

3333
# FIXME: remove globalness
34+
doctest_html_data_path = get_doctest_html_data_path(should_be_readable=True)
3435
try:
35-
doctest_html_data_path = get_doctest_html_data_path(should_be_readable=True)
3636
with open(doctest_html_data_path, "rb") as doctest_html_data_file:
3737
doc_data = pickle.load(doctest_html_data_file)
3838
except IOError:
@@ -43,9 +43,9 @@
4343
class DjangoDocElement:
4444
def href(self, ajax=False):
4545
if ajax:
46-
return "javascript:loadDoc('%s')" % self.get_uri()
46+
return f"javascript:loadDoc('{self.get_uri()}')"
4747
else:
48-
return "/doc%s" % self.get_uri()
48+
return f"/doc{self.get_uri()}"
4949

5050
def get_prev(self):
5151
return self.get_prev_next()[0]
@@ -212,7 +212,6 @@ def get_tests(self):
212212
return tests
213213

214214
def html(self):
215-
counters = {}
216215
items = [item for item in self.items if not item.is_private()]
217216
title_line = self.title + "\n"
218217
if len(items) and items[0].text.startswith(title_line):
@@ -221,7 +220,7 @@ def html(self):
221220
# Or that is the intent. This code is a bit hacky.
222221
items[0].text = items[0].text[len(title_line) :]
223222

224-
text = "\n".join(item.html(counters) for item in items if not item.is_private())
223+
text = "\n".join(item.html() for item in items if not item.is_private())
225224
if text == "":
226225
# HACK ALERT if text is "" we may have missed some test markup.
227226
return mark_safe(escape_html(self.rawdoc))
@@ -262,7 +261,7 @@ def get_collection(self):
262261
"""Return a list of parts in this doc"""
263262
return self.doc.parts
264263

265-
def html(self, counters=None):
264+
def html(self):
266265
if len(self.tests) == 0:
267266
return "\n"
268267
return '<ul class="tests">%s</ul>' % (
@@ -302,8 +301,7 @@ def __init__(
302301

303302
if text.count("<dl>") != text.count("</dl>"):
304303
raise ValueError(
305-
"Missing opening or closing <dl> tag in "
306-
"{} documentation".format(title)
304+
f"Missing opening or closing <dl> tag in {title} documentation"
307305
)
308306

309307
# Needs to come after self.chapter is initialized since
@@ -364,8 +362,7 @@ def __init__(
364362

365363
if text.count("<dl>") != text.count("</dl>"):
366364
raise ValueError(
367-
"Missing opening or closing <dl> tag in "
368-
"{} documentation".format(title)
365+
f"Missing opening or closing <dl> tag in {title} documentation"
369366
)
370367
# print("YYY Adding section", title)
371368
chapter.sections_by_slug[self.slug] = self
@@ -450,8 +447,7 @@ def __init__(
450447

451448
if text.count("<dl>") != text.count("</dl>"):
452449
raise ValueError(
453-
"Missing opening or closing <dl> tag in "
454-
"{} documentation".format(title)
450+
f"Missing opening or closing <dl> tag in {title} documentation"
455451
)
456452
self.section.subsections_by_slug[self.slug] = self
457453

@@ -520,7 +516,7 @@ def html(self) -> str:
520516

521517

522518
class DjangoDocTests(DocTests):
523-
def html(self, counters=None):
519+
def html(self):
524520
if len(self.tests) == 0:
525521
return "\n"
526522
return '<ul class="tests">%s</ul>' % (
@@ -531,6 +527,6 @@ def html(self, counters=None):
531527

532528

533529
class DjangoDocText(DocText):
534-
def html(self, counters=None) -> str:
535-
result = escape_html(self.text, counters=counters)
530+
def html(self) -> str:
531+
result = escape_html(self.text)
536532
return result

mathics_django/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def get_bool_from_environment(env_var: str, default_value: str):
7474
)
7575

7676
# We need another version as a fallback, and that is distributed with the
77-
# package. It is note user writable and not in the user space.
77+
# package. It is not user writable and not in the user space.
7878
DOC_SYSTEM_HTML_DATA_PATH = os.environ.get(
7979
"DOC_SYSTEM_HTML_DATA_PATH", osp.join(ROOT_DIR, "doc", "doc_html_data.pcl")
8080
)

mathics_django/web/controllers/doc.py

+43-8
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.eval.pymathics import pymathics_modules
11+
from mathics.doc.common_doc import get_module_doc
12+
from mathics.eval.pymathics import pymathics_builtins_by_module, pymathics_modules
1213

1314
from mathics_django.doc import documentation
1415
from mathics_django.doc.django_doc import (
@@ -21,12 +22,47 @@
2122

2223
DocResponse = Union[HttpResponse, JsonResponse]
2324

25+
seen_pymathics_modules = copy(pymathics_modules)
26+
27+
2428

2529
def check_for_pymathics_load():
30+
global seen_pymathics_modules
2631
if seen_pymathics_modules != pymathics_modules:
27-
# print("XXX refresh pymathics doc")
28-
global documentation
29-
documentation = MathicsDjangoDocumentation()
32+
print("XXX refresh pymathics doc", pymathics_modules)
33+
new_modules = pymathics_modules - seen_pymathics_modules
34+
for new_module in new_modules:
35+
title, _ = get_module_doc(new_module)
36+
mathics3_module_part = documentation.parts_by_slug.get("Mathics3 Modules", None)
37+
# If this is the first loaded module, we need to create the Part
38+
if mathics3_module_part is None:
39+
mathics3_module_part = self.doc_part(
40+
"Mathics3 Modules", pymathics_modules, pymathics_builtins_by_module, True
41+
)
42+
seen_pymathics_modules = copy(pymathics_modules)
43+
return
44+
45+
# The part already exists. Lets add the new chapter.
46+
47+
chapter = mathics3_module_part.doc.gather_chapter_doc_fn(
48+
mathics3_module_part,
49+
title,
50+
mathics3_module_part.doc,
51+
)
52+
from trepan.api import debug
53+
54+
debug()
55+
submodule_names_seen = set()
56+
chapter.doc.doc_chapter(
57+
new_module,
58+
mathics3_module_part,
59+
pymathics_builtins_by_module,
60+
seen_pymathics_modules,
61+
submodule_names_seen,
62+
)
63+
chapter.get_tests()
64+
seen_pymathics_modules = copy(pymathics_modules)
65+
pass
3066

3167

3268
def doc(request: WSGIRequest, ajax: bool = False) -> DocResponse:
@@ -44,7 +80,9 @@ def doc(request: WSGIRequest, ajax: bool = False) -> DocResponse:
4480

4581
def doc_chapter(request: WSGIRequest, part, chapter, ajax: bool = False) -> DocResponse:
4682
"""
47-
Produces HTML via jinja templating for a chapter. Some examples of Chapters:
83+
Produces HTML via jinja templating for a chapter. Some examples of
84+
Chapters:
85+
4886
* Introduction (in part Manual)
4987
* Procedural Programming (in part Reference of Built-in Symbols)
5088
"""
@@ -87,9 +125,6 @@ def doc_part(request: WSGIRequest, part, ajax: bool = False) -> DocResponse:
87125
)
88126

89127

90-
seen_pymathics_modules = copy(pymathics_modules)
91-
92-
93128
def doc_search(request: WSGIRequest) -> DocResponse:
94129
check_for_pymathics_load()
95130
query = request.GET.get("query", "")

mathics_django/web/templates/about.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ <h1>Connection Information</h1>
165165

166166
<p>Mathics3 is a general-purpose computer algebra system.</p>
167167

168-
<p>Copyright (C) 2021-2023 The Mathics3 Team<p><br>
168+
<p>Copyright (C) 2021-2024 The Mathics3 Team<p><br>
169169

170170
This program comes with ABSOLUTELY NO WARRANTY;
171171
This is free software, and you are welcome to redistribute it

0 commit comments

Comments
 (0)