-
Notifications
You must be signed in to change notification settings - Fork 32
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 black and isort for auto style formatting #58
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Black Linter | ||
|
||
# This allows Black be called from the isort workflow | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
black-linter: | ||
name: Run Black | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Determine Branch Name | ||
run: | | ||
if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV | ||
else | ||
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) | ||
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
fi | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ env.BRANCH_NAME }} | ||
|
||
- name: Pull latest changes | ||
run: git pull origin ${{ env.BRANCH_NAME }} | ||
|
||
- name: Run Black formatter | ||
uses: psf/black@stable | ||
with: | ||
options: "--verbose" | ||
src: "." | ||
jupyter: true | ||
|
||
- name: Push changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: Apply black formatting changes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Code Formatter | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
isort: | ||
name: Run Isort | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Determine Branch Name | ||
run: | | ||
if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV | ||
else | ||
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) | ||
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
fi | ||
Comment on lines
+15
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code for determining the branch name was only necessary if the workflow were to run on active PRs. This will not break the code but is no longer necessary. However, if we were to switch to have the workflow run on PRs then integrating that change will be very easy if we keep this code (addressed by the comment). Otherwise, it will take some work to change that behavior. Let me know if you think we should keep this code or not. |
||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ env.BRANCH_NAME }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Run Isort | ||
run: pip install isort==5.13.2 && isort . | ||
|
||
- name: Push changes | ||
uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: Apply isort formatting changes | ||
|
||
# Ensure Black runs after Isort has completed | ||
black: | ||
needs: isort | ||
uses: ./.github/workflows/black.yml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as previous comment.