Skip to content

Commit

Permalink
Reduce custom doc code...
Browse files Browse the repository at this point in the history
DRY code. docpipeline.py `-l` `--pymathics` probably works now

These changes cannot get merge before
Mathics3/mathics-core#778 is merged.
  • Loading branch information
rocky committed Feb 5, 2023
1 parent 8ee560f commit 2026f7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion mathics_django/doc/django_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def __init__(
self.section = section
self.slug = slugify(title)
self.title = title

if section:
chapter = section.chapter
part = chapter.part
Expand All @@ -437,7 +438,7 @@ def __init__(
# Tests haven't been picked out yet from the doc string yet.
# Gather them here.
self.items = gather_tests(
self.text, DjangoDocTests, DjangoDocTest, DjangoDocText, key_prefix
text, DjangoDocTests, DjangoDocTest, DjangoDocText, key_prefix
)
else:
self.items = []
Expand Down
27 changes: 18 additions & 9 deletions mathics_django/docpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from mathics.core.definitions import Definitions
from mathics.core.evaluation import Evaluation, Output
from mathics.core.parser import MathicsSingleLineFeeder
from mathics.eval.pymathics import PyMathicsLoadException, eval_LoadModule

from mathics_django.doc import MathicsDjangoDocumentation
from mathics_django.settings import get_doc_html_data_path
Expand Down Expand Up @@ -561,10 +562,24 @@ def main():

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

# LoadModule Mathics3 modules
if args.pymathics:
for module_name in args.pymathics.split(","):
try:
eval_LoadModule(module_name, definitions)
except PyMathicsLoadException:
print(f"Python module {module_name} is not a Mathics3 module.")

except ImportError:
print(f"Python module {module_name} does not exist")
else:
print(f"Mathics3 Module {module_name} loaded")

documentation.gather_doc_data()

if args.sections:
sections = set(args.sections.split(","))
if args.pymathics: # in case the section is in a pymathics module...
documentation.load_pymathics_doc()

test_sections(
sections,
Expand All @@ -574,18 +589,12 @@ def main():
)
elif args.chapters:
chapters = set(args.chapters.split(","))
if args.pymathics: # in case the section is in a pymathics module...
documentation.load_pymathics_doc()

test_chapters(
chapters, stop_on_failure=args.stop_on_failure, reload=args.reload
)
else:
# if we want to check also the pymathics modules
if args.pymathics:
print("Building pymathics documentation object")
documentation.load_pymathics_doc(want_sorting=args.want_sorting)
elif args.doc_only:
if args.doc_only:
extract_doc_from_source(
quiet=args.quiet,
reload=args.reload,
Expand Down

0 comments on commit 2026f7f

Please sign in to comment.