Skip to content

[6/6] Add type annotations, ruff/mypy CI, and pytest suite - #523

Draft
sarlinpe wants to merge 1 commit into
refresh/6-slim-localizerfrom
refresh/7-code-quality-typing-tests
Draft

sarlinpe wants to merge 1 commit into
refresh/6-slim-localizerfrom
refresh/7-code-quality-typing-tests

Conversation

@sarlinpe

@sarlinpe sarlinpe commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on #522 (refresh/6-slim-localizer) in Stack #525. Modernizes code quality tooling, adds full Python 3.10+ type annotations across hloc, and introduces a fast hermetic unit + Sacre Coeur end-to-end test suite.

What changed

  • Typing & py.typed:
    • Added PEP 585/604 type annotations across all modules in hloc/ (0 untyped defs remaining), including @overload signatures for get_keypoints, parse_image_lists, and parse_relocalization, plus confs: dict[str, dict[str, Any]] in extract_features.py, match_features.py, and match_dense.py.
    • Added hloc/py.typed and [tool.setuptools.package-data] so downstream typed consumers receive package types.
  • Linting, formatting & CI:
    • Replaced legacy .flake8 and .isort.cfg with [tool.ruff] (E, F, UP, B, SIM, I), [tool.mypy] (disallow_untyped_defs = true), and [tool.pytest.ini_options] in pyproject.toml, plus [project.optional-dependencies] dev.
    • Updated .github/workflows/code-quality.yml with lint (ruff check, ruff format --check, mypy hloc tests) and test (CPU PyTorch + pytest -v) jobs.
    • Fixed latent bugs surfaced during typing/linting: isinstance(ref_list, Iterable) in hloc/pairs_from_exhaustive.py, matplotlib.colormaps["jet"] in hloc/visualization.py, mutable default arguments in match_dense.py/visualization.py/4Seasons/utils.py, and assign_matches/get_unique_matches in hloc/match_dense.py.
  • Tests (tests/):
    • tests/test_parsers_and_io.py: parsers, HDF5 IO round-trip, reversed matches, pose formatting.
    • tests/test_pairing.py: pairs_from_exhaustive, pairs_from_covisibility, pairs_from_poses, pairs_from_retrieval.
    • tests/test_colmap_from_nvm.py: NVM conversion (unnormalized quaternions, camera center recovery), RobotCar NVM, Cambridge & 7Scenes model/depth helpers (auto-discovering both .bin and .txt).
    • tests/test_triangulation_and_localization.py: parse_option_args, synthetic multi-view triangulation.main (skip_geometric_verification True/False) + localize_sfm (covisibility_clustering True/False, error cases) + localize_inloc.
    • tests/test_extractors_and_sacre_coeur_e2e.py: DoG blank-image & NN matcher unit test + full end-to-end SfM -> guided-GV triangulation -> query localization on the bundled 10-image datasets/sacre_coeur/mapping/ dataset (no external weight downloads).

Verification

  • ruff check hloc tests *.ipynb: passed
  • ruff format --check hloc tests *.ipynb: 65 files formatted
  • mypy hloc tests (both with .venv deps and --no-site-packages): 0 issues in 53 files
  • pytest -v: 16 passed in ~11s on CPU
  • Wheel build verified hloc/py.typed is packaged in hloc-1.5-py3-none-any.whl

Stack (#525)

  1. Update hloc for COLMAP / pycolmap >= 4.2.1 and Python >= 3.10 #517 — COLMAP 4.2.1 compatibility
  2. Make hloc pip-installable via pyproject.toml and remove git submodules #518 — Pip-installable pyproject.toml, remove submodules, vendor SuperGlue
  3. Remove read_write_model.py and raw sqlite3 in favor of pycolmap #519 — Remove read_write_model.py and raw sqlite3
  4. Offload known-pose geometric verification to pycolmap.guided_geometric_verification #520 — Offload known-pose geometric verification to pycolmap
  5. Slim and modernize localizers on top of pycolmap 4.2.1 #522 — Slim and modernize localize_sfm and localize_inloc
  6. This PR — Full type annotations, ruff/mypy CI, and pytest suite

@sarlinpe
sarlinpe added this pull request to stack #524 November 22, 2026 11:18
@sarlinpe
sarlinpe force-pushed the refresh/7-code-quality-typing-tests branch from 0a38355 to 76808dd Compare November 22, 2026 14:05
@sarlinpe
sarlinpe removed this pull request from stack #524 November 22, 2026 14:17
@sarlinpe
sarlinpe force-pushed the refresh/7-code-quality-typing-tests branch from 76808dd to 46aa1c2 Compare November 22, 2026 14:17
@sarlinpe
sarlinpe added this pull request to stack #525 November 22, 2026 14:17
@sarlinpe sarlinpe changed the title [7/7] Add full type annotations, ruff/mypy CI, and pytest suite [6/6] Add type annotations, ruff/mypy CI, and pytest suite Nov 22, 2026
@sarlinpe
sarlinpe force-pushed the refresh/7-code-quality-typing-tests branch from 46aa1c2 to 4136abd Compare November 22, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant