Skip to content

Commit

Permalink
Fix pre-commit and QA configs (#262)
Browse files Browse the repository at this point in the history
This commit updates the pre-commit hooks to use newer versions of the plugins and also fixes the configuration to be able to run in the current monorepo layout, where git hooks are still executed from the root of the repository.

Main changes:
- Update pre-commit hook versions and settings, adding paths relative to repo root
- Add pre-commit and flake8 settings per model component folder
- Add GitHub CI action versions
- Add python caches to Github CI actions
- Update formatting in yaml and toml files
- Apply correct formatting to existing python files
  • Loading branch information
egparedes authored Sep 4, 2023
1 parent f929579 commit 10e848c
Show file tree
Hide file tree
Showing 99 changed files with 650 additions and 862 deletions.
45 changes: 35 additions & 10 deletions .github/workflows/icon4py-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,51 @@ on:
types: [submitted]

jobs:
pre-commit:
pre-commit-icon4py-model-common:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install icon4py-atmosphere-dycore
working-directory: model/atmosphere/dycore
cache: 'pip'
cache-dependency-path: |
**/pyproject.toml
**/base-requirements.txt
**/base-requirements-dev.txt
**/requirements.txt
**/requirements-dev.txt
- name: Install icon4py-common
working-directory: model/common
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r ./requirements-dev.txt
python -m pip list
- name: Run checks icon4py-model-common
run: |
pre-commit run --config model/common/.pre-commit-config.yaml --all-files
- name: Install icon4py-common
working-directory: model/common
pre-commit-icon4py-model-atmosphere-dycore:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'pip'
cache-dependency-path: |
**/pyproject.toml
**/base-requirements.txt
**/base-requirements-dev.txt
**/requirements.txt
**/requirements-dev.txt
- name: Install icon4py-model-atmosphere-dycore
working-directory: model/atmosphere/dycore
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r ./requirements-dev.txt
- name: Run checks icon4py-model
- name: Run checks icon4py-model-atmosphere-dycore
run: |
python -m pip list
pre-commit run --config model/.pre-commit-config.yaml --all-files
pre-commit run --config model/atmosphere/dycore/.pre-commit-config.yaml --all-files
11 changes: 9 additions & 2 deletions .github/workflows/icon4py-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ jobs:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install boost
run: |
sudo apt-get update
sudo apt-get install libboost-all-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
**/pyproject.toml
**/base-requirements.txt
**/base-requirements-dev.txt
**/requirements.txt
**/requirements-dev.txt
- name: Install python dependencies
run: |
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/icon4pytools-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'pip'
cache-dependency-path: |
**/pyproject.toml
**/base-requirements.txt
**/base-requirements-dev.txt
**/requirements.txt
**/requirements-dev.txt
- name: Install dependencies
working-directory: tools
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r ./requirements-dev.txt
python -m pip list
- name: Run checks
run: |
python -m pip list
pre-commit run --config tools/.pre-commit-config.yaml --all-files
11 changes: 9 additions & 2 deletions .github/workflows/icon4pytools-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ jobs:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install boost
run: |
sudo apt-get update
sudo apt-get install libboost-all-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
**/pyproject.toml
**/base-requirements.txt
**/base-requirements-dev.txt
**/requirements.txt
**/requirements-dev.txt
- name: Install python dependencies
run: |
Expand Down
137 changes: 0 additions & 137 deletions model/.pre-commit-config.yaml

This file was deleted.

File renamed without changes.
114 changes: 114 additions & 0 deletions model/atmosphere/dycore/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# NOTE: pre-commit runs all hooks from the root folder of the repository,
# as regular git hooks do. Therefore, paths passed as arguments to the plugins
# should always be relative to the root folder.

default_stages: [commit, push]
default_language_version:
python: python3.10
minimum_pre_commit_version: 2.20.0
files: "model/atmosphere/dycore/.*"

repos:
- repo: meta
hooks:
- id: check-hooks-apply
stages: [manual]
- id: check-useless-excludes
stages: [manual]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.1
hooks:
# Run only manually because it deletes comments
- id: setup-cfg-fmt
name: format setup.cfg
stages: [manual]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.6.0
hooks:
- id: pretty-format-ini
args: [--autofix]
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix, --preserve-quotes, --indent, "2"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
hooks:
- id: prettier
types_or: [markdown, json]

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: insert-license
name: add license for all ICON4Py Python source files
types: [python]
args: [--comment-style, "|#|", --license-filepath, model/.license_header.txt, --fuzzy-match-generates-todo]

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa

- repo: https://github.com/psf/black
rev: '22.3.0'
hooks:
- id: black
name: black Python formatter
args: [--config, model/atmosphere/dycore/pyproject.toml]

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
name: black Python formatter for docstrings
additional_dependencies: [black==22.3.0]

- repo: https://github.com/PyCQA/isort
rev: '5.12.0'
hooks:
- id: isort
args: [--config-root, model/atmosphere/dycore/, --resolve-all-configs]

- repo: https://github.com/PyCQA/flake8
rev: '4.0.1'
hooks:
- id: flake8
name: flake8 code style checks
additional_dependencies:
- darglint
- flake8-bugbear
- flake8-builtins
- flake8-debugger
- flake8-docstrings
- flake8-eradicate
- flake8-mutable
- pygments
args: [--config=model/atmosphere/dycore/.flake8, model/atmosphere/dycore/src/icon4py/]

- repo: local
hooks:
- id: mypy
name: mypy static type checker
entry: bash -c 'echo mypy temporarily disabled'
#entry: bash -c 'cd model/atmosphere/dycore; mypy src/' --
language: system
types_or: [python, pyi]
always_run: true
#pass_filenames: false
require_serial: true
stages: [commit]
Loading

0 comments on commit 10e848c

Please sign in to comment.