this repository serves as a template for integrating common tools (eg. pre-commit, pytest, clang-format, Ruff) in a common repository
cp -i `git ls-tree --full-tree --name-only HEAD` ../path/to/your/repo
Note that running cp * ../path/to/repo
will miss hidden files like .pre-commit-config
, so it's advised to use the above command.
It's probably worth staging and committing your changes here, just incase you don't like what the formatters/linters do next.
git add .
git commit -m
Follow all instructions in 'Setup' and then:
pre-commit run --all-files
git add .
git commit -m "Applied `pre-commit` rules"
Every time you clone this repository, you should:
- Setup Python virtual environment in
.venv
folder - Activate virtual environment
- Install python packages
- Install
pre-commit
for pre-commit hooks
python -m venv .venv
source .venv/bin/activate
pip install -r dev_requirements.txt
pre-commit install
On every new terminal session, activate your virtual environment:
source .venv/bin/activate
- This will prepend
$GIT_DIR/.venv/bin/
to your path, allowing you to runpre-commit
,pytest
andclang-format
. Note thatclang-format
is installed through pip, and is tied at the same version for all developers. - I personally find this a chore to type, so I've added
alias source-venv="source .venv/bin/activate"
to my.bashrc
.
Every time you run git commit
, pre-commit
will run formatters and linters against your staged changes. If your code fails, you'll get a screen that looks like this:
$ git commit
Check for case conflicts.................................................Passed
Check JSON...........................................(no files to check)Skipped
Mixed line ending........................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
Trim Trailing Whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook
Fixing README.md
black................................................(no files to check)Skipped
ruff.................................................(no files to check)Skipped
Simply run git add -p
to inspect and stage your commits.