From 91eeb0074635726930a76dcafe712a9d6f8962d5 Mon Sep 17 00:00:00 2001 From: kchason Date: Mon, 21 Mar 2022 14:33:31 -0400 Subject: [PATCH 1/4] CI job for black formatting --- .github/workflows/ci.yml | 4 ++++ .pre-commit-config.yaml | 5 +++++ CONTRIBUTE.md | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4d0c35..f92256a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.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/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..47b80d1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: +- repo: https://github.com/psf/black + rev: 22.1.0 + hooks: + - id: black diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 6d1e781..9619b97 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -32,3 +32,14 @@ make check git commit -m "Update CASE ontology pointer to version 0.6.0" dependencies/CASE case_utils/ontology/version_info.py git commit -m "Build CASE 0.6.0.ttl" case_utils/ontology/case-0.6.0.ttl ``` + +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 From a170bb1df7a97fbacc1fa06f4dd06af631e0c0ea Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Tue, 3 May 2022 13:51:37 -0400 Subject: [PATCH 2/4] Add pre-commit and configure hook to review with Black Disclaimer: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * [AC-215] Evaluate pre-commit usage on casework repositories * [AC-216] Apply Black to all casework Python code bases * https://github.com/casework/CASE-Utilities-Python/pull/37 Signed-off-by: Alex Nelson --- .gitignore | 1 + Makefile | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) 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/Makefile b/Makefile index aacc5ea..3997289 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 @@ -64,8 +65,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 \ From 0ecd01ff17b1c6dd5c9667adde9b7af37def541f Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Tue, 3 May 2022 13:53:30 -0400 Subject: [PATCH 3/4] Move Black-based auto-formatting to pre-commit Disclaimer: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * [AC-215] Evaluate pre-commit usage on casework repositories * [AC-216] Apply Black to all casework Python code bases * https://github.com/casework/CASE-Utilities-Python/pull/37 Signed-off-by: Alex Nelson --- tests/Makefile | 21 --------------------- tests/requirements.txt | 1 - 2 files changed, 22 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 3b0fe93..25fa731 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) \ @@ -112,13 +101,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 From 63f01d4cfe769e41f04a9cc4e0ab0ff6d024ee3e Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Tue, 3 May 2022 13:55:14 -0400 Subject: [PATCH 4/4] Run pre-commit autoupdate Disclaimer: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * [AC-215] Evaluate pre-commit usage on casework repositories * https://github.com/casework/CASE-Utilities-Python/pull/37 Signed-off-by: Alex Nelson --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 47b80d1..8bf5f39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 22.1.0 + rev: 22.3.0 hooks: - id: black