-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
documentation: automatically generate documentation from all .py file…
…s in xDSL (#3758) Excludes: - `__main__.py` files - `_`-prefixed files - `xdsl/irdl/error.py` as it contains a function called `error` which confuses the doc mechanism for some reason - `xdsl/ir/*.py` as we've already got curated docs for these files Still needs a bit of cleanup and to merge the code changes separately. The big question for this PR is whether we want to commit these files and, if not, how do we review them?
- Loading branch information
1 parent
5c96c6e
commit bba4671
Showing
5 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
docs/mlir_interoperation.md → docs/guides/mlir_interoperation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Generate the code reference pages and navigation.""" | ||
|
||
from pathlib import Path | ||
|
||
import mkdocs_gen_files | ||
from mkdocs_gen_files.nav import Nav | ||
|
||
nav = Nav() | ||
|
||
root = Path(__file__).parent.parent | ||
src = root / "xdsl" | ||
|
||
for path in sorted(src.rglob("*.py")): | ||
module_path = path.relative_to(src).with_suffix("") | ||
doc_path = path.relative_to(src).with_suffix(".md") | ||
full_doc_path = Path("reference", doc_path) | ||
|
||
parts = tuple(module_path.parts) | ||
|
||
if parts[-1] == "__init__": | ||
parts = parts[:-1] | ||
doc_path = doc_path.with_name("index.md") | ||
full_doc_path = full_doc_path.with_name("index.md") | ||
elif parts[-1] == "__main__": | ||
continue | ||
elif parts[-1].startswith("_"): | ||
continue | ||
if not parts: | ||
continue | ||
|
||
if "ir" == parts[0]: | ||
# IR is documented separately | ||
continue | ||
|
||
ident = ".".join(parts) | ||
|
||
if ident in ("irdl.error",): | ||
# TODO: rename error function, treated as circular reference | ||
continue | ||
|
||
nav[parts] = doc_path.as_posix() | ||
|
||
with mkdocs_gen_files.open(full_doc_path, "w") as fd: | ||
fd.write(f"::: xdsl.{ident}") | ||
|
||
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root)) | ||
|
||
with mkdocs_gen_files.open("reference/index.md", "w") as nav_file: | ||
nav_file.writelines(nav.build_literate_nav()) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.