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

Update CI & use pre-commit for linting #163

Merged
merged 13 commits into from
Dec 22, 2023
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
# there is no conda support for dependabot so this is the closest analog
# since the conda deps are also built from pyproject.toml it should work well enough
updates:
- package-ecosystem: "pip"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
79 changes: 44 additions & 35 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,70 @@
name: Build Docs
name: Build Documentation

# We don't want pushes (or PRs) to gh-pages to kick anything off
on:
workflow_dispatch:
push:
branches: [ main ]
branches: [main]
paths:
- tests/*
- hydromt/*
- docs/*
- examples/*
- pyproject.toml
pull_request:
branches: [ main ]
branches: [main]
paths:
- tests/*
- hydromt/*
- docs/*
- examples/*
- pyproject.toml

jobs:
# Build docs on Linux
Docs:
name: linux docs
runs-on: ubuntu-latest
test-docs:
env:
DOC_VERSION: dev
defaults:
run:
shell: bash -l {0}
PYDEVD_DISABLE_FILE_VALIDATION: 1
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

# - name: Get tags
# run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: checkout code
uses: actions/checkout@v3

- name: Setup environment
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.10"
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/hydromt-sfincs-dev.yml
activate-environment: hydromt-sfincs-dev
python-version: '3.11'
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true

- name: Install hydromt-sfincs
run: flit install
- name: Setup env
run: |
python make_env.py full -p 3.11 -n hydromt-sfincs -o environment-doc.yml
mamba env create -f environment-doc.yml
mamba run -n hydromt-sfincs pip install -e .

# Move examples folder before make html for nbsphinx
- name: Build docs
# if we're not publishing we don't have to write them, so we might as well
# save ourself a bunch of IO time
- name: Build dummy docs
if: ${{ github.event_name == 'pull_request' }}
run: |
pushd docs
make html
popd
mamba run -n hydromt-sfincs sphinx-build ./docs ./docs/_build -b dummy -W

# This overrides the version "dev" with the proper version if we're building off a
# branch that's not master (which is confined to n.nn.x above) or on a tag.
- name: Set doc version
run: echo "DOC_VERSION=$(python -c 'from hydromt_sfincs import __version__ as v; print("dev" if "dev" in v else "v"+v)')" >> $GITHUB_ENV
- name: Build html docs
if: ${{ github.event_name != 'pull_request' }}
run: |
mamba run -n hydromt-sfincs sphinx-build -M html ./docs ./docs/_build -W
echo "DOC_VERSION=$(mamba run -n hydromt-sfincs python -c 'from hydromt_sfincs import __version__ as v; print("dev" if "dev" in v else "v"+v)')" >> $GITHUB_ENV

- name: Upload to GitHub Pages
if: ${{ github.event_name != 'pull_request'}}
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}path
publish_dir: ./docs/_build/html
exclude_assets: '.buildinfo,_sources/*,_examples/*.ipynb'
destination_dir: ./${{ env.DOC_VERSION }}
keep_files: false
full_commit_message: Deploy ${{ env.DOC_VERSION }} to GitHub Pages
full_commit_message: Deploy ${{ env.DOC_VERSION }} to GitHub Pages
16 changes: 16 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Linting

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v5
with:
python-version: 3.11
- uses: pre-commit/[email protected]
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4

- uses: actions/setup-python@v5
name: Install Python
with:
python-version: 3.8
python-version: 3.11

- name: Install dependencies
run: |
Expand Down Expand Up @@ -113,4 +113,4 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
verbose: true
verbose: true
70 changes: 42 additions & 28 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
name: Tests stable
name: Tests

on:
push:
branches: [ main ]
branches: [main]
paths:
- tests/*
- hydromt_sfincs/*
- pyproject.toml
pull_request:
branches: [ main ]
branches: [main]
paths:
- tests/*
- hydromt_sfincs/*
- pyproject.toml


jobs:
Test:
name: ${{ matrix.os }} - py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
build:
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"] #, "macos-latest", "windows-latest"]
python-version: ["3.10", "3.11"] # TODO: add 3.9 back

os: [ubuntu-latest]
python-version: ['3.10','3.11'] # '3.9'
runs-on: ubuntu-latest
timeout-minutes: 30
concurrency:
group: ${{ github.workflow }}-${{ matrix.python-version }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2

- uses: actions/checkout@v3

- uses: actions/setup-python@v5
id: py
with:
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/hydromt-sfincs-dev.yml
activate-environment: hydromt-sfincs-dev

- name: Conda info
run: |
conda info
conda list
# caching, see https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
cache: 'pip'
cache-dependency-path: pyproject.toml

- name: Intall hydromt_sfincs
run: pip install .
# true if cache-hit occurred on the primary key
- name: Cache hit
run: echo '${{ steps.py.outputs.cache-hit }}'

- name: Test
run: python -m pytest --verbose --cov=hydromt_sfincs --cov-report xml
# build environment with pip
- name: Install hydromt-sfincs
run: |
pip install --upgrade pip
pip install .[test,examples]

- name: Check style
run: black --check .
# run test
- name: Test
run: |
export NUMBA_DISABLE_JIT=1
python -m pytest --verbose --cov=hydromt_sfincs --cov-report xml

# upload coverage
- uses: codecov/codecov-action@v3
73 changes: 43 additions & 30 deletions .github/workflows/tests_dev.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
name: Tests dev
name: Tests with HydroMT dev

on:
# trigger weekly on monday at 00:00 UTC
schedule:
- cron: '0 0 * * 1'
push:
branches: [ main ]
branches: [main]
paths:
- tests/*
- hydromt_sfincs/*
- pyproject.toml
pull_request:
branches: [ main ]
branches: [main]
paths:
- tests/*
- hydromt_sfincs/*
- pyproject.toml


jobs:
Test:
name: ubuntu-latest - py3.9
runs-on: "ubuntu-latest"
build:
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false

runs-on: ubuntu-latest
timeout-minutes: 30
concurrency:
group: ${{ github.workflow }}-${{ matrix.python-version }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.9"
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/hydromt-sfincs-dev.yml
activate-environment: hydromt-sfincs-dev

- name: Conda info
run: |
conda info
conda list

- name: Intall hydromt core dev version
run: pip install git+https://github.com/Deltares/hydromt.git
- uses: actions/checkout@v3

- name: Intall hydromt_sfincs
run: pip install .
- uses: actions/setup-python@v5
id: py311
with:
python-version: 3.11
# caching, see https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
cache: 'pip'
cache-dependency-path: pyproject.toml

- name: Test
run: python -m pytest --verbose --cov=hydromt_sfincs --cov-report xml
# true if cache-hit occurred on the primary key
- name: Cache hit
run: echo '${{ steps.py311.outputs.cache-hit }}'

- name: Check style
run: black --check .
# build environment with pip
- name: Install hydromt-sfincs
run: |
pip install --upgrade pip
pip install .[test,examples]
pip install git+https://github.com/Deltares/hydromt.git

- uses: codecov/codecov-action@v3
# run test
- name: Test
run: |
export NUMBA_DISABLE_JIT=1
python -m pytest --verbose
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ venv.bak/

# dask
dask-worker-space/

#ruff linting
.ruff_cache
.envrc
pyrightconfig.json

pixi.lock
.pixi
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: check-json
- id: debug-statements
- id: mixed-line-ending
# make sure notebooks are stripped of output before committing
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: nbstripout
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.0
hooks:
- id: black-jupyter
description: Black, with Jupyter Notebook support
# - repo: https://github.com/astral-sh/ruff-pre-commit
# rev: v0.1.2
# hooks:
# - id: ruff
# args: [--fix, --exit-non-zero-on-fix]
# - id: ruff-format
# - repo: https://github.com/python-jsonschema/check-jsonschema
# rev: 0.24.0
# hooks:
# - id: check-github-workflows
# - id: check-github-actions
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
],
"access_right": "open",
"license": "GPL-3.0"
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
Loading
Loading