Skip to content

Commit a085b62

Browse files
Merge pull request #37 from kchason/pre-commit-black
Pre-Commit
2 parents 4617cf4 + 0dfb21c commit a085b62

File tree

7 files changed

+48
-24
lines changed

7 files changed

+48
-24
lines changed

.github/workflows/cicd.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
uses: actions/setup-python@v2
3636
with:
3737
python-version: ${{ matrix.python-version }}
38+
- name: Pre-commit Checks
39+
run: |
40+
pip -q install pre-commit
41+
pre-commit run --all-files
3842
- name: Start from clean state
3943
run: make clean
4044
- name: Run tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.swp
33
.DS_Store
44
.idea/
5+
.venv-pre-commit/
56
__pycache__
67
build/
78
case_utils.egg-info/

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 22.3.0
4+
hooks:
5+
- id: black

CONTRIBUTE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@ make check
3333
git commit -m "Build CASE 0.6.0 monolithic .ttl files" case_utils/ontology/case-0.6.0-subclasses.ttl case_utils/ontology/case-0.6.0.ttl
3434
git commit -m "Update CASE ontology pointer to version 0.6.0" dependencies/CASE case_utils/ontology/version_info.py
3535
```
36+
37+
This project uses [the `pre-commit` tool](https://pre-commit.com/) for linting The easiest way to install it is with `pip`:
38+
```bash
39+
pip install pre-commit
40+
pre-commit --version
41+
```
42+
43+
The `pre-commit` tool hooks into Git's commit machinery to run a set of linters and static analyzers over each change. To install `pre-commit` into Git's hooks, run:
44+
```bash
45+
pre-commit install
46+
```

Makefile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ $(error Unable to determine CASE version)
2121
endif
2222

2323
all: \
24-
.ontology.done.log
24+
.ontology.done.log \
25+
.venv-pre-commit/var/.pre-commit-built.log
2526

2627
.PHONY: \
2728
download
@@ -54,8 +55,32 @@ all: \
5455
test -r case_utils/ontology/case-$(case_version)-subclasses.ttl
5556
touch $@
5657

58+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
59+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
60+
.venv-pre-commit/var/.pre-commit-built.log:
61+
rm -rf .venv-pre-commit
62+
test -r .pre-commit-config.yaml \
63+
|| (echo "ERROR:Makefile:pre-commit is expected to install for this repository, but .pre-commit-config.yaml does not seem to exist." >&2 ; exit 1)
64+
$(PYTHON3) -m venv \
65+
.venv-pre-commit
66+
source .venv-pre-commit/bin/activate \
67+
&& pip install \
68+
--upgrade \
69+
pip \
70+
setuptools \
71+
wheel
72+
source .venv-pre-commit/bin/activate \
73+
&& pip install \
74+
pre-commit
75+
source .venv-pre-commit/bin/activate \
76+
&& pre-commit install
77+
mkdir -p \
78+
.venv-pre-commit/var
79+
touch $@
80+
5781
check: \
58-
.ontology.done.log
82+
.ontology.done.log \
83+
.venv-pre-commit/var/.pre-commit-built.log
5984
$(MAKE) \
6085
PYTHON3=$(PYTHON3) \
6186
--directory tests \

tests/Makefile

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ check: \
6767
--ignore case_utils \
6868
--log-level=DEBUG
6969

70-
# TODO - Need to settle on policy for incorporating this and 'format' recipe into CI.
71-
# https://case.atlassian.net/browse/AC-215
72-
# https://case.atlassian.net/browse/AC-216
73-
check-black: \
74-
.venv.done.log
75-
source venv/bin/activate \
76-
&& black \
77-
--check \
78-
$(top_srcdir)/case_utils \
79-
$$PWD
80-
8170
check-case_utils: \
8271
.venv.done.log
8372
$(MAKE) \
@@ -114,13 +103,3 @@ clean:
114103

115104
download: \
116105
.venv.done.log
117-
118-
# TODO - Need to settle on policy for incorporating this and 'check-black' recipe into CI.
119-
# https://case.atlassian.net/browse/AC-215
120-
# https://case.atlassian.net/browse/AC-216
121-
format: \
122-
.venv.done.log
123-
source venv/bin/activate \
124-
&& black \
125-
$(top_srcdir)/case_utils \
126-
$$PWD

tests/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PyLD
2-
black
32
mypy
43
pytest
54
python-dateutil

0 commit comments

Comments
 (0)