Skip to content

Commit

Permalink
DX!: switch to Ruff as linter (#3)
Browse files Browse the repository at this point in the history
* MAINT: autoupdate pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Remco de Boer <29308176+redeboer@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] and redeboer authored Jul 10, 2023
1 parent 4394cac commit a9bc446
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 24 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI

on:
push:
branches:
- main
- epic/*
- "[0-9]+.[0-9]+.x"
pull_request:
branches:
- main
- epic/*
- "[0-9]+.[0-9]+.x"
workflow_dispatch:

jobs:
style:
secrets:
token: ${{ secrets.PAT }}
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v1
22 changes: 22 additions & 0 deletions .github/workflows/clean-caches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Clean caches

on:
pull_request:
types:
- closed
workflow_dispatch:
inputs:
ref:
description: Clean caches for this branch name or ref
required: false
type: string

jobs:
cleanup:
name: Remove caches
runs-on: ubuntu-22.04
steps:
- uses: ComPWA/actions/clean-caches@v1
with:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ inputs.ref }}
27 changes: 24 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ci:
autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks"
autoupdate_schedule: quarterly # already done by requirements-cron.yml
skip:
- pyright
- taplo

repos:
- repo: meta
hooks:
Expand All @@ -27,7 +31,7 @@ repos:
- id: black

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.1
rev: 2.7.2
hooks:
- id: editorconfig-checker
name: editorconfig-checker
Expand All @@ -38,13 +42,30 @@ repos:
- id: isort

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
rev: v3.0.0
hooks:
- id: prettier

- repo: https://github.com/ComPWA/mirrors-pyright
rev: v1.1.316
hooks:
- id: pyright

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.9.0
hooks:
- id: pyupgrade
args:
- --py37-plus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
hooks:
- id: ruff
args:
- --fix

- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.0
hooks:
- id: taplo
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
"eamodio.gitlens",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"garaioag.garaio-vscode-unwanted-recommendations",
"github.vscode-pull-request-github",
"ms-python.black-formatter",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"tamasfe.even-better-toml",
"tyriar.sort-lines",
"yzhang.markdown-all-in-one"
],
"unwantedRecommendations": [
"ms-python.flake8",
"ms-python.isort",
"ms-python.mypy-type-checker",
"ms-python.pylint"
]
}
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
}
},
"editor.formatOnSave": true,
"isort.importStrategy": "fromEnvironment",
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "basic",
"python.formatting.provider": "black"
"python.analysis.typeCheckingMode": "strict",
"python.formatting.provider": "black",
"ruff.enable": true,
"ruff.importStrategy": "fromEnvironment"
}
70 changes: 56 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ readme = "README.md"
requires-python = ">=3.7"

[project.optional-dependencies]
dev = [
"jax-mini-benchmark[sty]",
]
format = [
"black",
"isort",
]
dev = ["jax-mini-benchmark[sty]"]
sty = [
"jax-mini-benchmark[format]",
"black",
"pre-commit",
"ruff",
]

[project.scripts]
Expand All @@ -72,7 +67,6 @@ Documentation = "https://github.com/ComPWA/jax-mini-benchmark"
Source = "https://github.com/ComPWA/jax-mini-benchmark"
Tracker = "https://github.com/ComPWA/jax-mini-benchmark/issues"


[tool.black]
exclude = '''
/(
Expand All @@ -97,13 +91,61 @@ target-version = [
"py39",
]


[tool.isort]
profile = "black"
src_paths = [
"src",
[tool.pyright]
exclude = [
"**/*.egg-info",
"**/.git",
"**/.ipynb_checkpoints",
"**/.mypy_cache",
"**/.pytest_cache",
"**/.tox",
"**/__pycache__",
"**/_build",
".ruff_cache/**",
]
reportGeneralTypeIssues = false
reportMissingTypeArgument = false
reportMissingTypeStubs = false
reportUnknownArgumentType = false
reportUnknownMemberType = false
reportUnknownParameterType = false
reportUnknownVariableType = false
typeCheckingMode = "strict"

[tool.ruff]
extend-select = [
"A",
"B",
"BLE",
"C4",
"C90",
"EM",
"ERA",
"FA",
"I",
"ICN",
"INP",
"ISC",
"N",
"NPY",
"PGH",
"PIE",
"PL",
"Q",
"RET",
"RSE",
"RUF",
"SIM",
"TCH",
"TID",
"TRY",
"UP",
"YTT",
]
show-fixes = true
src = ["src"]
target-version = "py37"
task-tags = ["cspell"]

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
5 changes: 2 additions & 3 deletions src/jax_benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import yaml
from tqdm.auto import tqdm

from jax_benchmark.io import mute_warnings


def main() -> int:
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -48,7 +46,8 @@ def main() -> int:
def benchmark_cpu_range(number: int, repeat: int) -> dict[int, dict]:
n_available_cpus = os.cpu_count()
if n_available_cpus is None:
raise OSError("Could not determine number of CPUs")
msg = "Could not determine number of CPUs"
raise OSError(msg)
print(
f"Machine has {n_available_cpus} CPUs."
" JAX will be benchmarked over a range of them."
Expand Down

0 comments on commit a9bc446

Please sign in to comment.