Skip to content

Commit

Permalink
use conda for pre-commit/clang-format versioning (#1435)
Browse files Browse the repository at this point in the history
- use conda for pre-commit/clang-format versioning
- update devel/git-hooks.md documentation accordingly
  • Loading branch information
KrisThielemans authored May 21, 2024
1 parent 6b88234 commit 41c74f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/pre-commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
name: pre-commit
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- run: sudo apt-get install -yqq clang-format
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: pre-commit-env
environment-file: pre-commit-environment.yml
auto-activate-base: false
- uses: pre-commit/action@v3.0.0
47 changes: 31 additions & 16 deletions documentation/devel/git-hooks.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
# Developer documentation: how to install (software for) git hooks

You first need to have Python and pip
We use [pre-commit](https://pre-commit.com) to check coding conventions, including
white-space formatting rules.

## Install [pre-commit](https://pre-commit.com)
See https://pre-commit.com/#install but the following might work.
Unfortunately, exact formatting used depends on the `clang-format` version. Therefore,
you do have to install the same version as what is currently used in our GitHub Action.

pip install pre-commit
## Installation of software

If this fails with a permission error, try adding `--user` to the command.
We highly recommend to use `conda`:
```sh
cd /whereever/STIR
conda env create --file pre-commit-environment.yml
conda activate pre-commit-env
```

If that fails with a message about `PyYAML` and `distutils`, try
Alternative:

pip install --ignore-installed PyYAML
1. Install Python and pip

## Install clang-format
### debian/Ubuntu
sudo apt install clang-format
### MacOS
brew install clang-format
### Others
search the internet and tell us
2. Install [pre-commit](https://pre-commit.com). See https://pre-commit.com/#install but the following might work.
```sh
pip install pre-commit
```
If this fails with a permission error, try adding `--user` to the command. If that fails with a message about `PyYAML` and `distutils`, try
```sh
pip install --ignore-installed PyYAML
```

3. Install clang-format (but use correct version). At the time of writing, on Ubuntu 22.04, you can do
```sh
sudo apt install clang-format
```

## Enable pre-commit hooks

```sh
cd /whereever/STIR
pre-commit install
```

If you need to work with a branch that was forked prior to in inclusion of clang-format, you will need to temporarily disable/uninstall pre-commit again:
If you need to work with a branch that was forked prior to our use of `clang-format`, you will need to temporarily disable/uninstall pre-commit again:

pre-commit uninstall

or once-off with
or one-off with

git commit --no-verify

You will then need to run `pre-commit run --all-files` when done before we will merge your pull request.
7 changes: 7 additions & 0 deletions pre-commit-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: pre-commit-env
channels:
- conda-forge
- defaults
dependencies:
- pre-commit
- clang-format=14.0

0 comments on commit 41c74f5

Please sign in to comment.