diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 2ad1ebf..226ed72 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -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 diff --git a/.gitignore b/.gitignore index f45a3b3..2a4c981 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.swp .DS_Store .idea/ +.venv-pre-commit/ __pycache__ build/ case_utils.egg-info/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8bf5f39 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: +- repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index c7f9787..2e73b90 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -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 +``` \ No newline at end of file diff --git a/Makefile b/Makefile index faf4d2f..896b5cf 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 \ diff --git a/tests/Makefile b/tests/Makefile index 327c1ab..b75a75a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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) \ @@ -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 diff --git a/tests/requirements.txt b/tests/requirements.txt index acd3ddc..f913d96 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,5 +1,4 @@ PyLD -black mypy pytest python-dateutil