Skip to content
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

Add pre-commit #4

Merged
merged 2 commits into from
Aug 21, 2024
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
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E501
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to title 17 Section 105 of the
# United States Code this software is not subject to copyright
# protection and is in the public domain. NIST assumes no
# responsibility whatsoever for its use by other parties, and makes
# no guarantees, expressed or implied, about its quality,
# reliability, or any other characteristic.
#
# We would appreciate acknowledgement if the software is used.

name: Continuous Integration

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '15 5 * * TUE'

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.9'
- '3.12'

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Pre-commit Checks
run: |
pip -q install pre-commit
pre-commit run --all-files
43 changes: 43 additions & 0 deletions .github/workflows/supply-chain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to title 17 Section 105 of the
# United States Code this software is not subject to copyright
# protection and is in the public domain. NIST assumes no
# responsibility whatsoever for its use by other parties, and makes
# no guarantees, expressed or implied, about its quality,
# reliability, or any other characteristic.
#
# We would appreciate acknowledgement if the software is used.

# This workflow uses Make to review direct dependencies of this
# repository.

name: Supply Chain

on:
schedule:
- cron: '15 5 * * 1,2,3,4,5'

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.9'
- '3.12'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Review dependencies
run: make check-supply-chain
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.idea
__pycache__
.ipynb_checkpoints
.venv-pre-commit
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]
88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/make -f

# Portions of this file contributed by NIST are governed by the
# following statement:
#
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to title 17 Section 105 of the
# United States Code this software is not subject to copyright
# protection and is in the public domain. NIST assumes no
# responsibility whatsoever for its use by other parties, and makes
# no guarantees, expressed or implied, about its quality,
# reliability, or any other characteristic.
#
# We would appreciate acknowledgement if the software is used.

SHELL := /bin/bash

PYTHON3 ?= python3

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

.PHONY: \
check-supply-chain \
check-supply-chain-pre-commit

# 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: \
.venv-pre-commit/var/.pre-commit-built.log

check-supply-chain: \
check-supply-chain-pre-commit

# Update pre-commit configuration and use the updated config file to
# review code. Only have Make exit if 'pre-commit run' modifies files.
check-supply-chain-pre-commit: \
.venv-pre-commit/var/.pre-commit-built.log
source .venv-pre-commit/bin/activate \
&& pre-commit autoupdate
git diff \
--exit-code \
.pre-commit-config.yaml \
|| ( \
source .venv-pre-commit/bin/activate \
&& pre-commit run \
--all-files \
--config .pre-commit-config.yaml \
) \
|| git diff \
--stat \
--exit-code \
|| ( \
echo \
"WARNING:Makefile:pre-commit configuration can be updated. It appears the updated would change file formatting." \
>&2 \
; exit 1 \
)
@git diff \
--exit-code \
.pre-commit-config.yaml \
|| echo \
"INFO:Makefile:pre-commit configuration can be updated. It appears the update would not change file formatting." \
>&2

clean:
Loading