def __init__(self): self.title = "Overview" self.parts = [] self.parts_by_slug = {} dir = settings.DOC_DIR files = listdir(dir) files.sort() appendix = [] for file in files: part_title = file[2:] if part_title.endswith('.mdoc'): part_title = part_title[:-len('.mdoc')] part = DocPart(self, part_title) text = open(dir + file, 'r').read().decode('utf8') text = filter_comments(text) chapters = CHAPTER_RE.findall(text) for title, text in chapters: chapter = DocChapter(part, title) text += '<section title=""></section>' sections = SECTION_RE.findall(text) for pre_text, title, text in sections: if not chapter.doc: chapter.doc = Doc(pre_text) if title: section = DocSection(chapter, title, text) chapter.sections.append(section) part.chapters.append(chapter) if file[0].isdigit(): self.parts.append(part) else: part.is_appendix = True appendix.append(part) for title, modules, builtins_by_module, start in [( # nopep8 "Reference of built-in symbols", builtin.modules, builtin.builtins_by_module, True)]: #("Reference of optional symbols", optional.modules, # optional.optional_builtins_by_module, False)]: builtin_part = DocPart(self, title, is_reference=start) for module in modules: title, text = get_module_doc(module) chapter = DocChapter(builtin_part, title, Doc(text)) builtins = builtins_by_module[module.__name__] for instance in builtins: section = DocSection( chapter, strip_system_prefix(instance.get_name()), instance.__doc__ or '', operator=instance.get_operator()) chapter.sections.append(section) builtin_part.chapters.append(chapter) self.parts.append(builtin_part) for part in appendix: self.parts.append(part) # set keys of tests for tests in self.get_tests(): for test in tests.tests: test.key = ( tests.part, tests.chapter, tests.section, test.index)
def __init__(self): self.title = "Overview" self.parts = [] self.parts_by_slug = {} dir = settings.DOC_DIR files = listdir(dir) files.sort() appendix = [] for file in files: part_title = file[2:] if part_title.endswith('.mdoc'): part_title = part_title[:-len('.mdoc')] part = DocPart(self, part_title) text = open(dir + file, 'r').read().decode('utf8') text = filter_comments(text) chapters = CHAPTER_RE.findall(text) for title, text in chapters: chapter = DocChapter(part, title) text += '<section title=""></section>' sections = SECTION_RE.findall(text) for pre_text, title, text in sections: if not chapter.doc: chapter.doc = Doc(pre_text) if title: section = DocSection(chapter, title, text) chapter.sections.append(section) part.chapters.append(chapter) if file[0].isdigit(): self.parts.append(part) else: part.is_appendix = True appendix.append(part) for title, modules, builtins_by_module, start in [( # nopep8 "Reference of built-in symbols", builtin.modules, builtin.builtins_by_module, True)]: #("Reference of optional symbols", optional.modules, # optional.optional_builtins_by_module, False)]: builtin_part = DocPart(self, title, is_reference=start) for module in modules: title, text = get_module_doc(module) chapter = DocChapter(builtin_part, title, Doc(text)) builtins = builtins_by_module[module.__name__] for instance in builtins: section = DocSection(chapter, instance.get_name(), instance.__doc__ or '', operator=instance.get_operator()) chapter.sections.append(section) builtin_part.chapters.append(chapter) self.parts.append(builtin_part) for part in appendix: self.parts.append(part) # set keys of tests for tests in self.get_tests(): for test in tests.tests: test.key = (tests.part, tests.chapter, tests.section, test.index)
def __init__(self): self.title = "Overview" self.parts = [] self.parts_by_slug = {} self.doc_dir = settings.DOC_DIR self.xml_data_file = settings.DOC_XML_DATA self.tex_data_file = settings.DOC_TEX_DATA self.latex_file = settings.DOC_LATEX_FILE self.pymathics_doc_loaded = False files = listdir(self.doc_dir) files.sort() appendix = [] for file in files: part_title = file[2:] if part_title.endswith('.mdoc'): part_title = part_title[:-len('.mdoc')] part = DocPart(self, part_title) text = open(self.doc_dir + file, 'rb').read().decode('utf8') text = filter_comments(text) chapters = CHAPTER_RE.findall(text) for title, text in chapters: chapter = DocChapter(part, title) text += '<section title=""></section>' sections = SECTION_RE.findall(text) for pre_text, title, text in sections: if not chapter.doc: chapter.doc = Doc(pre_text) if title: section = DocSection(chapter, title, text) chapter.sections.append(section) part.chapters.append(chapter) if file[0].isdigit(): self.parts.append(part) else: part.is_appendix = True appendix.append(part) for title, modules, builtins_by_module, start in [ ("Reference of Built-in Symbols", builtin.modules, builtin.builtins_by_module, True) ]: # nopep8 # ("Reference of optional symbols", optional.modules, # optional.optional_builtins_by_module, False)]: builtin_part = DocPart(self, title, is_reference=start) for module in modules: title, text = get_module_doc(module) chapter = DocChapter(builtin_part, title, Doc(text)) builtins = builtins_by_module[module.__name__] for instance in builtins: installed = True for package in getattr(instance, 'requires', []): try: importlib.import_module(package) except ImportError: installed = False break section = DocSection(chapter, strip_system_prefix( instance.get_name()), instance.__doc__ or '', operator=instance.get_operator(), installed=installed) chapter.sections.append(section) builtin_part.chapters.append(chapter) self.parts.append(builtin_part) for part in appendix: self.parts.append(part) # set keys of tests for tests in self.get_tests(): for test in tests.tests: test.key = (tests.part, tests.chapter, tests.section, test.index)
def __init__(self, module=None): self.title = "Overview" self.parts = [] self.parts_by_slug = {} self.doc_dir = None self.xml_data_file = None self.tex_data_file = None self.latex_file = None self.symbols = {} if module is None: return import importlib # Load the module and verifies it is a pymathics module try: self.pymathicsmodule = importlib.import_module(module) except ImportError: print("Module does not exist") mainfolder = "" self.pymathicsmodule = None self.parts = [] return try: mainfolder = self.pymathicsmodule.__path__[0] if "name" in self.pymathicsmodule.pymathics_version_data: self.name = self.version = self.pymathicsmodule.pymathics_version_data[ 'name'] else: self.name = (self.pymathicsmodule.__package__)[10:] self.version = self.pymathicsmodule.pymathics_version_data[ 'version'] self.author = self.pymathicsmodule.pymathics_version_data['author'] except (AttributeError, KeyError, IndexError): print(module + " is not a pymathics module.") mainfolder = "" self.pymathicsmodule = None self.parts = [] return # Paths self.doc_dir = self.pymathicsmodule.__path__[0] + "/doc/" self.xml_data_file = self.doc_dir + "xml/data" self.tex_data_file = self.doc_dir + "tex/data" self.latex_file = self.doc_dir + "tex/documentation.tex" # Load the dictionary of mathics symbols defined in the module self.symbols = {} from mathics.builtin import is_builtin, Builtin print("loading symbols") for name in dir(self.pymathicsmodule): var = getattr(self.pymathicsmodule, name) if (hasattr(var, '__module__') and var.__module__ != 'mathics.builtin.base' and is_builtin(var) and not name.startswith('_') and var.__module__[:len(self.pymathicsmodule.__name__)] == self.pymathicsmodule.__name__): # nopep8 instance = var(expression=False) if isinstance(instance, Builtin): self.symbols[instance.get_name()] = instance # Defines de default first part, in case we are building an independent documentation module. self.title = "Overview" self.parts = [] self.parts_by_slug = {} try: files = listdir(self.doc_dir) files.sort() except FileNotFoundError: self.doc_dir = "" self.xml_data_file = "" self.tex_data_file = "" self.latex_file = "" files = [] appendix = [] for file in files: part_title = file[2:] if part_title.endswith('.mdoc'): part_title = part_title[:-len('.mdoc')] part = DocPart(self, part_title) text = open(self.doc_dir + file, 'rb').read().decode('utf8') text = filter_comments(text) chapters = CHAPTER_RE.findall(text) for title, text in chapters: chapter = DocChapter(part, title) text += '<section title=""></section>' sections = SECTION_RE.findall(text) for pre_text, title, text in sections: if not chapter.doc: chapter.doc = Doc(pre_text) if title: section = DocSection(chapter, title, text) chapter.sections.append(section) part.chapters.append(chapter) if file[0].isdigit(): self.parts.append(part) else: part.is_appendix = True appendix.append(part) # Builds the automatic documentation builtin_part = DocPart(self, "Pymathics Modules", is_reference=True) title, text = get_module_doc(self.pymathicsmodule) chapter = DocChapter(builtin_part, title, Doc(text)) for name in self.symbols: instance = self.symbols[name] installed = True for package in getattr(instance, 'requires', []): try: importlib.import_module(package) except ImportError: installed = False break section = DocSection(chapter, strip_system_prefix(name), instance.__doc__ or '', operator=instance.get_operator(), installed=installed) chapter.sections.append(section) builtin_part.chapters.append(chapter) self.parts.append(builtin_part) # Adds possible appendices for part in appendix: self.parts.append(part) # set keys of tests for tests in self.get_tests(): for test in tests.tests: test.key = (tests.part, tests.chapter, tests.section, test.index)
def __init__(self): self.doc_data_file = DOC_DATA_PATH self.doc_dir = settings.DOC_DIR self.parts = [] self.parts_by_slug = {} self.pymathics_doc_loaded = False self.title = "Overview" files = listdir(self.doc_dir) files.sort() appendix = [] for file in files: part_title = file[2:] if part_title.endswith(".mdoc"): part_title = part_title[:-len(".mdoc")] part = DjangoDocPart(self, part_title) text = open(self.doc_dir + file, "rb").read().decode("utf8") text = filter_comments(text) chapters = CHAPTER_RE.findall(text) for title, text in chapters: chapter = DjangoDocChapter(part, title) text += '<section title=""></section>' sections = SECTION_RE.findall(text) for pre_text, title, text in sections: if title: section = DjangoDocSection(chapter, title, text, operator=None, installed=True) chapter.sections.append(section) subsections = SUBSECTION_RE.findall(text) for subsection_title in subsections: subsection = DjangoDocSubsection( chapter, section, subsection_title, text, ) section.subsections.append(subsection) pass pass else: section = None if not chapter.doc: chapter.doc = DjangoDoc(pre_text, title, section) pass part.chapters.append(chapter) if file[0].isdigit(): self.parts.append(part) else: part.is_appendix = True appendix.append(part) for title, modules, builtins_by_module, start in [( "Reference of Built-in Symbols", builtin.modules, builtin.builtins_by_module, True, )]: # nopep8 # ("Reference of optional symbols", optional.modules, # optional.optional_builtins_by_module, False)]: builtin_part = DjangoDocPart(self, title, is_reference=start) modules_seen = set([]) for module in modules: # FIXME add an additional mechanism in the module # to allow a docstring and indicate it is not to go in the # user manual if module.__doc__ is None: continue if module in modules_seen: continue title, text = get_module_doc(module) chapter = DjangoDocChapter(builtin_part, title, DjangoDoc(text, title, None)) builtins = builtins_by_module[module.__name__] # FIXME: some Box routines, like RowBox *are* # documented sections = [ builtin for builtin in builtins if not builtin.__class__.__name__.endswith("Box") ] if module.__file__.endswith("__init__.py"): # We have a Guide Section. name = get_doc_name_from_module(module) self.add_section(chapter, name, module, operator=None, is_guide=True) submodules = [ value for value in module.__dict__.values() if isinstance(value, ModuleType) ] # Add sections in the guide section... for submodule in submodules: # FIXME add an additional mechanism in the module # to allow a docstring and indicate it is not to go in the # user manual if submodule.__doc__ is None: continue if submodule in modules_seen: continue section = self.add_section( chapter, get_doc_name_from_module(submodule), submodule, operator=None, is_guide=False, ) modules_seen.add(submodule) builtins = builtins_by_module[submodule.__name__] subsections = [ builtin for builtin in builtins if not builtin.__class__.__name__.endswith("Box") ] for instance in subsections: modules_seen.add(instance) name = instance.get_name(short=True) self.add_subsection( chapter, section, instance.get_name(short=True), instance, instance.get_operator(), in_guide=False, ) else: for instance in sections: if instance not in modules_seen: name = instance.get_name(short=True) self.add_section( chapter, instance.get_name(short=True), instance, instance.get_operator(), is_guide=False, in_guide=False, ) modules_seen.add(instance) builtin_part.chapters.append(chapter) self.parts.append(builtin_part) for part in appendix: self.parts.append(part) # set keys of tests for tests in self.get_tests(): for test in tests.tests: test.key = (tests.part, tests.chapter, tests.section, test.index)