diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3e914e9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/clean-caches.yml b/.github/workflows/clean-caches.yml new file mode 100644 index 0000000..a66c407 --- /dev/null +++ b/.github/workflows/clean-caches.yml @@ -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 }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 69a370c..446bf8d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: @@ -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 @@ -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 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index af3b23e..b4d6265 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -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" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 4e1f574..8b24c13 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } diff --git a/pyproject.toml b/pyproject.toml index 72c8c0e..5be28cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -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 = ''' /( @@ -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"] diff --git a/src/jax_benchmark/__init__.py b/src/jax_benchmark/__init__.py index 5c57369..ee68c51 100644 --- a/src/jax_benchmark/__init__.py +++ b/src/jax_benchmark/__init__.py @@ -10,8 +10,6 @@ import yaml from tqdm.auto import tqdm -from jax_benchmark.io import mute_warnings - def main() -> int: parser = argparse.ArgumentParser() @@ -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."