8
8
from django .core .handlers .wsgi import WSGIRequest
9
9
from django .http import Http404 , HttpResponse
10
10
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
12
13
from mathics .eval .pymathics import pymathics_builtins_by_module , pymathics_modules
13
14
14
15
from mathics_django .doc import documentation
23
24
24
25
seen_pymathics_modules = copy (pymathics_modules )
25
26
27
+ MATHICS3_MODULES_SLUG = slugify (MATHICS3_MODULES_TITLE )
26
28
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
+ """
28
35
global seen_pymathics_modules
29
36
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
51
53
seen_pymathics_modules = copy (pymathics_modules )
52
- pass
54
+ return
53
55
54
56
55
57
def doc (request : WSGIRequest , ajax : bool = False ) -> DocResponse :
56
- check_for_pymathics_load ()
58
+ check_for_new_load_modules ()
57
59
return render_doc (
58
60
request ,
59
61
"overview.html" ,
@@ -73,7 +75,7 @@ def doc_chapter(request: WSGIRequest, part, chapter, ajax: bool = False) -> DocR
73
75
* Introduction (in part Manual)
74
76
* Procedural Programming (in part Reference of Built-in Symbols)
75
77
"""
76
- check_for_pymathics_load ()
78
+ check_for_new_load_modules ()
77
79
chapter = documentation .get_chapter (part , chapter )
78
80
if not chapter :
79
81
raise Http404
@@ -96,7 +98,7 @@ def doc_part(request: WSGIRequest, part, ajax: bool = False) -> DocResponse:
96
98
* Manual
97
99
* Reference of Built-in Symbols
98
100
"""
99
- check_for_pymathics_load ()
101
+ check_for_new_load_modules ()
100
102
part = documentation .get_part (part )
101
103
if not part :
102
104
raise Http404
@@ -113,7 +115,7 @@ def doc_part(request: WSGIRequest, part, ajax: bool = False) -> DocResponse:
113
115
114
116
115
117
def doc_search (request : WSGIRequest ) -> DocResponse :
116
- check_for_pymathics_load ()
118
+ check_for_new_load_modules ()
117
119
query = request .GET .get ("query" , "" )
118
120
result = documentation .search (query )
119
121
if len ([item for exact , item in result if exact ]) <= 1 :
@@ -170,7 +172,7 @@ def doc_section(
170
172
* A list of builtin-functions under a Guide Section. For example: Color Directives.
171
173
The guide section here would be Colors.
172
174
"""
173
- check_for_pymathics_load ()
175
+ check_for_new_load_modules ()
174
176
section_obj = documentation .get_section (part , chapter , section )
175
177
if not section_obj :
176
178
raise Http404
@@ -204,7 +206,7 @@ def doc_subsection(
204
206
organized in a guide section are tagged as a section rather than a
205
207
subsection.)
206
208
"""
207
- check_for_pymathics_load ()
209
+ check_for_new_load_modules ()
208
210
subsection_obj = documentation .get_subsection (part , chapter , section , subsection )
209
211
if not subsection_obj :
210
212
raise Http404
@@ -240,7 +242,7 @@ def render_doc(
240
242
If ``ajax`` is True the should the ajax URI prefix, e.g. " it we pass the result
241
243
242
244
"""
243
- check_for_pymathics_load ()
245
+ check_for_new_load_modules ()
244
246
object = context .get ("object" )
245
247
context .update (
246
248
{
0 commit comments