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

Automatic formatting via black + CI support #176

Merged
merged 1 commit into from
Nov 19, 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
Empty file added .git-blame-ignore-revs
Empty file.
38 changes: 38 additions & 0 deletions .github/workflows/formatapply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: apply-code-format

on: [ workflow_dispatch ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: ""
src: "."
jupyter: true
- name: Commit Formatting
run: |
git config user.name 'Auto Format'
git config user.email '[email protected]'
if [ -z "$(git status --porcelain)" ]
then
echo "Code did not change"
else
git commit -am "Applied code formatting"
git rev-parse HEAD >> .git-blame-ignore-revs
git commit -am "Add code formatting commit to .git-blame-ignore-revs"
fi
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
branch: ci/apply-code-format
delete-branch: true
title: 'Code formatting'
body: |
Auto-generated pull request triggered by the `apply-code-format` workflow.
- Manually close and reopen this PR to trigger the CI.
- Make sure to **merge** (and not rebase) this PR so that the added commit hash in `.git-blame-ignore-revs` remains valid.
15 changes: 15 additions & 0 deletions .github/workflows/formatcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: check-code-format

on: [push, pull_request, workflow_dispatch]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: "--check --diff --color"
src: "."
jupyter: true
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def finalize_options(self):
"plot": ["matplotlib","numpy","scipy"],
"test": ["pytest", "nbval", "numpy"],
"doc": ["Sphinx", "sphinx-bootstrap-theme", "nbsphinx", "ipython", "ipykernel"], # also requires pandoc to be installed
"dev": ["black"],
},
python_requires='>=3.7', # required by packaging
)
Loading