Skip to content

Commit

Permalink
Maintenance rework (#35)
Browse files Browse the repository at this point in the history
Major change to the pre-commit fixes & checks to align with the current state of https://learn.scientific-python.org/development/guides/style/

The main thing: Switching to ruff, motivated by problems updating the pre-commit tools (black made changes that flake8 then complained about). Using ruff replaces using black and flake8 directly. It has a long list of rules that can be configured. A lot of style changes were made automatically, and I've temporarily(?) disabled rules that caused a problem needing manual changes.

Some minor fixes to CI, including switching from the deprecated pre-commit action to the pre-commit.ci application
  • Loading branch information
smithara authored Feb 8, 2024
1 parent c941eac commit 510e25a
Show file tree
Hide file tree
Showing 33 changed files with 337 additions and 277 deletions.
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

19 changes: 6 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@ on:
workflow_dispatch:
pull_request:
branches: [ main, staging ]
schedule:
# Weekly on Sunday
- cron: "0 1 * * 0"

jobs:
pre-commit:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
with:
extra_args: --hook-stage manual --all-files

checks:
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]
runs-on: [ubuntu-latest, macos-latest, windows-latest]

# include:
Expand All @@ -36,9 +29,9 @@ jobs:
run: brew reinstall gfortran
shell: bash

- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ cython_debug/
src/*/_version.py

# VSCode
.vscode/*
.vscode

# Other dev tool junk
.ruff_cache
node_modules
160 changes: 77 additions & 83 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,97 +1,91 @@
exclude: ^(.*/data/.*)

repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black-jupyter
# Strip outputs from notebooks
- repo: https://github.com/kynan/nbstripout
rev: "0.7.1"
hooks:
- id: nbstripout
args:
["--extra-keys", "metadata.kernelspec metadata.language_info.version"]

- repo: https://github.com/kynan/nbstripout
rev: "0.6.1"
hooks:
- id: nbstripout
args: ["--extra-keys", "metadata.kernelspec metadata.language_info.version"]
# The rest of the checks are from:
# https://github.com/scientific-python/cookie/blob/main/%7B%7Bcookiecutter.project_name%7D%7D/.pre-commit-config.yaml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
# - id: python-check-blanket-type-ignore
- id: python-no-eval
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
# args: ["-a", "from __future__ import annotations"] # Python 3.7+
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: "v4.0.0-alpha.8"
# hooks:
# - id: prettier
# types_or: [yaml, markdown, html, css, scss, javascript, json]
# args: [--prose-wrap=always]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.2.1"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

# - repo: https://github.com/hadialqattan/pycln
# rev: v1.1.0
# hooks:
# - id: pycln
# args: [--config=pyproject.toml]
# TODO: Enable type checking
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "v1.8.0"
# hooks:
# - id: mypy
# files: src|tests
# args: []
# additional_dependencies:
# - pytest

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
exclude: docs/conf.py
additional_dependencies: &flake8_dependencies
- flake8-bugbear
- flake8-print
- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
- id: codespell

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
exclude: docs/conf.py
additional_dependencies: *flake8_dependencies
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.9.0.6"
hooks:
- id: shellcheck

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.930
# hooks:
# - id: mypy
# files: src
# args: [--show-error-codes]
- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.16"
hooks:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
- id: shellcheck

- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.28.0"
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs
14 changes: 7 additions & 7 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ sphinx:
formats: []

build:
os: ubuntu-20.04
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.11"

python:
install:
- method: pip
path: .
extra_requirements:
- docs
- dsecs_cp38_manylinux
- method: pip
path: .
extra_requirements:
- docs
- dsecs_cp311_manylinux
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
[![GitHub Discussion][github-discussions-badge]][github-discussions-link]

[![Actions Status][actions-badge]][actions-link]
[![Code style: black][black-badge]][black-link]
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json)](https://github.com/astral-sh/ruff)

---

Expand All @@ -30,7 +30,7 @@
[rtd-badge]: https://img.shields.io/badge/docs-online-success
[rtd-link]: https://swarmpal.readthedocs.io/

![SwarmPAL diagram](https://swarmpal-benchmarks.netlify.app/swarmpal-diagram.png)
![SwarmPAL diagram](https://swarmdisc.org/wp-content/uploads/2024/02/SwarmPAL-diagrams-overview.png)

For more information see:
- <https://swarmdisc.org/lab/>
Loading

0 comments on commit 510e25a

Please sign in to comment.