-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from DEEPDIP-project/precommit
Add precommit hooks for formatting and notebook creation
- Loading branch information
Showing
27 changed files
with
8,712 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Format suggestions | ||
on: | ||
push: | ||
pull_request: | ||
jobs: | ||
code-style: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/cache@v1 | ||
- uses: julia-actions/setup-julia@v1 | ||
- name: format code | ||
run: | | ||
julia -e ' | ||
import Pkg; | ||
Pkg.add("JuliaFormatter"); | ||
using JuliaFormatter; | ||
JuliaFormatter.format(".") | ||
' | ||
- name: Check for uncommitted changes | ||
run: git diff --exit-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
examples/*.ipynb | ||
examples/*.md | ||
examples/test* | ||
.vscode | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
repos: | ||
- repo: "local" | ||
hooks: | ||
- id: "format-julia" | ||
name: "Format with JuliaFormatter" | ||
entry: "julia format_julia_files.jl" | ||
language: "system" | ||
|
||
- id: "build-notebooks" | ||
name: "Build Notebooks" | ||
language: "script" | ||
entry: "./build_notebooks.sh" | ||
files: 'examples/.*\.jl$' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Pre-commit | ||
We use pre-commit to run some checks before you commit your changes. | ||
|
||
To install it follow instructions [here](https://pre-commit.com/) and then run: | ||
|
||
```bash | ||
pre-commit install | ||
``` | ||
|
||
in the root of the repository. | ||
|
||
Now every time you commit your changes, pre-commit will run a formatting check and create any notebooks whose source files have changed. | ||
If it made any changes, you'll have to manually stage them and commit again. | ||
|
||
If for some reason you want to skip pre-commit checks, you can use the `--no-verify` flag when committing (perhaps to correct formatting in a separate commit for clarity). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
echo "Building notebooks..." | ||
|
||
# pre-commit passes staged files as arguments | ||
FILENAMES=$(echo "$@" | grep 'examples/.*\.jl$') | ||
echo "Files changed: $FILENAMES" | ||
|
||
if [ -n "$FILENAMES" ]; then | ||
julia make_examples.jl $FILENAMES | ||
else | ||
echo "No Julia notebook source files changed." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Import the necessary packages" | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"outputs": [], | ||
"cell_type": "code", | ||
"source": [ | ||
"using CoupledNODE" | ||
], | ||
"metadata": {}, | ||
"execution_count": null | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Let's greet the world" | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"outputs": [], | ||
"cell_type": "code", | ||
"source": [ | ||
"helloworld()" | ||
], | ||
"metadata": {}, | ||
"execution_count": null | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"---\n", | ||
"\n", | ||
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" | ||
], | ||
"metadata": {} | ||
} | ||
], | ||
"nbformat_minor": 3, | ||
"metadata": { | ||
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.10.2" | ||
}, | ||
"kernelspec": { | ||
"name": "julia-1.10", | ||
"display_name": "Julia 1.10.2", | ||
"language": "julia" | ||
} | ||
}, | ||
"nbformat": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Import the necessary packages | ||
|
||
```julia | ||
using CoupledNODE | ||
``` | ||
|
||
Let's greet the world | ||
|
||
```julia | ||
helloworld() | ||
``` | ||
|
||
--- | ||
|
||
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* | ||
|
Oops, something went wrong.