Skip to content

Commit 54f192f

Browse files
authored
Add pre-commit (#853)
* Added a pre-commit configuration The configuration runs the formatters currently used by the project, i.e. clang-format v15 and black v25. * Removed the format commands from the Makefile These will now be handled automatically with pre-commit and GitHub workflows. * Added a GitHub workflow that runs pre-commit * Removed Clang Tools from SuperBuild This module was already deprecated and is being removed since ClangFormat is now managed by pre-commit. * Removed formatting from existing CI This is because formatting is now handled via the pre-commit CI. Note that pylint was removed here as well since this is the only place in the project that it is used. * Removed run-clang-format.sh CI scripts This has been replaced by pre-commit. * Updated clang-format pre-commit configuration to include Java API * Removed clang-format from Java JNI script * Removed black from Python API dependencies This is because black is now managed by pre-commit. * Update formatting related documentation Specifically, clang-format was dropped from the Java API documentation and pre-commit in now mentioned in the contributing documentation. * Corrected external sources directory path in pre-commit configuration
1 parent bd644a0 commit 54f192f

11 files changed

Lines changed: 61 additions & 188 deletions

File tree

.github/workflows/ci-linters.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Run pre-commit
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- name: Checkout TileDB-VCF
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.12"
19+
20+
- name: Restore pre-commit cache
21+
uses: actions/cache@v4
22+
with:
23+
path: ~/.cache/pre-commit
24+
key: pre-commit-ubuntu-24.04-3.12-${{ hashFiles('.github/workflows/lint-python.yml', '.pre-commit-config.yaml') }}
25+
26+
- name: Install pre-commit
27+
run: pip -v install pre-commit
28+
29+
- name: Log pip dependencies
30+
run: pip list
31+
32+
- name: Run pre-commit hooks on all files
33+
run: pre-commit run -a -v

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: v15.0.7
4+
hooks:
5+
- id: clang-format
6+
types_or: [c++, c]
7+
files: 'libtiledbvcf/.*|apis/java/src/main/java/io/tiledb/libvcfnative/.*|apis/python/src/.*'
8+
exclude: 'libtiledbvcf/external/.*'
9+
- repo: https://github.com/psf/black
10+
rev: 25.9.0
11+
hooks:
12+
- id: black
13+
files: 'apis/python/src/.*'

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ Thanks for your interest in TileDB-VCF. The notes below give some pointers for f
1818
- Make changes locally, then rebuild as appropriate for the level of changes (e.g.: `make` for `libtilebvcf` or `python setup.py develop` for `apis/python`).
1919
- Make sure to run `make check`, or `pytest` to verify changes against tests (add new tests where applicable).
2020
- Please submit [pull requests](https://help.github.com/en/desktop/contributing-to-projects/creating-a-pull-request) against the default [`main` branch of TileDB-VCF](https://github.com/TileDB-Inc/TileDB-VCF/tree/main).
21+
- If you edit the Python files, please run the pre-commit hooks
22+
23+
```sh
24+
python -m venv ./pre-commit
25+
source ./pre-commit/bin/activate
26+
python -m pip -v install pre-commit
27+
pre-commit run -a -v
28+
deactivate
29+
```

Makefile

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,6 @@ docs:
5151
@rm tiledbvcf
5252
quarto render --fail-if-warnings
5353

54-
# format
55-
# -------------------------------------------------------------------
56-
.PHONY: check-format
57-
check-format:
58-
@./ci/run-clang-format.sh . clang-format 0 \
59-
`find libtiledbvcf/src -name "*.cc" -or -name "*.h"`
60-
@./ci/run-clang-format.sh . clang-format 0 \
61-
`find libtiledbvcf/test -name "*.cc" -or -name "*.h"`
62-
63-
.PHONY: format
64-
format:
65-
@./ci/run-clang-format.sh . clang-format 1 \
66-
`find libtiledbvcf/src -name "*.cc" -or -name "*.h"`
67-
@./ci/run-clang-format.sh . clang-format 1 \
68-
`find libtiledbvcf/test -name "*.cc" -or -name "*.h"`
69-
7054
# venv
7155
# -------------------------------------------------------------------
7256
.PHONY: venv
@@ -116,8 +100,6 @@ Rules:
116100
notebooks Execute notebooks and update cell outputs
117101
docs Render the documentation
118102
docker Build and test docker images
119-
check-format Run C++ format check
120-
format Run C++ format
121103
venv Create a virtual environment
122104
wheel Build python wheel
123105
clean Remove build artifacts

apis/java/src/main/java/io/tiledb/libvcfnative/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ To build the binding you must first compile the java file to a header file by us
55
javac -cp .:commons-io-2.14.0.jar *.java -h .;
66
```
77

8-
Next, format the header and replace the old
8+
Next, replace the old header
99
```
10-
clang-format -i io_tiledb_libvcfnative_LibVCFNative.h;
1110
mv io_tiledb_libvcfnative_LibVCFNative.h LibVCFNative.h;
1211
```
1312

1413
Finally, remove all ```.class``` files
1514

1615
```
1716
rm *.class;
18-
```
17+
```
18+
19+
This process can be done autmatically using the `genearteJNI.sh` script.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
javac -cp .:commons-io-2.14.0.jar *.java -h .;
2-
clang-format -i io_tiledb_libvcfnative_LibVCFNative.h;
32
mv io_tiledb_libvcfnative_LibVCFNative.h LibVCFNative.h;
4-
rm *.class;
3+
rm *.class;

apis/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies = ["pandas", "pyarrow>=14.0.1", "numpy"]
4444

4545
[project.optional-dependencies]
4646
test = ["pytest", "tiledb"]
47-
dev = ["black", "tiledb-cloud", "pybind11[global]"]
47+
dev = ["tiledb-cloud", "pybind11[global]"]
4848

4949
[project.urls]
5050
homepage = "https://tiledb.com"

ci/azure-linux_mac.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ steps:
66
addToPath: true
77
displayName: 'Set Python Version'
88

9-
- script: python -m pip install --upgrade black pylint
10-
displayName: 'Install black (formatter) and pylint (linter)'
11-
12-
- script: black --check .
13-
displayName: 'Test Formatting'
14-
15-
# pylint cannot lint all files in a directory, it requires an __init__.py file (https://github.com/PyCQA/pylint/issues/352)
16-
# run pylint on all directories with an __init__.py file
17-
- bash: |
18-
set -eux pipefail
19-
find . -name __init__.py | xargs dirname | xargs pylint --disable=all --enable=E1101
20-
displayName: 'Check function name/signature mismatches'
21-
22-
- bash: |
23-
set -e pipefail
24-
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
25-
sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main'
26-
sudo apt-get install -y clang-format-15
27-
src=$BUILD_REPOSITORY_LOCALPATH/libtiledbvcf
28-
cd $BUILD_REPOSITORY_LOCALPATH
29-
ci/run-clang-format.sh $src clang-format-15 0 \
30-
$(find $src/src $src/test -name "*.cc" -or -name "*.c" -or -name "*.h")
31-
apis=$BUILD_REPOSITORY_LOCALPATH/apis
32-
ci/run-clang-format.sh $apis clang-format-15 0 \
33-
$(find $apis -name "*.cc" -or -name "*.c" -or -name "*.h")
34-
condition: eq(variables['Agent.OS'], 'Linux')
35-
displayName: 'Check formatting (Linux only)'
36-
379
- bash: |
3810
set -e pipefail
3911

ci/run-clang-format.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

libtiledbvcf/cmake/Modules/FindClangTools.cmake

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)