Skip to content

Commit

Permalink
add lint GH action, switch ruff, require py3.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
janfb committed Jan 23, 2025
1 parent 01c0588 commit a5ef03b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Linting

on:
pull_request:
push:
branches: [main, dev]
workflow_dispatch:

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
name: ruff and hooks.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --show-diff-on-failure

pyright:
name: Check types
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Cache dependency
id: cache-dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ubuntu-latest-pip-3.9
restore-keys: |
ubuntu-latest-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e .[dev]
55 changes: 42 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [
{ name = "Jan-Matthis Lueckmann", email = "[email protected]" },
{ name = "Jan Boelts", email = "[email protected]" }
]
requires-python = ">=3.7"
requires-python = ">=3.9"
license = { text = "MIT" }
classifiers = [
"License :: OSI Approved :: MIT License",
Expand Down Expand Up @@ -47,10 +47,12 @@ dependencies = [

[project.optional-dependencies]
dev = [
"autoflake",
"black",
"flake8",
"isort>5.0.0",
# Lint
"pre-commit == 4.0.1",
"pyyaml",
"pyright",
"ruff==0.9.0",
# Test
"ipdb",
"pytest",
"pytest-plt",
Expand All @@ -69,14 +71,41 @@ exclude = ["tests", "tests.*"]
[tool.setuptools.dynamic]
version = {attr = "sbibm.__version__.__version__"}

[tool.flake8]
exclude = ["docs", "build", "dist", ".ipynb_checkpoints", ".git", "third_party"]
max-line-length = 119
extend-ignore = ["W503", "E203"]
# ruff configs
[tool.ruff]
extend-include = ["*.ipynb"]
line-length = 88

[tool.isort]
profile = "black"
[tool.ruff.lint]
# pycodestyle, Pyflakes, pyupgrade, flake8-bugbear, flake8-simplify, isort
select = ["E", "F", "W", "B", "SIM", "I"]
ignore = [
"E731", # allow naming lambda functions.
"B008", # allow function calls in default args.
]

[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = ["E402", "F401", "F403"] # allow unused imports and undefined names
"test_*.py" = ["F403", "F405"]
"tutorials/*.ipynb" = ["E501"] # allow long lines in notebooks

[tool.ruff.lint.isort]
case-sensitive = true
lines-between-types = 0 # like isort default.
relative-imports-order = "furthest-to-closest" # like isort default.
known-first-party = ["sbibm", "tests"]

[tool.ruff.format]
exclude = ["*.ipynb"]
preview = true
quote-style = "preserve"

# Pytest configuration
[tool.pytest.ini_options]
addopts = "--ignore=src/"
plt_filename_drop = ["^--"]
minversion = "6.0"
addopts = "-ra -q"
filterwarnings = [
"ignore::DeprecationWarning",
"ignore::PendingDeprecationWarning"
]
testpaths = ["tests"]

0 comments on commit a5ef03b

Please sign in to comment.