Skip to content

Commit

Permalink
update doc generating files
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 27, 2023
1 parent 6379579 commit 34cfd1e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 67 deletions.
12 changes: 7 additions & 5 deletions docs/sort__all__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import compas
from compas import geometry
from compas_blender import conversions as module

functions = []
classes = []
errors = []
numpy = []

__newall__ = {
"functions": [],
"classes": [],
"errors": [],
"functions": [],
"numpy": [],
"pluggables": [],
"plugins": [],
}

for name in geometry.__all__:
obj = getattr(geometry, name)
for name in module.__all__:
obj = getattr(module, name)

if name.endswith("_numpy"):
numpy.append(name)
Expand All @@ -35,4 +37,4 @@
__newall__["numpy"].append(name)


compas.json_dump(__newall__, "docs/geometry__all__.json", pretty=True)
compas.json_dump(__newall__, f"docs/{module.__name__}__all__.json", pretty=True)
135 changes: 73 additions & 62 deletions docs/write_rst.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from compas import geometry
# from pathlib import Path
from compas import numerical as module

TPL = """
********************************************************************************
Expand All @@ -11,108 +11,119 @@
.. rst-class:: lead
{lead}
{sections}
Classes
=======
.. autosummary::
:toctree: generated/
:nosignatures:
{classes}
Functions
=========
.. autosummary::
:toctree: generated/
:nosignatures:
{functions}
Functions using NumPy
=====================
.. autosummary::
:toctree: generated/
:nosignatures:
{numpy}
"""

Pluggables
==========
SECTION = """
{title}
{line}
.. autosummary::
:toctree: generated/
:nosignatures:
{pluggables}
{items}
"""

__newall__ = {
"functions": [],
"classes": [],
"errors": [],
"numpy": [],
"pluggables": [],
"plugins": [],
}

for name in geometry.__all__:
obj = getattr(geometry, name)
for name in module.__all__:
obj = getattr(module, name)

if name.endswith("_numpy"):
__newall__["numpy"].append(name)
continue

if hasattr(obj, "__pluggable__"):
__newall__["pluggables"].append(name)
continue

if hasattr(obj, "__plugin__"):
__newall__["plugins"].append(name)
continue

if isinstance(obj, type):
__newall__["classes"].append(name)
else:
__newall__["functions"].append(name)


currentmodule = "compas.geometry"
currentmodule = module.__name__

lead = """
This package provides a wide range of geometry objects and geometric algorithms
independent from the geometry kernels of CAD software.
"""
lead = module.__doc__

classes = ""
for name in sorted(__newall__["classes"]):
classes += f" {name}\n"
classes += " {name}\n".format(name=name)

if classes:
classes = SECTION.format(
title="Classes",
line="=" * len("Classes"),
items=classes,
)

functions = ""
for name in sorted(__newall__["functions"]):
functions += f" {name}\n"
functions += " {name}\n".format(name=name)

if functions:
functions = SECTION.format(
title="Functions",
line="=" * len("Functions"),
items=functions,
)

numpy = ""
for name in sorted(__newall__["numpy"]):
numpy += f" {name}\n"
numpy += " {name}\n".format(name=name)

if numpy:
numpy = SECTION.format(
title="Numpy",
line="=" * len("Numpy"),
items=numpy,
)

pluggables = ""
# for name in sorted(__newall__["pluggables"]):
# pluggables += f" {name}\n"

# print(
# TPL.format(
# currentmodule=currentmodule,
# lead=lead,
# classes=classes,
# functions=functions,
# numpy="",
# )
# )

docs = Path(__file__).parent

with open(docs / "reference/compas.geometry.rst", "w") as f:
for name in sorted(__newall__["pluggables"]):
pluggables += " {name}\n".format(name=name)

if pluggables:
pluggables = SECTION.format(
title="Pluggables",
line="=" * len("Pluggables"),
items=pluggables,
)

plugins = ""
for name in sorted(__newall__["plugins"]):
plugins += " {name}\n".format(name=name)

if plugins:
plugins = SECTION.format(
title="Plugins",
line="=" * len("Plugins"),
items=plugins,
)

sections = "".join([classes, functions, numpy, pluggables, plugins])

# docs = Path(__file__).parent

with open("/Users/vanmelet/Code/compas/docs/reference/{name}.rst".format(name=module.__name__), "w") as f:
f.write(
TPL.format(
currentmodule=currentmodule,
lead=lead,
classes=classes,
functions=functions,
numpy=numpy,
pluggables=pluggables,
sections=sections,
)
)

0 comments on commit 34cfd1e

Please sign in to comment.