Skip to content

Commit

Permalink
Merge pull request #25 from DEEPDIP-project/precommit
Browse files Browse the repository at this point in the history
Add precommit hooks for formatting and notebook creation
  • Loading branch information
APJansen authored Mar 26, 2024
2 parents 56e7069 + 41890f3 commit b3842f0
Show file tree
Hide file tree
Showing 27 changed files with 8,712 additions and 13 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/Format.yaml
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
examples/*.ipynb
examples/*.md
examples/test*
.vscode

Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
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$'

15 changes: 15 additions & 0 deletions CONTRIBUTING.md
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).
13 changes: 13 additions & 0 deletions build_notebooks.sh
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
60 changes: 60 additions & 0 deletions examples/00-Toy.ipynb
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
}
16 changes: 16 additions & 0 deletions examples/00-Toy.md
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).*

Loading

0 comments on commit b3842f0

Please sign in to comment.