From 016f5f643f73769e3dfd6a56bd7e6738be4fd97a Mon Sep 17 00:00:00 2001 From: Kenneth Yang <82800265+kjy5@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:21:38 -0800 Subject: [PATCH] chore: Api styling, moved unity model (#65) * Add material styling, fixed typing in unity * Moved unity model back into models subpackage --- .github/workflows/build-docs.yml | 4 ++ .github/workflows/build-models.yml | 4 ++ .github/workflows/static-analysis.yml | 4 ++ docs/api/unity.md | 1 + docs/api/unity_models.md | 1 - docs/stylesheets/mkdocstrings.css | 27 ++++++++++++ mkdocs.yml | 3 +- pyproject.toml | 7 ++- src/vbl_aquarium/__about__.py | 2 +- src/vbl_aquarium/build.py | 4 ++ src/vbl_aquarium/models/ephys_link.py | 2 +- src/vbl_aquarium/models/generic.py | 2 +- src/vbl_aquarium/models/pinpoint.py | 2 +- .../unity_models.py => models/unity.py} | 44 ++++++++++--------- src/vbl_aquarium/models/urchin.py | 2 +- src/vbl_aquarium/utils/common.py | 4 +- src/vbl_aquarium/utils/generate_csharp.py | 4 +- 17 files changed, 82 insertions(+), 35 deletions(-) create mode 100644 docs/api/unity.md delete mode 100644 docs/api/unity_models.md create mode 100644 docs/stylesheets/mkdocstrings.css rename src/vbl_aquarium/{utils/unity_models.py => models/unity.py} (61%) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 825ed65..2792bbf 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -6,6 +6,10 @@ on: workflow_dispatch: workflow_call: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: name: Build diff --git a/.github/workflows/build-models.yml b/.github/workflows/build-models.yml index d06c57c..66e8261 100644 --- a/.github/workflows/build-models.yml +++ b/.github/workflows/build-models.yml @@ -6,6 +6,10 @@ on: branches: - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: name: Build diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index fe6c884..ff17e32 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -6,6 +6,10 @@ on: branches: - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: analyze: name: Analyze diff --git a/docs/api/unity.md b/docs/api/unity.md new file mode 100644 index 0000000..5840d75 --- /dev/null +++ b/docs/api/unity.md @@ -0,0 +1 @@ +::: vbl_aquarium.models.unity diff --git a/docs/api/unity_models.md b/docs/api/unity_models.md deleted file mode 100644 index 12c20c1..0000000 --- a/docs/api/unity_models.md +++ /dev/null @@ -1 +0,0 @@ -::: vbl_aquarium.utils.unity_models diff --git a/docs/stylesheets/mkdocstrings.css b/docs/stylesheets/mkdocstrings.css new file mode 100644 index 0000000..45dbd71 --- /dev/null +++ b/docs/stylesheets/mkdocstrings.css @@ -0,0 +1,27 @@ +/* Indentation. */ +div.doc-contents:not(.first) { + padding-left: 25px; + border-left: .05rem solid var(--md-typeset-table-color); +} + +/* Mark external links as such. */ +a.external::after, +a.autorefs-external::after { + /* https://primer.style/octicons/arrow-up-right-24 */ + mask-image: url('data:image/svg+xml,'); + -webkit-mask-image: url('data:image/svg+xml,'); + content: ' '; + + display: inline-block; + vertical-align: middle; + position: relative; + + height: 1em; + width: 1em; + background-color: currentColor; +} + +a.external:hover::after, +a.autorefs-external:hover::after { + background-color: var(--md-accent-fg-color); +} \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 29df24c..df9fe0a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -47,6 +47,7 @@ theme: - toc.follow extra_css: - stylesheets/extra.css + - stylesheets/mkdocstrings.css markdown_extensions: - admonition - attr_list @@ -89,5 +90,5 @@ nav: - API: - api/index.md - "VBL Base Model": api/vbl_base_model.md - - "Unity": api/unity_models.md + - "Unity": api/unity.md - "Ephys Link": api/ephys_link.md diff --git a/pyproject.toml b/pyproject.toml index 186d536..89a3c9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ python = "3.13.1" skip-install = true dependencies = [ "mkdocs-material==9.5.49", - "mkdocstrings-python==1.12.2", + "mkdocstrings-python==1.13.0", ] [tool.hatch.envs.docs.scripts] serve = "mkdocs serve" @@ -66,8 +66,7 @@ build = "mkdocs build" [tool.basedpyright] include = ["src/vbl_aquarium"] -exclude = ["src/vbl_aquarium/old_build.py", "src/vbl_aquarium/old_generate_cs.py"] strict = ["src/vbl_aquarium"] -[tool.ruff.lint] -ignore = ["A003", "EM101", "FBT002", "T201", "TCH001", "TRY002", "TRY003"] \ No newline at end of file +#[tool.ruff.lint] +#ignore = ["A003", "EM101", "FBT002", "T201", "TCH001", "TRY002", "TRY003"] \ No newline at end of file diff --git a/src/vbl_aquarium/__about__.py b/src/vbl_aquarium/__about__.py index c9bd737..5313823 100644 --- a/src/vbl_aquarium/__about__.py +++ b/src/vbl_aquarium/__about__.py @@ -1 +1 @@ -__version__ = "1.0.0b0" +__version__ = "1.0.0b1" diff --git a/src/vbl_aquarium/build.py b/src/vbl_aquarium/build.py index 9ef5a14..3f61fb9 100644 --- a/src/vbl_aquarium/build.py +++ b/src/vbl_aquarium/build.py @@ -35,6 +35,10 @@ # Look for all modules under the models subpackage. for module in iter_modules([MODELS_DIRECTORY]): + # Skip Unity module since it's already built into Unity. + if module.name == "unity": + continue + # Collect classes. imported_module = import_module(f"vbl_aquarium.models.{module.name}") module_classes = get_model_classes(imported_module) diff --git a/src/vbl_aquarium/models/ephys_link.py b/src/vbl_aquarium/models/ephys_link.py index b4e0751..a3b4bf0 100644 --- a/src/vbl_aquarium/models/ephys_link.py +++ b/src/vbl_aquarium/models/ephys_link.py @@ -7,7 +7,7 @@ from pydantic import Field -from vbl_aquarium.utils.unity_models import Vector3, Vector4 +from vbl_aquarium.models.unity import Vector3, Vector4 from vbl_aquarium.utils.vbl_base_model import VBLBaseModel diff --git a/src/vbl_aquarium/models/generic.py b/src/vbl_aquarium/models/generic.py index 88272ba..4165000 100644 --- a/src/vbl_aquarium/models/generic.py +++ b/src/vbl_aquarium/models/generic.py @@ -2,7 +2,7 @@ from pydantic import Field -from vbl_aquarium.utils.unity_models import Color, Vector2, Vector3 +from vbl_aquarium.models.unity import Color, Vector2, Vector3 # noqa: TCH001 from vbl_aquarium.utils.vbl_base_model import VBLBaseModel diff --git a/src/vbl_aquarium/models/pinpoint.py b/src/vbl_aquarium/models/pinpoint.py index 3683b0b..b0c6154 100644 --- a/src/vbl_aquarium/models/pinpoint.py +++ b/src/vbl_aquarium/models/pinpoint.py @@ -2,7 +2,7 @@ from pydantic import Field -from vbl_aquarium.utils.unity_models import Color, Vector2, Vector3 +from vbl_aquarium.models.unity import Color, Vector2, Vector3 from vbl_aquarium.utils.vbl_base_model import VBLBaseModel # CRANIOTOMY diff --git a/src/vbl_aquarium/utils/unity_models.py b/src/vbl_aquarium/models/unity.py similarity index 61% rename from src/vbl_aquarium/utils/unity_models.py rename to src/vbl_aquarium/models/unity.py index a7af236..b8490fc 100644 --- a/src/vbl_aquarium/utils/unity_models.py +++ b/src/vbl_aquarium/models/unity.py @@ -1,6 +1,8 @@ """Models for Unity data types.""" -# pyright: reportAny=false, reportExplicitAny=false +# pyright: reportUnnecessaryIsInstance=false, reportAny=false, reportExplicitAny=false +from __future__ import annotations + from typing import Any from pydantic import BaseModel, Field @@ -67,7 +69,7 @@ class Vector4(BaseModel): z: float = 0.0 w: float = 0.0 - def __add__(self, other: Any): + def __add__(self, other: Any) -> Vector4: """Add two vectors together. Args: @@ -79,12 +81,12 @@ def __add__(self, other: Any): Raises: TypeError: If the other object is not a Vector4. """ - if isinstance(other, Vector4): - return Vector4(x=self.x + other.x, y=self.y + other.y, z=self.z + other.z, w=self.w + other.w) - error = f"unsupported operand type(s) for +: 'Vector4' and '{type(other)}'" - raise TypeError(error) + if not isinstance(other, Vector4): + error = f"Unsupported operand type(s) for +: 'Vector4' and '{type(other)}'" + raise TypeError(error) + return Vector4(x=self.x + other.x, y=self.y + other.y, z=self.z + other.z, w=self.w + other.w) - def __sub__(self, other: Any): + def __sub__(self, other: Any) -> Vector4: """Subtract one vector from another. Args: @@ -96,12 +98,12 @@ def __sub__(self, other: Any): Raises: TypeError: If the other object is not a Vector4. """ - if isinstance(other, Vector4): - return Vector4(x=self.x - other.x, y=self.y - other.y, z=self.z - other.z, w=self.w - other.w) - error = f"unsupported operand type(s) for -: 'Vector4' and '{type(other)}'" - raise TypeError(error) + if not isinstance(other, Vector4): + error = f"Unsupported operand type(s) for -: 'Vector4' and '{type(other)}'" + raise TypeError(error) + return Vector4(x=self.x - other.x, y=self.y - other.y, z=self.z - other.z, w=self.w - other.w) - def __mul__(self, other: Any): + def __mul__(self, other: Any) -> Vector4: """Multiply a vector by a scalar. Args: @@ -113,12 +115,12 @@ def __mul__(self, other: Any): Raises: TypeError: If the other object is not an int or float. """ - if isinstance(other, (int, float)): - return Vector4(x=self.x * other, y=self.y * other, z=self.z * other, w=self.w * other) - error = f"unsupported operand type(s) for *: 'Vector4' and '{type(other)}'" - raise TypeError(error) + if not isinstance(other, (int, float)): + error = f"Unsupported operand type(s) for *: 'Vector4' and '{type(other)}'" + raise TypeError(error) + return Vector4(x=self.x * other, y=self.y * other, z=self.z * other, w=self.w * other) - def __truediv__(self, other: Any): + def __truediv__(self, other: Any) -> Vector4: """Divide a vector by a scalar. Args: @@ -130,7 +132,7 @@ def __truediv__(self, other: Any): Raises: TypeError: If the other object is not an int or float. """ - if isinstance(other, (int, float)): - return Vector4(x=self.x / other, y=self.y / other, z=self.z / other, w=self.w / other) - error = f"unsupported operand type(s) for /: 'Vector4' and '{type(other)}'" - raise TypeError(error) + if not isinstance(other, (int, float)): + error = f"Unsupported operand type(s) for /: 'Vector4' and '{type(other)}'" + raise TypeError(error) + return Vector4(x=self.x / other, y=self.y / other, z=self.z / other, w=self.w / other) diff --git a/src/vbl_aquarium/models/urchin.py b/src/vbl_aquarium/models/urchin.py index 713b16e..16a9efd 100644 --- a/src/vbl_aquarium/models/urchin.py +++ b/src/vbl_aquarium/models/urchin.py @@ -4,7 +4,7 @@ from pydantic import Field -from vbl_aquarium.utils.unity_models import Color, Vector2, Vector3 +from vbl_aquarium.models.unity import Color, Vector2, Vector3 from vbl_aquarium.utils.vbl_base_model import VBLBaseModel # CustomAtlas diff --git a/src/vbl_aquarium/utils/common.py b/src/vbl_aquarium/utils/common.py index c5ec02e..5f95552 100644 --- a/src/vbl_aquarium/utils/common.py +++ b/src/vbl_aquarium/utils/common.py @@ -7,7 +7,7 @@ from pydantic import BaseModel -from vbl_aquarium.utils import unity_models +from vbl_aquarium.models import unity from vbl_aquarium.utils.vbl_base_model import VBLBaseModel if TYPE_CHECKING: @@ -42,6 +42,6 @@ def get_unity_model_class_names() -> set[str]: """ return { model_name - for model_name, class_object in getmembers(unity_models, isclass) + for model_name, class_object in getmembers(unity, isclass) if issubclass(class_object, BaseModel) and class_object != BaseModel } diff --git a/src/vbl_aquarium/utils/generate_csharp.py b/src/vbl_aquarium/utils/generate_csharp.py index 3fe6d88..ac599f2 100644 --- a/src/vbl_aquarium/utils/generate_csharp.py +++ b/src/vbl_aquarium/utils/generate_csharp.py @@ -7,7 +7,9 @@ from pydantic.alias_generators import to_camel, to_pascal, to_snake from vbl_aquarium.utils.common import get_unity_model_class_names -from vbl_aquarium.utils.vbl_base_model import VBLBaseModel + +if TYPE_CHECKING: + from vbl_aquarium.utils.vbl_base_model import VBLBaseModel if TYPE_CHECKING: from pydantic.fields import FieldInfo