Skip to content

Commit

Permalink
Merge pull request #71 from nox1134/issue-68
Browse files Browse the repository at this point in the history
Use pre-commit CI to automatically fix code style issues
  • Loading branch information
TimidRobot authored Mar 13, 2024
2 parents 330a8f4 + f1439a4 commit f506109
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 38 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/python_static_analysis.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Static Analysis

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

jobs:
job:
runs-on: ubuntu-latest

steps:

# https://github.com/actions/setup-python
- name: Install Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install black 'black[jupyter]' flake8 isort
pip install pre-commit
# https://github.com/actions/checkout
- name: Checkout quantifying
uses: actions/checkout@v4
with:
path: quantifying

- name: pre-commit
run: pre-commit run --show-diff-on-failure --color=always --all-files
working-directory: ./quantifying
57 changes: 57 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.11

ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: []
submodules: false

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: destroyed-symlinks
#- id: end-of-file-fixer
#- id: mixed-line-ending
# args:
# - --fix=no
#- id: trailing-whitespace

- repo: local
hooks:
- id: black
name: "Black"
entry: black
language: system
types: ["file", "python", "text"]

- id: flake8
name: "Flake8"
entry: flake8
language: system
types: ["file", "python", "text"]

- id: isort
name: "isort"
entry: isort --filter-files
language: system
types: ["file", "python", "text"]
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ follow these steps:
### Static analysis
#### Using [`pre-commit`][pre-commit]
1. Install pre-commit
- Using pip:
```shell
pip install pre-commit
```
- Using homebrew:
```shell
brew install pre-commit
```
2. Install the git hook scripts
```shell
pre-commit install
```
It will run on every commit automatically.
#### Using [`dev/tools.sh`][tools-sh] helper script
The [`dev/tools.sh`][tools-sh] helper script runs the static analysis tools
(`black`, `flake8`, and `isort`):
```shell
Expand All @@ -89,6 +109,7 @@ directories to check:
```
[tools-sh]: /dev/tools.sh
[pre-commit]: https://pre-commit.com/
### Resources
Expand All @@ -100,12 +121,15 @@ directories to check:
- [isort][isort]: _A Python utility / library to sort imports_
- (It doesn't import any libraries, it only sorts and formats them.)
- [ppypa/pipenv][pipenv]: _Python Development Workflow for Humans._
- [pre-commit][pre-commit]: _A framework for managing and maintaining
multi-language pre-commit hooks._

[ccospyguide]: https://opensource.creativecommons.org/contributing-code/python-guidelines/
[black]: https://github.com/psf/black
[flake8]: https://gitlab.com/pycqa/flake8
[isort]: https://pycqa.github.io/isort/
[pipenv]: https://github.com/pypa/pipenv
[pre-commit]: https://pre-commit.com/


### GitHub Actions
Expand All @@ -115,7 +139,7 @@ GitHub Actions workflow performs static analysis (`black`, `flake8`, and
`isort`) on committed changes. The workflow is triggered automatically when you
push changes to the main branch or open a pull request.

[workflow-static-analysis]: .github/workflows/python_static_analysis.yml
[workflow-static-analysis]: .github/workflows/static_analysis.yml


## Data sources
Expand Down

0 comments on commit f506109

Please sign in to comment.