diff --git a/.cspell.json b/.cspell.json index 2e00672a..fd41364f 100644 --- a/.cspell.json +++ b/.cspell.json @@ -22,14 +22,11 @@ "*particle*.*ml", ".constraints/*.txt", ".editorconfig", - ".flake8*", ".gitignore", ".gitpod.*", ".mypy.ini", ".pre-commit-config.yaml", ".prettierignore", - ".pydocstyle*", - ".pylintrc", ".readthedocs.yml", ".vscode/*", ".vscode/.gitignore", diff --git a/.gitpod.yml b/.gitpod.yml index 1c6a7656..1eca252d 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -13,9 +13,11 @@ github: vscode: extensions: + - charliermarsh.ruff - eamodio.gitlens - editorconfig.editorconfig - esbenp.prettier-vscode + - garaioag.garaio-vscode-unwanted-recommendations - github.vscode-github-actions - github.vscode-pull-request-github - ms-python.python diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 25e734f4..e1cc061f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,12 +44,14 @@ repos: - 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/psf/black rev: 23.3.0 hooks: @@ -71,11 +73,6 @@ repos: .*\.py )$ - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - - repo: https://github.com/kynan/nbstripout rev: 0.6.1 hooks: @@ -117,6 +114,13 @@ repos: args: - --py37-plus + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "" + hooks: + - id: ruff + args: + - --fix + - repo: https://github.com/ComPWA/mirrors-taplo rev: v0.8.0 hooks: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index e9ae2c93..1d9df646 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,10 @@ { "recommendations": [ + "charliermarsh.ruff", "eamodio.gitlens", "editorconfig.editorconfig", "esbenp.prettier-vscode", + "garaioag.garaio-vscode-unwanted-recommendations", "github.vscode-github-actions", "github.vscode-pull-request-github", "ms-python.python", @@ -17,5 +19,12 @@ "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", + "travisillig.vscode-json-stable-stringify" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 6ed525f6..53f9c876 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,15 +34,19 @@ "github-actions.workflows.pinned.workflows": [".github/workflows/ci.yml"], "livePreview.defaultPreviewPath": "docs/_build/html", "python.analysis.autoImportCompletions": false, - "python.analysis.diagnosticMode": "workspace", "python.analysis.inlayHints.pytestParameters": true, "python.analysis.typeCheckingMode": "strict", "python.formatting.provider": "black", "python.linting.enabled": true, + "python.linting.flake8Enabled": false, + "python.linting.pydocstyleEnabled": false, + "python.linting.pylintEnabled": false, "python.testing.pytestArgs": ["--color=no"], "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" } diff --git a/README.md b/README.md index ebd935fd..015f303d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Symbolic Dalitz-Plot Decomposition +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![GPLv3+ license](https://img.shields.io/badge/License-GPLv3+-blue.svg)](https://www.gnu.org/licenses/gpl-3.0-standalone.html) [![PyPI package](https://badge.fury.io/py/ampform-dpd.svg)](https://pypi.org/project/ampform-dpd) diff --git a/docs/_unsrt_et_al.py b/docs/_unsrt_et_al.py index fe01a836..dfe91ca2 100644 --- a/docs/_unsrt_et_al.py +++ b/docs/_unsrt_et_al.py @@ -1,17 +1,10 @@ from pybtex.database import Entry from pybtex.richtext import Tag, Text from pybtex.style.formatting.unsrt import Style as UnsrtStyle -from pybtex.style.template import _format_list # pyright: ignore[reportPrivateUsage] -from pybtex.style.template import ( - FieldIsMissing, - Node, - field, - href, - join, - node, - sentence, - words, -) +from pybtex.style.template import \ + _format_list # pyright: ignore[reportPrivateUsage] +from pybtex.style.template import (FieldIsMissing, Node, field, href, join, + node, sentence, words) class MyStyle(UnsrtStyle): # type: ignore[reportUntypedBaseClass] diff --git a/docs/comparison/d2kkk.ipynb b/docs/comparison/d2kkk.ipynb index 68b99e15..6aa5414f 100644 --- a/docs/comparison/d2kkk.ipynb +++ b/docs/comparison/d2kkk.ipynb @@ -48,37 +48,22 @@ "from ampform.kinematics import FourMomentumSymbol, InvariantMass\n", "from ampform.sympy import perform_cached_doit\n", "from IPython.display import SVG, Latex, Markdown, clear_output, display\n", - "from ipywidgets import (\n", - " Accordion,\n", - " Checkbox,\n", - " GridBox,\n", - " HBox,\n", - " Layout,\n", - " SelectMultiple,\n", - " Tab,\n", - " ToggleButtons,\n", - " VBox,\n", - " interactive_output,\n", - ")\n", + "from ipywidgets import (Accordion, Checkbox, GridBox, HBox, Layout,\n", + " SelectMultiple, Tab, ToggleButtons, VBox,\n", + " interactive_output)\n", "from qrules.transition import ReactionInfo\n", "from tensorwaves.data.phasespace import TFPhaseSpaceGenerator\n", "from tensorwaves.data.rng import TFUniformRealNumberGenerator\n", "from tensorwaves.data.transform import SympyDataTransformer\n", - "from tensorwaves.interface import DataSample, ParameterValue, ParametrizedFunction\n", - "\n", - "from ampform_dpd import DalitzPlotDecompositionBuilder, simplify_latex_rendering\n", - "from ampform_dpd.decay import (\n", - " IsobarNode,\n", - " Particle,\n", - " ThreeBodyDecay,\n", - " ThreeBodyDecayChain,\n", - ")\n", - "from ampform_dpd.io import (\n", - " as_markdown_table,\n", - " aslatex,\n", - " get_readable_hash,\n", - " perform_cached_lambdify,\n", - ")\n", + "from tensorwaves.interface import (DataSample, ParameterValue,\n", + " ParametrizedFunction)\n", + "\n", + "from ampform_dpd import (DalitzPlotDecompositionBuilder,\n", + " simplify_latex_rendering)\n", + "from ampform_dpd.decay import (IsobarNode, Particle, ThreeBodyDecay,\n", + " ThreeBodyDecayChain)\n", + "from ampform_dpd.io import (as_markdown_table, aslatex, get_readable_hash,\n", + " perform_cached_lambdify)\n", "from ampform_dpd.spin import filter_parity_violating_ls, generate_ls_couplings\n", "\n", "simplify_latex_rendering()\n", diff --git a/docs/comparison/jpsi2phipipi.ipynb b/docs/comparison/jpsi2phipipi.ipynb index a6ded54f..47b25a71 100644 --- a/docs/comparison/jpsi2phipipi.ipynb +++ b/docs/comparison/jpsi2phipipi.ipynb @@ -48,37 +48,22 @@ "from ampform.kinematics import FourMomentumSymbol, InvariantMass\n", "from ampform.sympy import perform_cached_doit\n", "from IPython.display import SVG, Latex, Markdown, clear_output, display\n", - "from ipywidgets import (\n", - " Accordion,\n", - " Checkbox,\n", - " GridBox,\n", - " HBox,\n", - " Layout,\n", - " SelectMultiple,\n", - " Tab,\n", - " ToggleButtons,\n", - " VBox,\n", - " interactive_output,\n", - ")\n", + "from ipywidgets import (Accordion, Checkbox, GridBox, HBox, Layout,\n", + " SelectMultiple, Tab, ToggleButtons, VBox,\n", + " interactive_output)\n", "from qrules.transition import ReactionInfo\n", "from tensorwaves.data.phasespace import TFPhaseSpaceGenerator\n", "from tensorwaves.data.rng import TFUniformRealNumberGenerator\n", "from tensorwaves.data.transform import SympyDataTransformer\n", - "from tensorwaves.interface import DataSample, ParameterValue, ParametrizedFunction\n", - "\n", - "from ampform_dpd import DalitzPlotDecompositionBuilder, simplify_latex_rendering\n", - "from ampform_dpd.decay import (\n", - " IsobarNode,\n", - " Particle,\n", - " ThreeBodyDecay,\n", - " ThreeBodyDecayChain,\n", - ")\n", - "from ampform_dpd.io import (\n", - " as_markdown_table,\n", - " aslatex,\n", - " get_readable_hash,\n", - " perform_cached_lambdify,\n", - ")\n", + "from tensorwaves.interface import (DataSample, ParameterValue,\n", + " ParametrizedFunction)\n", + "\n", + "from ampform_dpd import (DalitzPlotDecompositionBuilder,\n", + " simplify_latex_rendering)\n", + "from ampform_dpd.decay import (IsobarNode, Particle, ThreeBodyDecay,\n", + " ThreeBodyDecayChain)\n", + "from ampform_dpd.io import (as_markdown_table, aslatex, get_readable_hash,\n", + " perform_cached_lambdify)\n", "from ampform_dpd.spin import filter_parity_violating_ls, generate_ls_couplings\n", "\n", "simplify_latex_rendering()\n", diff --git a/docs/comparison/jpsi2pipipi.ipynb b/docs/comparison/jpsi2pipipi.ipynb index ecf90aa4..828893f3 100644 --- a/docs/comparison/jpsi2pipipi.ipynb +++ b/docs/comparison/jpsi2pipipi.ipynb @@ -48,37 +48,22 @@ "from ampform.kinematics import FourMomentumSymbol, InvariantMass\n", "from ampform.sympy import perform_cached_doit\n", "from IPython.display import SVG, Latex, Markdown, clear_output, display\n", - "from ipywidgets import (\n", - " Accordion,\n", - " Checkbox,\n", - " GridBox,\n", - " HBox,\n", - " Layout,\n", - " SelectMultiple,\n", - " Tab,\n", - " ToggleButtons,\n", - " VBox,\n", - " interactive_output,\n", - ")\n", + "from ipywidgets import (Accordion, Checkbox, GridBox, HBox, Layout,\n", + " SelectMultiple, Tab, ToggleButtons, VBox,\n", + " interactive_output)\n", "from qrules.transition import ReactionInfo\n", "from tensorwaves.data.phasespace import TFPhaseSpaceGenerator\n", "from tensorwaves.data.rng import TFUniformRealNumberGenerator\n", "from tensorwaves.data.transform import SympyDataTransformer\n", - "from tensorwaves.interface import DataSample, ParameterValue, ParametrizedFunction\n", - "\n", - "from ampform_dpd import DalitzPlotDecompositionBuilder, simplify_latex_rendering\n", - "from ampform_dpd.decay import (\n", - " IsobarNode,\n", - " Particle,\n", - " ThreeBodyDecay,\n", - " ThreeBodyDecayChain,\n", - ")\n", - "from ampform_dpd.io import (\n", - " as_markdown_table,\n", - " aslatex,\n", - " get_readable_hash,\n", - " perform_cached_lambdify,\n", - ")\n", + "from tensorwaves.interface import (DataSample, ParameterValue,\n", + " ParametrizedFunction)\n", + "\n", + "from ampform_dpd import (DalitzPlotDecompositionBuilder,\n", + " simplify_latex_rendering)\n", + "from ampform_dpd.decay import (IsobarNode, Particle, ThreeBodyDecay,\n", + " ThreeBodyDecayChain)\n", + "from ampform_dpd.io import (as_markdown_table, aslatex, get_readable_hash,\n", + " perform_cached_lambdify)\n", "from ampform_dpd.spin import filter_parity_violating_ls, generate_ls_couplings\n", "\n", "simplify_latex_rendering()\n", diff --git a/docs/jpsi2ksp.ipynb b/docs/jpsi2ksp.ipynb index 3bf110fb..36c0a3ce 100644 --- a/docs/jpsi2ksp.ipynb +++ b/docs/jpsi2ksp.ipynb @@ -37,29 +37,18 @@ "import sympy as sp\n", "from ampform.dynamics import EnergyDependentWidth, formulate_form_factor\n", "from ampform.kinematics.phasespace import compute_third_mandelstam\n", - "from ampform.sympy import (\n", - " UnevaluatedExpression,\n", - " create_expression,\n", - " implement_doit_method,\n", - " make_commutative,\n", - " perform_cached_doit,\n", - ")\n", + "from ampform.sympy import (UnevaluatedExpression, create_expression,\n", + " implement_doit_method, make_commutative,\n", + " perform_cached_doit)\n", "from IPython.display import Latex, Markdown\n", "from tensorwaves.data.transform import SympyDataTransformer\n", "from tensorwaves.interface import DataSample, ParametrizedFunction\n", "from tqdm.auto import tqdm\n", "\n", - "from ampform_dpd import (\n", - " DalitzPlotDecompositionBuilder,\n", - " _get_particle,\n", - " simplify_latex_rendering,\n", - ")\n", - "from ampform_dpd.decay import (\n", - " IsobarNode,\n", - " Particle,\n", - " ThreeBodyDecay,\n", - " ThreeBodyDecayChain,\n", - ")\n", + "from ampform_dpd import (DalitzPlotDecompositionBuilder, _get_particle,\n", + " simplify_latex_rendering)\n", + "from ampform_dpd.decay import (IsobarNode, Particle, ThreeBodyDecay,\n", + " ThreeBodyDecayChain)\n", "from ampform_dpd.io import as_markdown_table, aslatex, perform_cached_lambdify\n", "from ampform_dpd.spin import filter_parity_violating_ls, generate_ls_couplings\n", "\n", diff --git a/docs/lc2pkpi.ipynb b/docs/lc2pkpi.ipynb index c2a3d7da..07d0a60b 100644 --- a/docs/lc2pkpi.ipynb +++ b/docs/lc2pkpi.ipynb @@ -33,13 +33,10 @@ "import sympy as sp\n", "from IPython.display import Latex, Markdown\n", "\n", - "from ampform_dpd import DalitzPlotDecompositionBuilder, simplify_latex_rendering\n", - "from ampform_dpd.decay import (\n", - " IsobarNode,\n", - " Particle,\n", - " ThreeBodyDecay,\n", - " ThreeBodyDecayChain,\n", - ")\n", + "from ampform_dpd import (DalitzPlotDecompositionBuilder,\n", + " simplify_latex_rendering)\n", + "from ampform_dpd.decay import (IsobarNode, Particle, ThreeBodyDecay,\n", + " ThreeBodyDecayChain)\n", "from ampform_dpd.dynamics import BreitWignerMinL\n", "from ampform_dpd.io import as_markdown_table, aslatex\n", "from ampform_dpd.spin import filter_parity_violating_ls, generate_ls_couplings\n", diff --git a/pyproject.toml b/pyproject.toml index 891e8526..f660b677 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,21 +32,20 @@ target-version = [ "py39", ] -[tool.isort] -known_third_party = "THIRDPARTY,sympy" -profile = "black" -src_paths = [ - "src", -] - [tool.nbqa.addopts] black = [ "--line-length=85", ] -flake8 = [ - "--extend-ignore=E501,E731", -] -isort = [ +ruff = [ + "--extend-ignore=B018", + "--extend-ignore=C90", + "--extend-ignore=D", + "--extend-ignore=N806", + "--extend-ignore=N816", + "--extend-ignore=PLR09", + "--extend-ignore=PLR2004", + "--extend-ignore=PLW0602", + "--extend-ignore=PLW0603", "--line-length=85", ] @@ -78,3 +77,108 @@ testpaths = [ "src", "tests", ] + +[tool.pyright] +exclude = [ + "**/.git", + "**/.ipynb_checkpoints", + "**/.mypy_cache", + "**/.pytest_cache", + "**/.tox", + "**/__pycache__", + "**/_build", +] +reportGeneralTypeIssues = false +reportImportCycles = false +reportIncompatibleMethodOverride = false +reportMissingParameterType = false +reportMissingTypeArgument = false +reportMissingTypeStubs = false +reportPrivateImportUsage = false +reportUnknownArgumentType = false +reportUnknownLambdaType = false +reportUnknownMemberType = false +reportUnknownParameterType = false +reportUnknownVariableType = false +reportUnnecessaryContains = false +reportUnnecessaryIsInstance = false +reportUnusedClass = true +reportUnusedFunction = true +reportUnusedImport = true +reportUnusedVariable = true +typeCheckingMode = "strict" + +[tool.ruff] +extend-select = [ + "A", + "B", + "BLE", + "C4", + "C90", + "D", + "EM", + "ERA", + "FA", + "I", + "ICN", + "INP", + "ISC", + "N", + "NPY", + "PGH", + "PIE", + "PL", + "Q", + "RET", + "RSE", + "RUF", + "S", + "SIM", + "T20", + "TCH", + "TID", + "TRY", + "UP", + "YTT", +] +ignore = [ + "D101", + "D102", + "D103", + "D105", + "D107", + "D203", + "D213", + "D407", + "D416", + "E501", + "SIM108", +] +show-fixes = true +target-version = "py37" +task-tags = ["cspell"] +src = [ + "src", + "tests", +] + +[tool.ruff.per-file-ignores] +"docs/*" = [ + "E402", + "INP001", + "S101", + "S113", + "T201", +] +"setup.py" = ["D100"] +"tests/*" = [ + "D", + "INP001", + "PGH001", + "PLR0913", + "PLR2004", + "S101", +] + +[tool.ruff.pydocstyle] +convention = "google" diff --git a/pyrightconfig.json b/pyrightconfig.json deleted file mode 100644 index bb58f27a..00000000 --- a/pyrightconfig.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "exclude": [ - "**/__pycache__", - "**/_build", - "**/.git", - "**/.ipynb_checkpoints", - "**/.mypy_cache", - "**/.pytest_cache", - "**/.tox" - ], - "reportGeneralTypeIssues": false, - "reportImportCycles": false, - "reportIncompatibleMethodOverride": false, - "reportMissingParameterType": false, - "reportMissingTypeArgument": false, - "reportMissingTypeStubs": false, - "reportPrivateImportUsage": false, - "reportUnknownArgumentType": false, - "reportUnknownLambdaType": false, - "reportUnknownMemberType": false, - "reportUnknownParameterType": false, - "reportUnknownVariableType": false, - "reportUnnecessaryContains": false, - "reportUnnecessaryIsInstance": false, - "reportUnusedClass": true, - "reportUnusedFunction": true, - "reportUnusedImport": true, - "reportUnusedVariable": true, - "typeCheckingMode": "strict" -} diff --git a/src/ampform_dpd/__init__.py b/src/ampform_dpd/__init__.py index 33b87f33..46d78ae2 100644 --- a/src/ampform_dpd/__init__.py +++ b/src/ampform_dpd/__init__.py @@ -14,14 +14,9 @@ from sympy.physics.quantum.spin import Rotation as Wigner from sympy.physics.quantum.spin import WignerD -from ampform_dpd.decay import ( - IsobarNode, - LSCoupling, - Particle, - ThreeBodyDecay, - ThreeBodyDecayChain, - get_decay_product_ids, -) +from ampform_dpd.decay import (IsobarNode, LSCoupling, Particle, + ThreeBodyDecay, ThreeBodyDecayChain, + get_decay_product_ids) from ampform_dpd.spin import create_spin_range from .angles import formulate_scattering_angle, formulate_zeta_angle diff --git a/src/ampform_dpd/dynamics.py b/src/ampform_dpd/dynamics.py index a085f6c2..baa9a49f 100644 --- a/src/ampform_dpd/dynamics.py +++ b/src/ampform_dpd/dynamics.py @@ -5,12 +5,8 @@ import sympy as sp from ampform.kinematics.phasespace import Kallen -from ampform.sympy import ( - UnevaluatedExpression, - create_expression, - implement_doit_method, - make_commutative, -) +from ampform.sympy import (UnevaluatedExpression, create_expression, + implement_doit_method, make_commutative) @make_commutative diff --git a/src/ampform_dpd/io.py b/src/ampform_dpd/io.py index 3db25857..88920d6a 100644 --- a/src/ampform_dpd/io.py +++ b/src/ampform_dpd/io.py @@ -31,11 +31,15 @@ import cloudpickle import sympy as sp from ampform.io import aslatex -from tensorwaves.function import ParametrizedBackendFunction, PositionalArgumentFunction -from tensorwaves.function.sympy import create_function, create_parametrized_function -from tensorwaves.interface import Function, ParameterValue, ParametrizedFunction - -from ampform_dpd.decay import IsobarNode, Particle, ThreeBodyDecay, ThreeBodyDecayChain +from tensorwaves.function import (ParametrizedBackendFunction, + PositionalArgumentFunction) +from tensorwaves.function.sympy import (create_function, + create_parametrized_function) +from tensorwaves.interface import (Function, ParameterValue, + ParametrizedFunction) + +from ampform_dpd.decay import (IsobarNode, Particle, ThreeBodyDecay, + ThreeBodyDecayChain) _LOGGER = logging.getLogger(__name__) diff --git a/tests/test_angles.py b/tests/test_angles.py index ca8eb2cc..bbc6cc56 100644 --- a/tests/test_angles.py +++ b/tests/test_angles.py @@ -3,11 +3,9 @@ import sympy as sp from ampform.kinematics.phasespace import Kallen, compute_third_mandelstam -from ampform_dpd.angles import ( - formulate_scattering_angle, - formulate_theta_hat_angle, - formulate_zeta_angle, -) +from ampform_dpd.angles import (formulate_scattering_angle, + formulate_theta_hat_angle, + formulate_zeta_angle) m0, m1, m2, m3 = sp.symbols("m:4", nonnegative=True) σ1, σ2, σ3 = sp.symbols("sigma1:4", nonnegative=True)