Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Issues labelled [`good first issue`](https://github.com/petercorke/machinevision
- Keep pull requests scoped to a single feature or fix. If you have several unrelated changes, open separate PRs so each can be reviewed and merged independently.
- For API changes, propose the change in [Discussions](https://github.com/petercorke/machinevision-toolbox-python/discussions) before opening a PR.
- PR titles follow [Conventional Commits](https://www.conventionalcommits.org/) (`type: description`) — checked automatically on the PR.
- Code is linted and import-sorted with [ruff](https://docs.astral.sh/ruff/); configuration is in `pyproject.toml` under `[tool.ruff]`. Type checking is done with [pyright](https://microsoft.github.io/pyright/) (`[tool.pyright]`).
- Code is linted and import-sorted with [ruff](https://docs.astral.sh/ruff/); configuration is in `pyproject.toml` under `[tool.ruff]`. Type checking is done with [mypy](https://mypy.readthedocs.io/) (`[tool.mypy]`); run `mypy` from the repo root. The package passes with no errors, and CI fails if that changes.
- New or changed code should be type-hinted using modern syntax (`X | Y`, `X | None`, `list[X]`, `dict[K, V]` — not `Union`, `Optional`, `List`, `Dict`).
- Docstrings use reST style (`:param:`, `:returns:`). Type hints in the function signature already cover types, so `:type:`/`:rtype:` are rarely needed.
- Any code change should be covered by tests and must not break existing ones. Tests live in `tests/`. Install the dev dependencies with `pip install -e '.[dev]'` (add `,docs` too if you're touching documentation), then run:
Expand Down
42 changes: 41 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,45 @@ jobs:
MPLBACKEND: Agg
run: python -m pytest tests/test_bundleadjust.py --timeout=50 --timeout-method=thread

typecheck:
name: typecheck and build wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: actions/setup-python@v7
with:
python-version: "3.12"

# open3d and the ros extra are installed so that mypy sees their types: a
# "type: ignore" for one of them is unused, and so an error, where it is missing
- name: Install package and development dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev,ros]
pip install open3d build

# configuration is in pyproject.toml, [tool.mypy]; the package must stay at zero errors
- name: Run mypy
run: mypy

- name: Build wheel and verify typed marker
run: |
python -m build --wheel
python - <<'PY'
from pathlib import Path
from zipfile import ZipFile

wheel = next(Path("dist").glob("machinevision_toolbox_python-*.whl"))
with ZipFile(wheel) as archive:
assert "machinevisiontoolbox/py.typed" in archive.namelist(), (
f"{wheel.name} is missing machinevisiontoolbox/py.typed"
)
PY

all-tests-passed:
name: All tests passed
needs: [test, pgraph-compat]
needs: [test, pgraph-compat, typecheck]
runs-on: ubuntu-latest
if: always()
steps:
Expand All @@ -100,6 +136,10 @@ jobs:
echo "pgraph compat did not succeed: ${{ needs.pgraph-compat.result }}"
exit 1
fi
if [ "${{ needs.typecheck.result }}" != "success" ]; then
echo "typecheck did not succeed: ${{ needs.typecheck.result }}"
exit 1
fi

codecov:
needs: test
Expand Down
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ description and ask first.
exists, tracked via `tech-debt`-labelled issues (including a "mypy not in CI" entry) — see
ecosystem `AGENTS.md` §5 for how that target is framed.
- Type checking: `mypy` (config in `pyproject.toml` under `[tool.mypy]`; run it from the repo
root with no arguments). The package passes with zero errors and must stay that way. It is
not yet run in CI (tracked as Issue 40), so run it yourself before opening a PR. Write
root with no arguments). The package passes with zero errors and must stay that way. CI runs
it (the `typecheck` job, part of the required `All tests passed` check), so run it yourself
before opening a PR. Write
ignores as `# type: ignore[code]` with the specific error code; unused ignores are reported.
Import from the defining submodule (for example `machinevisiontoolbox.base.graphics`), not
through the package's star imports, which mypy cannot follow.
Expand Down
4 changes: 3 additions & 1 deletion src/machinevisiontoolbox/BagOfWords.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def __init__(
if seed is not None:
cv2.setRNGSeed(seed)

ret, labels, centroids = cv2.kmeans( # type: ignore[call-overload]
# OpenCV's stubs for kmeans differ between releases, so call it untyped
kmeans: Any = cv2.kmeans
ret, labels, centroids = kmeans(
data=features._descriptor,
K=k,
bestLabels=None,
Expand Down
6 changes: 4 additions & 2 deletions src/machinevisiontoolbox/ImageColor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

import cv2
import numpy as np
Expand Down Expand Up @@ -267,7 +267,9 @@ def kmeans_color(

if k is not None:
# perform clustering
ret, label, centres = cv2.kmeans( # type: ignore[call-overload]
# OpenCV's stubs for kmeans differ between releases, so call it untyped
kmeans: Any = cv2.kmeans
ret, label, centres = kmeans(
data=data,
K=k,
bestLabels=None,
Expand Down
Loading