From d90b40b29c2e7ae994b224b71731e0a9b6b16cd4 Mon Sep 17 00:00:00 2001 From: tomvanmele Date: Thu, 29 Feb 2024 09:24:14 +0100 Subject: [PATCH] fix docs --- docs/conf.py | 7 +- pyproject.toml | 2 +- src/compas_dr/constraints/constraint.py | 2 +- src/compas_dr/loads/selfweight.py | 7 +- src/compas_dr/solvers/dr_constrained_numpy.py | 2 +- src/compas_dr/types.py | 19 +++++ tasks.py | 85 +++++++++++++++++-- 7 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 src/compas_dr/types.py diff --git a/docs/conf.py b/docs/conf.py index df38f97..ada62d6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -44,12 +44,7 @@ # autodoc options autodoc_type_aliases = { - # "Vertices": "compas_cgal.types.Vertices", - # "Faces": "compas_cgal.types.Faces", - # "VerticesFaces": "compas_cgal.types.VerticesFaces", - # "VerticesFacesNumpy": "compas_cgal.types.VerticesFacesNumpy", - # "PolylinesNumpy": "compas_cgal.types.PolylinesNumpy", - # "Planes": "compas_cgal.types.Planes", + "FloatNx3": "compas_dr.types.FloatNx3", } autodoc_typehints_description_target = "documented" diff --git a/pyproject.toml b/pyproject.toml index b9203b3..3592abb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,7 +69,7 @@ doctest_optionflags = [ # ============================================================================ [tool.bumpversion] -current_version = "0.4.2" +current_version = "0.1.0" message = "Bump version to {new_version}" commit = true tag = true diff --git a/src/compas_dr/constraints/constraint.py b/src/compas_dr/constraints/constraint.py index 5572503..b7e54b6 100644 --- a/src/compas_dr/constraints/constraint.py +++ b/src/compas_dr/constraints/constraint.py @@ -45,7 +45,7 @@ class Constraint(Data): Examples -------- >>> from compas.geometry import Line - >>> from compas_fd.constraints import Constraint + >>> from compas_dr.constraints import Constraint >>> line = Line([0, 0, 0], [1, 0, 0]) >>> constraint = Constraint(line) >>> constraint diff --git a/src/compas_dr/loads/selfweight.py b/src/compas_dr/loads/selfweight.py index fa9346c..cbd35ae 100644 --- a/src/compas_dr/loads/selfweight.py +++ b/src/compas_dr/loads/selfweight.py @@ -4,8 +4,9 @@ from compas.geometry import cross_vectors from compas.geometry import length_vector from compas.matrices import face_matrix -from compas_fd.types import FloatNx1 -from compas_fd.types import FloatNx3 + +from compas_dr.types import FloatNx1 +from compas_dr.types import FloatNx3 class SelfweightCalculator: @@ -27,7 +28,7 @@ class SelfweightCalculator: Examples -------- >>> from compas.datastructures import Mesh - >>> from compas_fd.loads import SelfWeightCalculator + >>> from compas_dr.loads import SelfWeightCalculator >>> mesh = Mesh.from_meshgrid(dx=10, nx=10) >>> mesh.update_default_vertex_attributes(t=0.10) >>> density = 22 diff --git a/src/compas_dr/solvers/dr_constrained_numpy.py b/src/compas_dr/solvers/dr_constrained_numpy.py index 2117b8a..d016dcb 100644 --- a/src/compas_dr/solvers/dr_constrained_numpy.py +++ b/src/compas_dr/solvers/dr_constrained_numpy.py @@ -52,7 +52,7 @@ def dr_constrained_numpy( ---------- indata : :class:`compas_dr.numdata.InputData` An input data object. - constraints : list[:class:`~compas_fd.constraints.Constraint`] + constraints : list[:class:`~compas_dr.constraints.Constraint`] Vertex constraints. kmax : int, optional The maximum number of iterations. diff --git a/src/compas_dr/types.py b/src/compas_dr/types.py new file mode 100644 index 0000000..7652931 --- /dev/null +++ b/src/compas_dr/types.py @@ -0,0 +1,19 @@ +from typing import Annotated +from typing import Literal +from typing import Sequence +from typing import Union + +import numpy as np +import numpy.typing as npt + +FloatNx3 = Union[ + Sequence[Annotated[Sequence[float], 3]], + Annotated[npt.NDArray[np.float64], Literal["*, 3"]], +] +"""An array-like object, with each item in the array containing three (3) floats.""" + +FloatNx1 = Union[ + Sequence[Annotated[Sequence[float], 1]], + Annotated[npt.NDArray[np.float64], Literal["*, 1"]], +] +"""An array-like object, with each item in the array containing one (1) float.""" diff --git a/tasks.py b/tasks.py index b019716..fa055f3 100644 --- a/tasks.py +++ b/tasks.py @@ -1,13 +1,56 @@ +import glob import os +import shutil import invoke from invoke import Collection from compas_invocations import build -from compas_invocations import docs +from compas_invocations import docs as docs_ from compas_invocations import tests from compas_invocations.console import chdir +@invoke.task( + help={ + "docs": "True to clean up generated documentation, otherwise False", + "bytecode": "True to clean up compiled python files, otherwise False.", + "builds": "True to clean up build/packaging artifacts, otherwise False.", + } +) +def clean(ctx, docs=True, bytecode=True, builds=True, ghuser=True): + """Cleans the local copy from compiled artifacts.""" + + with chdir(ctx.base_folder): + if bytecode: + for root, dirs, files in os.walk(ctx.base_folder): + for f in files: + if f.endswith(".pyc"): + os.remove(os.path.join(root, f)) + if ".git" in dirs: + dirs.remove(".git") + + folders = [] + + if docs: + folders.append("docs/api/generated") + + folders.append("dist/") + + if bytecode: + for t in ("src", "tests"): + folders.extend(glob.glob("{}/**/__pycache__".format(t), recursive=True)) + + if builds: + folders.append("build/") + folders.extend(glob.glob("src/**/*.egg-info", recursive=False)) + + if ghuser and ctx.get("ghuser"): + folders.append(os.path.abspath(ctx.ghuser.target_dir)) + + for folder in folders: + shutil.rmtree(os.path.join(ctx.base_folder, folder), ignore_errors=True) + + @invoke.task() def lint(ctx): """Check the consistency of coding style.""" @@ -42,18 +85,50 @@ def check(ctx): lint(ctx) +@invoke.task( + help={ + "rebuild": "True to clean all previously built docs before starting, otherwise False.", + "doctest": "True to run doctests, otherwise False.", + "check_links": "True to check all web links in docs for validity, otherwise False.", + } +) +def docs(ctx, doctest=False, rebuild=False, check_links=False): + """Builds the HTML documentation.""" + + if rebuild: + clean(ctx) + + with chdir(ctx.base_folder): + if doctest: + ctx.run("pytest --doctest-modules") + + opts = "-E" if rebuild else "" + ctx.run("sphinx-build {} -b html docs dist/docs".format(opts)) + + if check_links: + linkcheck(ctx, rebuild=rebuild) + + +@invoke.task() +def linkcheck(ctx, rebuild=False): + """Check links in documentation.""" + print("Running link check...") + opts = "-E" if rebuild else "" + ctx.run("sphinx-build {} -b linkcheck docs dist/docs".format(opts)) + + ns = Collection( - docs.help, + docs_.help, check, lint, format, - docs.docs, - docs.linkcheck, + docs, + linkcheck, tests.test, tests.testdocs, tests.testcodeblocks, build.prepare_changelog, - build.clean, + clean, build.release, build.build_ghuser_components, )