This document outlines the code style standards for the jetson-containers project and how to set up automatic code formatting.
The project uses several tools to maintain consistent code style:
- black: Python code formatter
- flake8: Python code linter
- pre-commit: Git hooks manager
-
Install the required tools:
pip install -r requirements.txt
-
Install the pre-commit hooks:
pre-commit install
-
(Optional) Run formatting on all files:
pre-commit run --all-files
- The pre-commit hooks run automatically before each commit
- Only files in whitelisted paths are checked (see
.pre-commit-config.yaml) - If formatting issues are found:
- Some will be fixed automatically
- Others will need manual fixes
- The commit will be blocked until all checks pass
If you want your package to be included in the formatting checks:
-
Add your package path to the
filespatterns in.pre-commit-config.yaml:files: | (?x)^( jetson_containers/.*\.py| packages/your-package/.*\.py| # Add your package here test_precommit\.py )$
-
Install pre-commit (if not already installed):
pip install pre-commit pre-commit install
If you don't want to use the formatting tools:
- You don't need to install pre-commit
- Your package won't be checked if it's not in the whitelist
- You can still commit and push code normally
If you encounter issues:
-
Check pre-commit version:
pre-commit --version
-
Update pre-commit:
pre-commit autoupdate
-
Clear pre-commit cache:
pre-commit clean
-
Run pre-commit manually:
pre-commit run --all-files