DeepInfer/CONTRIBUTING.md
Tony Lin 3a8d5865dd Add pre-commit hooks for Ruff formatting and linting
Signed-off-by: Tony Lin <tony.lin@intel.com>
2026-10-21 07:17:07 +00:00

2.0 KiB

Contributing

Run all commands below from the repository root. See README.md for environment setup.

Code formatting

Before committing, format the modified code and pass the corresponding checks.

Pre-commit

Install pre-commit and enable the Git hook in your local clone:

python -m pip install pre-commit
pre-commit install
pre-commit run --all-files  # Optional: check the whole repository

The hook runs Ruff checks and formatting on staged Python files. If it changes a file, review and stage the changes before committing again. Each contributor must install the hook in their own clone.

Python

Ruff is configured in pyproject.toml.

ruff check --fix && ruff format                          # Format
ruff check --no-cache && ruff format --check --no-cache  # Check

C++

Use scripts/format_csrc.sh to format C++ and CUDA code under csrc/. Install clang-format or set CLANG_FORMAT to its executable path.

bash scripts/format_csrc.sh          # Format
bash scripts/format_csrc.sh --check  # Check

Testing

Directory conventions

  • tests/: pytest test scripts. All tests should be discoverable by pytest by default.
  • examples/: standalone offline inference and resource-intensive validation scripts. These typically require models or services and take longer to run; they are not collected by pytest.

Core test markers

Core tests must remain lightweight. Mark them according to the target platform:

  • Use @pytest.mark.ci for GPU core tests.
  • Use @pytest.mark.ci_npu for NPU-only core tests.
  • Apply both @pytest.mark.ci and @pytest.mark.ci_npu to tests that must run on both GPUs and NPUs.

Running tests

Run tests in an environment with the required hardware, models, and dependencies:

python -m pytest -v -s -m ci tests      # GPU core tests
python -m pytest -v -s -m ci_npu tests  # NPU core tests
python -m pytest -v -s tests            # Full pytest suite