Skip to content

Commit

Permalink
ci: add pre-commit (#5)
Browse files Browse the repository at this point in the history
* ci: add pre-commit

Signed-off-by: ktro2828 <[email protected]>

* ci: add github actions for pre-coomit

Signed-off-by: ktro2828 <[email protected]>

* style: apply pre-commit

Signed-off-by: ktro2828 <[email protected]>

---------

Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 authored Oct 2, 2024
1 parent 047c1bc commit 3bc02a4
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 87 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
name: build-and-test

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
paths:
- "**"
- "!docs/**"
- "!README.md"
- "!.github/**"
- .github/workflows/build-and-test.yaml
workflow_dispatch:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
paths:
- "**"
- "!docs/**"
- "!README.md"
- "!.github/**"
- .github/workflows/build-and-test.yaml
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.12"]
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.12"]

steps:
- name: Checkout code
uses: actions/checkout@v4
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install poetry
run: pip install poetry
- name: Install poetry
run: pip install poetry

- name: Setup python (with pip)
uses: actions/setup-python@v5
with:
cache: "poetry"
python-version: ${{ matrix.python-version }}
- name: Setup python (with pip)
uses: actions/setup-python@v5
with:
cache: "poetry"
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: poetry install
- name: Install dependencies
run: poetry install

- name: Run tests
run: poetry run pytest
- name: Run tests
run: poetry run pytest
2 changes: 1 addition & 1 deletion .github/workflows/cancel-previous-workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
uses: styfle/[email protected]
with:
workflow_id: all
all_but_latest: true
all_but_latest: true
28 changes: 14 additions & 14 deletions .github/workflows/deploy-document.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: deploy-document

on:
push:
branches: [main]
workflow_dispatch:
push:
branches: [main]
workflow_dispatch:

jobs:
deplot-document:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install poetry
- uses: actions/setup-python@v5
with:
cache: "poetry"
python-version: "3.10"
- run: poetry install
- run: poetry run mkdocs gh-deploy --force
deplot-document:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install poetry
- uses: actions/setup-python@v5
with:
cache: "poetry"
python-version: "3.10"
- run: poetry install
- run: poetry run mkdocs gh-deploy --force
18 changes: 18 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: pre-commit

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run pre-commit
uses: autowarefoundation/autoware-github-actions/pre-commit@v1
with:
pre-commit-config: .pre-commit-config.yaml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode
6 changes: 6 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default: true
MD013: false
MD024:
siblings_only: true
MD033: false
MD041: false
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ci:
autofix_commit_msg: "style(pre-commit): autofix"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.42.0
hooks:
- id: markdownlint
args: ["-c", ".markdownlint.yaml", "--fix"]

- repo: https://github.com/tcort/markdown-link-check
rev: v3.12.2
hooks:
- id: markdown-link-check

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ A toolkit to load and operate T4 dataset.

## Getting started

📘 [Documentation](https://tier4.github.io/t4-devkit/) |
⚙️ [Tutorial](https://tier4.github.io/t4-devkit/tutorials/initialize/) |
📘 [Documentation](https://tier4.github.io/t4-devkit/) |
⚙️ [Tutorial](https://tier4.github.io/t4-devkit/tutorials/initialize/) |
🧰 [API Reference](https://tier4.github.io/t4-devkit/apis/tier4/)

### Installation
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

<div align="center">
<img src="assets/render_scene.gif" width="800" alt="RENDER SAMPLE"/>
</div>
</div>
12 changes: 6 additions & 6 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ site_name: T4 Perception Dataset devkit
nav:
- Home: index.md
- Tutorials:
- Initialization: tutorials/initialize.md
- Rendering: tutorials/render.md
- Customization: tutorials/customize.md
- Initialization: tutorials/initialize.md
- Rendering: tutorials/render.md
- Customization: tutorials/customize.md
- API:
- TIER IV: apis/tier4.md
- Schema: apis/schema.md
- Common: apis/common.md
- TIER IV: apis/tier4.md
- Schema: apis/schema.md
- Common: apis/common.md

theme:
name: material
Expand Down
31 changes: 29 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lark = "^1.1.9"
mkdocs = "^1.6.0"
mkdocstrings = { extras = ["python"], version = "^0.25.1" }
mkdocs-material = "^9.5.27"
ruff = "^0.6.8"

[build-system]
requires = ["poetry-core"]
Expand Down
4 changes: 3 additions & 1 deletion t4_devkit/common/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def distance_color(
Color map in the shape of (N,). If input type is any number, returns a color as
`tuple[float, float, float]`. Otherwise, returns colors as `NDArrayF64`.
"""
color_map = matplotlib.colormaps["turbo_r"] if cmap is None else matplotlib.colormaps[cmap]
color_map = (
matplotlib.colormaps["turbo_r"] if cmap is None else matplotlib.colormaps[cmap]
)
norm = matplotlib.colors.Normalize(v_min, v_max)
return color_map(norm(distances))
8 changes: 6 additions & 2 deletions t4_devkit/common/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def view_points(
x_ = points[0]
y_ = points[1]
r2 = x_**2 + y_**2
f1 = (1 + k1 * r2 + k2 * r2**2 + k3 * r2**3) / (1 + k4 * r2 + k5 * r2**2 + k6 * r2**3)
f1 = (1 + k1 * r2 + k2 * r2**2 + k3 * r2**3) / (
1 + k4 * r2 + k5 * r2**2 + k6 * r2**3
)
f2 = x_ * y_
x__ = x_ * f1 + 2 * p1 * f2 + p2 * (r2 + 2 * x_**2) + s1 * r2 + s2 * r2**2
y__ = y_ * f1 + p1 * (r2 + 2 * y_**2) + 2 * p2 * f2 + s3 * r2 + s4 * r2**2
Expand Down Expand Up @@ -99,7 +101,9 @@ def is_box_in_image(
is_visible = np.logical_and(is_visible, corners_on_img[1, :] > 0)
is_visible = np.logical_and(is_visible, corners_on_img[2, :] > 1)

in_front = corners_3d[2, :] > 0.1 # True if a corner is at least 0.1 meter in front of camera.
in_front = (
corners_3d[2, :] > 0.1
) # True if a corner is at least 0.1 meter in front of camera.

if visibility == VisibilityLevel.FULL:
return all(is_visible) and all(in_front)
Expand Down
6 changes: 5 additions & 1 deletion t4_devkit/schema/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ def is_optional(self) -> bool:
Returns:
Return True if this schema is optional.
"""
return self in (SchemaName.OBJECT_ANN, SchemaName.SURFACE_ANN, SchemaName.KEYPOINT)
return self in (
SchemaName.OBJECT_ANN,
SchemaName.SURFACE_ANN,
SchemaName.KEYPOINT,
)
7 changes: 6 additions & 1 deletion t4_devkit/schema/tables/calibrated_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
from ..name import SchemaName

if TYPE_CHECKING:
from t4_devkit.typing import CamDistortionType, CamIntrinsicType, RotationType, TranslationType
from t4_devkit.typing import (
CamDistortionType,
CamIntrinsicType,
RotationType,
TranslationType,
)

__all__ = ("CalibratedSensor",)

Expand Down
4 changes: 3 additions & 1 deletion t4_devkit/schema/tables/ego_pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ def from_dict(cls, data: dict[str, Any]) -> Self:
rotation = Quaternion(data["rotation"])
timestamp: int = data["timestamp"]

return cls(token=token, translation=translation, rotation=rotation, timestamp=timestamp)
return cls(
token=token, translation=translation, rotation=rotation, timestamp=timestamp
)
8 changes: 6 additions & 2 deletions t4_devkit/schema/tables/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def _register_decorator(obj: object) -> object:

return _register_decorator

def _add_module(self, module: object, name: SchemaName, *, force: bool = False) -> None:
def _add_module(
self, module: object, name: SchemaName, *, force: bool = False
) -> None:
if not inspect.isclass(module):
raise TypeError(f"module must be a class, but got {type(module)}.")

Expand All @@ -60,7 +62,9 @@ def _add_module(self, module: object, name: SchemaName, *, force: bool = False)

self.__schemas[name.value] = module

def build_from_json(self, key: str | SchemaName, filepath: str) -> list[SchemaTable]:
def build_from_json(
self, key: str | SchemaName, filepath: str
) -> list[SchemaTable]:
"""Build schema dataclass from json.
Args:
Expand Down
4 changes: 3 additions & 1 deletion t4_devkit/schema/tables/sample_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def from_dict(cls, data: dict[str, Any]) -> Self:
visibility_token: str = data["visibility_token"]
translation = np.array(data["translation"])
velocity = np.array(data["velocity"]) if data.get("velocity") else None
acceleration = np.array(data["acceleration"]) if data.get("acceleration") else None
acceleration = (
np.array(data["acceleration"]) if data.get("acceleration") else None
)
size = np.array(data["size"])
rotation = Quaternion(data["rotation"])
num_lidar_pts: int = data["num_lidar_pts"]
Expand Down
Loading

0 comments on commit 3bc02a4

Please sign in to comment.