Skip to content

Commit

Permalink
chore: Api styling, moved unity model (#65)
Browse files Browse the repository at this point in the history
* Add material styling, fixed typing in unity

* Moved unity model back into models subpackage
  • Loading branch information
kjy5 authored Jan 2, 2025
1 parent e4757d4 commit 016f5f6
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
workflow_dispatch:
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build-models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
analyze:
name: Analyze
Expand Down
1 change: 1 addition & 0 deletions docs/api/unity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: vbl_aquarium.models.unity
1 change: 0 additions & 1 deletion docs/api/unity_models.md

This file was deleted.

27 changes: 27 additions & 0 deletions docs/stylesheets/mkdocstrings.css
Original file line number Diff line number Diff line change
@@ -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,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.25 15.5a.75.75 0 00.75-.75v-9a.75.75 0 00-.75-.75h-9a.75.75 0 000 1.5h7.19L6.22 16.72a.75.75 0 101.06 1.06L17.5 7.56v7.19c0 .414.336.75.75.75z"></path></svg>');
-webkit-mask-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.25 15.5a.75.75 0 00.75-.75v-9a.75.75 0 00-.75-.75h-9a.75.75 0 000 1.5h7.19L6.22 16.72a.75.75 0 101.06 1.06L17.5 7.56v7.19c0 .414.336.75.75.75z"></path></svg>');
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);
}
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ theme:
- toc.follow
extra_css:
- stylesheets/extra.css
- stylesheets/mkdocstrings.css
markdown_extensions:
- admonition
- attr_list
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ 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"
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"]
#[tool.ruff.lint]
#ignore = ["A003", "EM101", "FBT002", "T201", "TCH001", "TRY002", "TRY003"]
2 changes: 1 addition & 1 deletion src/vbl_aquarium/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0b0"
__version__ = "1.0.0b1"
4 changes: 4 additions & 0 deletions src/vbl_aquarium/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/vbl_aquarium/models/ephys_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/vbl_aquarium/models/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/vbl_aquarium/models/pinpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)
2 changes: 1 addition & 1 deletion src/vbl_aquarium/models/urchin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/vbl_aquarium/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion src/vbl_aquarium/utils/generate_csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 016f5f6

Please sign in to comment.