Skip to content

Commit

Permalink
use conda for pre-commit/clang-format versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisThielemans committed May 20, 2024
1 parent 6b88234 commit 6d4faf2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 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
30 changes: 22 additions & 8 deletions documentation/devel/git-hooks.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# Developer documentation: how to install (software for) git hooks

We use [pre-commit](https://pre-commit.com) to check coding conventions, including
white-space formatting rules.

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.

## Installation of software

We highly recommend to use `conda`:
```sh
cd /whereever/STIR
conda env create --file pre-commit-environment.yml
conda activate pre-commit-env
```

### Alternative
You first need to have Python and pip

## Install [pre-commit](https://pre-commit.com)
### Install [pre-commit](https://pre-commit.com)
See https://pre-commit.com/#install but the following might work.

pip install pre-commit
Expand All @@ -13,13 +29,11 @@ If that fails with a message about `PyYAML` and `distutils`, try

pip install --ignore-installed PyYAML

## Install clang-format
### debian/Ubuntu
### Install clang-format (correct version)
At the time of writing, the `clang-format` version in `pre-commit-environment.yml`
is the same default version in Ubuntu 22.04, so if you are using that, you could do

sudo apt install clang-format
### MacOS
brew install clang-format
### Others
search the internet and tell us

## Enable pre-commit hooks
```sh
Expand All @@ -31,6 +45,6 @@ If you need to work with a branch that was forked prior to in inclusion of clang

pre-commit uninstall

or once-off with
or one-off with

git commit --no-verify
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 6d4faf2

Please sign in to comment.