Skip to content

Pre-Commit #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Pre-commit Checks
run: |
pip -q install pre-commit
pre-commit run --all-files
- name: Start from clean state
run: make clean
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.swp
.DS_Store
.idea/
.venv-pre-commit/
__pycache__
build/
case_utils.egg-info/
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
11 changes: 11 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ make check
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
git commit -m "Update CASE ontology pointer to version 0.6.0" dependencies/CASE case_utils/ontology/version_info.py
```

This project uses [the `pre-commit` tool](https://pre-commit.com/) for linting The easiest way to install it is with `pip`:
```bash
pip install pre-commit
pre-commit --version
```

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:
```bash
pre-commit install
```
29 changes: 27 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ $(error Unable to determine CASE version)
endif

all: \
.ontology.done.log
.ontology.done.log \
.venv-pre-commit/var/.pre-commit-built.log

.PHONY: \
download
Expand Down Expand Up @@ -54,8 +55,32 @@ all: \
test -r case_utils/ontology/case-$(case_version)-subclasses.ttl
touch $@

# This virtual environment is meant to be built once and then persist, even through 'make clean'.
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
.venv-pre-commit/var/.pre-commit-built.log:
rm -rf .venv-pre-commit
test -r .pre-commit-config.yaml \
|| (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)
$(PYTHON3) -m venv \
.venv-pre-commit
source .venv-pre-commit/bin/activate \
&& pip install \
--upgrade \
pip \
setuptools \
wheel
source .venv-pre-commit/bin/activate \
&& pip install \
pre-commit
source .venv-pre-commit/bin/activate \
&& pre-commit install
mkdir -p \
.venv-pre-commit/var
touch $@

check: \
.ontology.done.log
.ontology.done.log \
.venv-pre-commit/var/.pre-commit-built.log
$(MAKE) \
PYTHON3=$(PYTHON3) \
--directory tests \
Expand Down
21 changes: 0 additions & 21 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ check: \
--ignore case_utils \
--log-level=DEBUG

# TODO - Need to settle on policy for incorporating this and 'format' recipe into CI.
# https://case.atlassian.net/browse/AC-215
# https://case.atlassian.net/browse/AC-216
check-black: \
.venv.done.log
source venv/bin/activate \
&& black \
--check \
$(top_srcdir)/case_utils \
$$PWD

check-case_utils: \
.venv.done.log
$(MAKE) \
Expand Down Expand Up @@ -114,13 +103,3 @@ clean:

download: \
.venv.done.log

# TODO - Need to settle on policy for incorporating this and 'check-black' recipe into CI.
# https://case.atlassian.net/browse/AC-215
# https://case.atlassian.net/browse/AC-216
format: \
.venv.done.log
source venv/bin/activate \
&& black \
$(top_srcdir)/case_utils \
$$PWD
1 change: 0 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PyLD
black
mypy
pytest
python-dateutil
Expand Down