Contributing¶
Bug reports, questions and pull requests are all welcome. This page covers getting a working environment, the checks to run before opening a pull request, and the conventions the existing code follows. For where the modules live and what each one does, see Development.
Setting up¶
git clone https://github.com/kesai-labs/py123d_detection.git
cd py123d_detection
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
The export side needs only py123d and numpy. It never imports mmcv, mmdet3d or torch, and the training-side plugin imports mmdet3d lazily, inside the one module that needs it. So you do not need a working mmdet3d installation to work on most of this codebase, which is deliberate: a mmcv/mmdet3d environment is pinned to Python 3.8 and sometimes painful to build.
Concretely, 287 of the 616 unit tests run without torch, and pytest -m "not torch" selects
exactly those. The rest need the torch extra. CI runs both selections as separate jobs, so
neither can quietly stop working, and its export job installs [dev,nuscenes]: the devkit is part
of the export side, since core.evaluation scores with it, and it pulls no torch.
Add the extras for the part you are touching:
extra |
pulls in |
needed when |
|---|---|---|
|
pytest, ruff |
always, since it is what runs the checks below |
|
sphinx, furo, myst-parser, … |
editing anything under |
|
nuscenes-devkit |
working on native nuScenes token restoration |
|
opencv-python |
working on |
|
torch, torchvision, lightning, hydra, nuscenes-devkit, … |
anything under |
|
matplotlib (>= 3.8), opencv-python |
|
One environment caveat is worth knowing before you debug a confusing pickle failure. If your
conversion environment is on numpy 2, the pickles it writes will not load under the numpy 1 that
mmdet3d environments use. Installing numpy<2 alongside py123d is the simple fix, and
Crossing the Python version boundary explains the whole hazard
and the alternative.
Checks before a pull request¶
Three commands, none of which need any data on disk:
ruff check . # lint; the configuration lives in pyproject.toml
pytest # the unit tests, about a minute
sphinx-build -b dirhtml docs docs/_build # only if you touched docs/ or a docstring
ruff format is deliberately not on that list. The tree is not formatter-managed, and running
it today would reformat 26 files that have nothing to do with your change. Match the style of the
code around you instead.
.github/workflows/tests.yaml runs the suite and ruff check on every pull request, as two jobs,
one without the torch extra and one with everything. The full job fails outright if the extra did
not install, because seven test modules skip themselves when torch is missing and a run that
quietly drops them would otherwise report green. Running the checks locally first is still the
quicker loop.
The integration tests¶
Twenty-eight tests are marked integration and deselected by default (addopts in
pyproject.toml). Twelve of them need a real nuScenes tree and its 123D conversion side by side.
The other sixteen are the dataset-equivalence fixtures, which need converted 123D logs:
export NUSCENES_DATA_ROOT=/path/to/nuscenes # holds v1.0-mini/, samples/, sweeps/
export PY123D_DATA_ROOT=/path/to/py123d # the 123D conversion of that nuScenes
pytest -m integration
They export a pickle, build the reference pickle on the fly with
tools/reference_nuscenes_converter.py (a port of the converter mmdetection3d and StreamPETR ship)
and compare the two field by field. That comparison is the project’s central claim, so run it if you
change anything under src/py123d_detection/mmcv/export/, and say in the pull request whether it
still holds. Validation describes what it checks and the two differences that are
expected.
Conventions¶
Style. ruff with line-length = 120 and rules E, F and I (pycodestyle errors, pyflakes
and import sorting), ignoring E501 and E741, with __init__.py excluded so re-exports can be
grouped by hand. ruff check . is the authority, and nothing else is enforced.
Docstrings are reST field lists, rendered by sphinx.ext.autodoc directly. There is no
napoleon extension, so Google- and NumPy-style sections will not render. Types come from the
annotations via sphinx-autodoc-typehints, so do not repeat them in the text:
def export_to_mmdet3d(sources, output_path, config=None, version="py123d-v1.0") -> ExportReport:
"""Export one or more 123D sources into a single mmdetection3d info pickle.
:param version: Stored as ``metadata['version']``, which mmdet3d reads back.
"""
Document a parameter when its meaning is not obvious from its name and type. The existing docstrings skip the ones that are.
Comments in this codebase explain why, not what: the constraint that forced a decision, the reason a default is what it is, the failure that a check exists to prevent. A comment restating the line below it is noise. A comment recording why protocol 4 is the default is the reason the next person does not break it. Please keep writing them that way.
Tests are named as sentences about the behaviour they pin down, so
test_rebuild_preserves_the_shape_of_empty_arrays rather than test_rebuild_2. New behaviour goes
in the tests/test_<module>.py that matches the module it lives in.
Adding a documentation page¶
Write the Markdown under docs/ (or docs/guides/ for a task-oriented one), then add it to a
toctree in docs/index.md. Sphinx warns about any page that no toctree includes, and the page is
unreachable until you do.
MyST is configured so the same Markdown reads well on GitHub and on the site: heading anchors are
generated down to h3, so [text](validation.md#known-differences) resolves in both places, and
a ```mermaid fence renders as a diagram rather than a code block. See
Building the docs for the local preview.
Opening the pull request¶
Branch off main with a feat/ or fix/ prefix, and avoid naming a branch after a top-level
documentation page such as guides or api. Branch documentation previews are published alongside
those pages and would shadow them, as Publishing explains.
Say what changed and why. If the change affects what ends up in an exported pickle, say so explicitly and report the integration comparison. If a reviewer would benefit from reading the rendered documentation, publish a preview for your branch: Actions -> docs -> Run workflow, pick the branch, and link the resulting URL in the pull request.
Contributions are made under the project’s Apache-2.0 license, the full text of which is in
LICENSE at the repository root.