Skip to content

Commit

Permalink
DX!: switch to Ruff as linter (#308)
Browse files Browse the repository at this point in the history
* MAINT: update pip constraints and pre-commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: GitHub <noreply@github.com>
  • Loading branch information
3 people authored Jul 11, 2023
1 parent 3f4d92b commit 7167f3e
Show file tree
Hide file tree
Showing 39 changed files with 374 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .constraints/py3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ ipython==8.14.0
ipython-genutils==0.2.0
ipywidgets==8.0.7
isoduration==20.11.0
isort==5.12.0
jax==0.4.13
jaxlib==0.4.13
jedi==0.18.2
Expand Down Expand Up @@ -150,6 +149,7 @@ requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.8.10
ruff==0.0.277
scipy==1.11.1
send2trash==1.8.2
six==1.16.0
Expand Down
2 changes: 1 addition & 1 deletion .constraints/py3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ ipython==8.14.0
ipython-genutils==0.2.0
ipywidgets==8.0.7
isoduration==20.11.0
isort==5.12.0
jax==0.4.13
jaxlib==0.4.13
jedi==0.18.2
Expand Down Expand Up @@ -149,6 +148,7 @@ requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.8.10
ruff==0.0.277
scipy==1.11.1
send2trash==1.8.2
six==1.16.0
Expand Down
2 changes: 1 addition & 1 deletion .constraints/py3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ ipython==7.34.0
ipython-genutils==0.2.0
ipywidgets==8.0.7
isoduration==20.11.0
isort==5.11.5
jax==0.3.25
jaxlib==0.3.25
jedi==0.18.2
Expand Down Expand Up @@ -149,6 +148,7 @@ qrules==0.9.8
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
ruff==0.0.277
scipy==1.7.3
send2trash==1.8.2
singledispatchmethod==1.0
Expand Down
2 changes: 1 addition & 1 deletion .constraints/py3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ ipython==8.12.2
ipython-genutils==0.2.0
ipywidgets==8.0.7
isoduration==20.11.0
isort==5.12.0
jax==0.4.13
jaxlib==0.4.13
jedi==0.18.2
Expand Down Expand Up @@ -152,6 +151,7 @@ requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.8.10
ruff==0.0.277
scipy==1.10.1
send2trash==1.8.2
six==1.16.0
Expand Down
2 changes: 1 addition & 1 deletion .constraints/py3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ ipython==8.14.0
ipython-genutils==0.2.0
ipywidgets==8.0.7
isoduration==20.11.0
isort==5.12.0
jax==0.4.13
jaxlib==0.4.13
jedi==0.18.2
Expand Down Expand Up @@ -151,6 +150,7 @@ requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.8.10
ruff==0.0.277
scipy==1.11.1
send2trash==1.8.2
six==1.16.0
Expand Down
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,16 @@ repos:
hooks:
- id: cspell

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
- id: nbqa-black
additional_dependencies:
- black>=22.1.0
- id: nbqa-flake8
- id: nbqa-isort
- id: nbqa-pyupgrade
args:
- --py37-plus
- id: nbqa-ruff
args:
- --fix

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
Expand Down Expand Up @@ -97,6 +91,13 @@ repos:
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:
Expand Down
13 changes: 11 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"recommendations": [
"ExecutableBookProject.myst-highlight",
"charliermarsh.ruff",
"eamodio.gitlens",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"executablebookproject.myst-highlight",
"garaioag.garaio-vscode-unwanted-recommendations",
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"julialang.language-julia",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.vscode-jupyter-cell-tags",
"ms-vscode.cpptools",
"ms-vscode.live-server",
"ms-vsliveshare.vsliveshare",
"oijaz.unicode-latex",
Expand All @@ -20,5 +21,13 @@
"tamasfe.even-better-toml",
"tyriar.sort-lines",
"yzhang.markdown-all-in-one"
],
"unwantedRecommendations": [
"bungcip.better-toml",
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
"ms-vscode.cpptools",
"travisillig.vscode-json-stable-stringify"
]
}
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"cSpell.enabled": true,
"editor.formatOnSave": true,
"editor.rulers": [88],
"editor.unicodeHighlight.allowedCharacters": {
"σ": true
},
"files.associations": {
".cspell/*.txt": "plaintext"
},
Expand All @@ -38,7 +41,7 @@
"julia.NumThreads": "auto",
"livePreview.defaultPreviewPath": "docs/_build/html",
"python.analysis.autoImportCompletions": false,
"python.analysis.diagnosticMode": "workspace",
"python.analysis.diagnosticMode": "openFilesOnly",
"python.analysis.inlayHints.pytestParameters": true,
"python.analysis.typeCheckingMode": "strict",
"python.formatting.provider": "black",
Expand All @@ -47,6 +50,8 @@
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"rewrap.wrappingColumn": 88,
"ruff.enable": true,
"ruff.organizeImports": true,
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "./.github/workflows/requirements.yml"
}
Expand Down
7 changes: 3 additions & 4 deletions docs/amplitude-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
" perform_cached_doit,\n",
")\n",
"from polarimetry.lhcb import load_model_builder, load_model_parameters\n",
"from polarimetry.lhcb.particle import K, Λc, Σ, load_particles, p, π\n",
"from polarimetry.lhcb.particle import Σ, K, Λc, load_particles, p, π\n",
"\n",
"simplify_latex_rendering()\n",
"\n",
Expand Down Expand Up @@ -272,9 +272,8 @@
"source": [
"def simplify_notation(expr):\n",
" def substitute_node(node):\n",
" if isinstance(node, sp.Indexed):\n",
" if node.indices[2:] == (0, 0):\n",
" return sp.Indexed(node.base, *node.indices[:2])\n",
" if isinstance(node, sp.Indexed) and node.indices[2:] == (0, 0):\n",
" return sp.Indexed(node.base, *node.indices[:2])\n",
" return node\n",
"\n",
" for node in sp.preorder_traversal(expr):\n",
Expand Down
1 change: 0 additions & 1 deletion docs/appendix/benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"from polarimetry.lhcb import (\n",
" load_model_builder,\n",
" load_model_parameters,\n",
" load_three_body_decay,\n",
")\n",
"from polarimetry.lhcb.particle import load_particles\n",
"\n",
Expand Down
8 changes: 3 additions & 5 deletions docs/appendix/ls-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@
"\n",
"def simplify_notation(expr: sp.Expr) -> sp.Expr:\n",
" def substitute_node(node):\n",
" if isinstance(node, sp.Indexed):\n",
" if node.indices[2:] == (0, 0):\n",
" return sp.Indexed(node.base, *node.indices[:2])\n",
" if isinstance(node, sp.Indexed) and node.indices[2:] == (0, 0):\n",
" return sp.Indexed(node.base, *node.indices[:2])\n",
" return node\n",
"\n",
" for node in sp.preorder_traversal(expr):\n",
Expand Down Expand Up @@ -372,8 +371,7 @@
"source": [
"def to_regex(text: str) -> str:\n",
" text = text.replace(\"(\", r\"\\(\")\n",
" text = text.replace(\")\", r\"\\)\")\n",
" return text\n",
" return text.replace(\")\", r\"\\)\")\n",
"\n",
"\n",
"def compute_decay_rates() -> dict[Particle, tuple[float, float]]:\n",
Expand Down
21 changes: 10 additions & 11 deletions docs/appendix/widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@
" expr = perform_cached_doit(expr)\n",
" expr = perform_cached_doit(expr.xreplace(MODELS[reference_subsystem].amplitudes))\n",
" expr = expr.xreplace(POLAR_SUBSTITUTIONS)\n",
" expr = expr.xreplace(FIXED_PARAMETERS)\n",
" return expr"
" return expr.xreplace(FIXED_PARAMETERS)"
]
},
{
Expand All @@ -201,7 +200,7 @@
"def create_function(\n",
" expr: sp.Expr, reference_subsystem: int = 1\n",
") -> ParametrizedFunction:\n",
" global progress_bar\n",
" global progress_bar # noqa: PLW0602\n",
" expr = unfold_and_substitute(expr, reference_subsystem)\n",
" func = perform_cached_lambdify(expr, parameters=FREE_PARAMETERS)\n",
" progress_bar.update()\n",
Expand Down Expand Up @@ -291,7 +290,7 @@
"\n",
" @temporarily_deactivate_continuous_update\n",
" def set_reference_subsystem(value: Bunch) -> None:\n",
" global REFERENCE_SUBSYSTEM\n",
" global REFERENCE_SUBSYSTEM # noqa: PLW0603\n",
" subsystems = {1: \"K\", 2: \"L\", 3: \"D\"}\n",
" REFERENCE_SUBSYSTEM = value.new\n",
" for name, slider in SLIDERS.items():\n",
Expand Down Expand Up @@ -321,7 +320,7 @@
" continue\n",
" if filter_pattern not in name:\n",
" continue\n",
" set_slider(SLIDERS[name], 0)\n",
" set_slider(slider, 0)\n",
"\n",
" def set_all_to_zero(action: Button | None = None) -> None:\n",
" set_coupling_to_zero(\"D\")\n",
Expand Down Expand Up @@ -364,7 +363,9 @@
" ]\n",
" )\n",
"\n",
" get_subscript = lambda p: Rf\"{p.name} \\to p K^-\" if \"1405\" in p.name else p.name\n",
" def get_subscript(p):\n",
" return f\"{p.name} \\\\to p K^-\" if \"1405\" in p.name else p.name\n",
"\n",
" grouped_sliders = []\n",
" for p in RESONANCES:\n",
" row = (\n",
Expand All @@ -373,7 +374,7 @@
" SLIDERS[Rf\"\\Gamma_{{{get_subscript(p)}}}\"],\n",
" )\n",
" rows = [row]\n",
" for slider_name, slider in SLIDERS.items():\n",
" for slider_name in SLIDERS:\n",
" if p.name not in slider_name:\n",
" continue\n",
" if not slider_name.startswith(\"C\"):\n",
Expand Down Expand Up @@ -465,15 +466,13 @@
"\n",
"def to_unicode(text: str) -> str:\n",
" text = text.replace(\"L\", \"Λ\")\n",
" text = text.replace(\"D\", \"Δ\")\n",
" return text\n",
" return text.replace(\"D\", \"Δ\")\n",
"\n",
"\n",
"def from_unicode(text: str) -> str:\n",
" text = text.replace(\"Λ\", \"L\")\n",
" text = text.replace(\"Δ\", \"D\")\n",
" text = text.replace(\"*\", \"\")\n",
" return text\n",
" return text.replace(\"*\", \"\")\n",
"\n",
"\n",
"def temporarily_deactivate_continuous_update(func):\n",
Expand Down
Loading

0 comments on commit 7167f3e

Please sign in to comment.