From 35d37b03296891d299ed8f2c2d61fd5620686ce4 Mon Sep 17 00:00:00 2001 From: shenvitor Date: Thu, 25 Apr 2024 15:24:12 +0200 Subject: [PATCH 1/3] import to top --- .cspell.json | 4 ++++ .github/workflows/cd.yml | 16 ++++++++++++++-- .pre-commit-config.yaml | 4 ++-- .readthedocs.yml | 4 +++- .vscode/settings.json | 3 ++- pyproject.toml | 1 - 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.cspell.json b/.cspell.json index 83c04866..311821c9 100644 --- a/.cspell.json +++ b/.cspell.json @@ -26,6 +26,9 @@ "**/.cspell.json", "**/Manifest.toml", "**/Project.toml", + "*.ico", + "*.rst_t", + "*.svg", ".constraints/*.txt", ".editorconfig", ".gitignore", @@ -92,6 +95,7 @@ "pathlib", "permutate", "Plotly", + "pypa", "pyproject", "pytest", "PYTHONHASHSEED", diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 925b84d6..54ae3bc8 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -10,10 +10,22 @@ jobs: milestone: if: startsWith(github.ref, 'refs/tags') uses: ComPWA/actions/.github/workflows/close-milestone.yml@v1 + package-name: + uses: ComPWA/actions/.github/workflows/get-pypi-name.yml@v1 pypi: + environment: + name: PyPI + url: https://pypi.org/p/${{ needs.package-name.outputs.name }} if: startsWith(github.ref, 'refs/tags') - secrets: inherit - uses: ComPWA/actions/.github/workflows/publish-to-pypi.yml@v1 + name: Publish to PyPI + needs: + - package-name + permissions: + id-token: write + runs-on: ubuntu-22.04 + steps: + - uses: ComPWA/actions/build-pypi-distribution@v1 + - uses: pypa/gh-action-pypi-publish@release/v1 push: if: startsWith(github.ref, 'refs/tags') && !github.event.release.prerelease secrets: inherit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f262c1d1..a7738248 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,7 +40,7 @@ repos: metadata.vscode - repo: https://github.com/ComPWA/policy - rev: 0.3.0 + rev: 0.3.6 hooks: - id: check-dev-files args: @@ -104,7 +104,7 @@ repos: hooks: - id: toml-sort args: [--in-place] - exclude: (?x)^(.*(Manifest|Project)\.toml)$ + exclude: (?x)^(.*/Manifest\.toml|.*/Project\.toml)$ - repo: https://github.com/python-jsonschema/check-jsonschema rev: 0.28.0 diff --git a/.readthedocs.yml b/.readthedocs.yml index 65d8d11a..b7807f25 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -16,7 +16,9 @@ build: python: "3.10" jobs: post_install: - - pip install -c .constraints/py3.10.txt -e .[doc] + - curl -LsSf https://astral.sh/uv/install.sh | sh + - |- + /home/docs/.cargo/bin/uv pip install --system -c .constraints/py3.10.txt -e .[doc] - | wget https://julialang-s3.julialang.org/bin/linux/x64/1.9/julia-1.9.2-linux-x86_64.tar.gz - tar xzf julia-1.9.2-linux-x86_64.tar.gz diff --git a/.vscode/settings.json b/.vscode/settings.json index 5932bd63..fc802d40 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,8 @@ "rewrap.wrappingColumn": 72 }, "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.wordWrap": "on" }, "[jsonc]": { "editor.defaultFormatter": "esbenp.prettier-vscode" diff --git a/pyproject.toml b/pyproject.toml index 9d3c6f74..fd4d3157 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -252,7 +252,6 @@ split-on-trailing-comma = false "C408", "C90", "D", - "E402", "E703", "F404", "N802", From 6340b6de6b02876418e17b0eefb347b83ddb26f1 Mon Sep 17 00:00:00 2001 From: shenvitor Date: Thu, 25 Apr 2024 16:09:17 +0200 Subject: [PATCH 2/3] DX: remove line in doc/* --- .gitignore | 2 +- .pre-commit-config.yaml | 2 +- pyproject.toml | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index df349805..28ada63d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ version.py # Temporary files *.pyc *condaenv.* +.DS_Store .coverage .coverage.* .ipynb_checkpoints/ @@ -55,4 +56,3 @@ pyvenv*/ !codecov.yml !environment.yml !pyrightconfig.json -.jupyter_ystore.db diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06d285cc..80f7f9e0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,7 +40,7 @@ repos: metadata.vscode - repo: https://github.com/ComPWA/policy - rev: 0.3.6 + rev: 0.3.7 hooks: - id: check-dev-files args: diff --git a/pyproject.toml b/pyproject.toml index 86d2077b..0095ac50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -269,7 +269,7 @@ split-on-trailing-comma = false "PLW0602", "PLW0603", "PLW2901", - "RUF027", # for _latex_repr_ + "RUF027", "S101", "S307", "T20", @@ -277,7 +277,6 @@ split-on-trailing-comma = false ] "docs/*" = [ "D", - "E402", "INP001", "S101", "S113", From 01d37cf37f7ac5ca2a90e9b42a7f1bb7f1240626 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:56:44 +0200 Subject: [PATCH 3/3] MAINT: move imports to top cell --- .pre-commit-config.yaml | 24 +++++++++++++++++++++++- docs/report/004.ipynb | 9 +++++---- docs/report/014.ipynb | 9 +++------ docs/report/015.ipynb | 35 +++++++++++++++-------------------- docs/report/017.ipynb | 18 ++++++++++++++++-- docs/report/021.ipynb | 12 ++---------- docs/report/026.ipynb | 4 +--- docs/report/033.ipynb | 29 ++++++----------------------- pyproject.toml | 3 +++ 9 files changed, 74 insertions(+), 69 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 014e9784..24f3d6b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,14 @@ repos: - id: check-useless-excludes - repo: https://github.com/ComPWA/policy - rev: 0.4.0 + rev: 0.4.1 hooks: - id: check-dev-files args: - --doc-apt-packages=graphviz - --dev-python-version=3.12 - --github-pages + - --imports-on-top - --no-prettierrc - --pin-requirements=bimonthly - --repo-name=compwa.github.io @@ -146,6 +147,27 @@ repos: docs/_static/favicon.ico )$ + - repo: https://github.com/nbQA-dev/nbQA + rev: 1.9.0 + hooks: + - id: nbqa-isort + args: [--float-to-top] + exclude: >- + (?x)^( + docs/adr/.*\.ipynb| + docs/report/001\.ipynb| + docs/report/002\.ipynb| + docs/report/003\.ipynb| + docs/report/008\.ipynb| + docs/report/013\.ipynb| + docs/report/018\.ipynb| + docs/report/020\.ipynb| + docs/report/026\.ipynb| + docs/report/027\.ipynb| + docs/report/028\.ipynb| + docs/symbolics\.ipynb + )$ + - repo: local hooks: - id: pin-nb-requirements diff --git a/docs/report/004.ipynb b/docs/report/004.ipynb index daba0609..335077c8 100644 --- a/docs/report/004.ipynb +++ b/docs/report/004.ipynb @@ -77,7 +77,11 @@ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import sympy as sp\n", - "from ampform.dynamics import PhaseSpaceFactor, relativistic_breit_wigner_with_ff\n", + "from ampform.dynamics import (\n", + " BreakupMomentumSquared,\n", + " PhaseSpaceFactor,\n", + " relativistic_breit_wigner_with_ff,\n", + ")\n", "from IPython.display import Math, display\n", "from ipywidgets import widgets\n", "from matplotlib import cm\n", @@ -374,9 +378,6 @@ }, "outputs": [], "source": [ - "from ampform.dynamics import BreakupMomentumSquared\n", - "\n", - "\n", "def breakup_momentum(s: sp.Symbol, m_a: sp.Symbol, m_b: sp.Symbol) -> sp.Expr:\n", " return sp.sqrt(BreakupMomentumSquared(s, m_a, m_b).doit())\n", "\n", diff --git a/docs/report/014.ipynb b/docs/report/014.ipynb index 78aaaf24..43535150 100644 --- a/docs/report/014.ipynb +++ b/docs/report/014.ipynb @@ -65,6 +65,7 @@ "import inspect\n", "import itertools\n", "import logging\n", + "from collections import defaultdict\n", "from functools import lru_cache\n", "from typing import TYPE_CHECKING, Iterable, Sequence\n", "\n", @@ -84,12 +85,14 @@ " _generate_kinematic_variables,\n", ")\n", "from ampform.helicity.decay import TwoBodyDecay\n", + "from ampform.helicity.naming import HelicityAmplitudeNameGenerator\n", "from ampform.sympy import (\n", " UnevaluatedExpression,\n", " create_expression,\n", " implement_doit_method,\n", ")\n", "from IPython.display import Math, display\n", + "from qrules import ReactionInfo\n", "from sympy.core.symbol import Str\n", "from sympy.physics.quantum.spin import Rotation as Wigner\n", "from sympy.printing.precedence import PRECEDENCE\n", @@ -641,10 +644,6 @@ }, "outputs": [], "source": [ - "from collections import defaultdict\n", - "\n", - "from qrules import ReactionInfo\n", - "\n", "if TYPE_CHECKING:\n", " if sys.version_info >= (3, 8):\n", " from typing import Literal\n", @@ -1460,8 +1459,6 @@ }, "outputs": [], "source": [ - "from ampform.helicity.naming import HelicityAmplitudeNameGenerator\n", - "\n", "A = sp.IndexedBase(R\"\\mathcal{A}\")\n", "\n", "\n", diff --git a/docs/report/015.ipynb b/docs/report/015.ipynb index 9d5550cd..98a4bb7f 100644 --- a/docs/report/015.ipynb +++ b/docs/report/015.ipynb @@ -61,15 +61,29 @@ }, "outputs": [], "source": [ + "import inspect\n", "import logging\n", "import warnings\n", "\n", "import ampform\n", "import graphviz\n", + "import numpy as np\n", "import qrules\n", "import sympy as sp\n", - "from ampform.helicity import formulate_wigner_d\n", + "from ampform.helicity import (\n", + " formulate_helicity_rotation_chain,\n", + " formulate_rotation_chain,\n", + " formulate_spin_alignment,\n", + " formulate_wigner_d,\n", + ")\n", + "from ampform.kinematics import (\n", + " compute_boost_chain,\n", + " compute_wigner_angles,\n", + " compute_wigner_rotation_matrix,\n", + " create_four_momentum_symbols,\n", + ")\n", "from IPython.display import Math, display\n", + "from qrules.topology import create_isobar_topologies\n", "\n", "LOGGER = logging.getLogger()\n", "LOGGER.setLevel(logging.ERROR)\n", @@ -518,13 +532,6 @@ }, "outputs": [], "source": [ - "from ampform.helicity import (\n", - " formulate_helicity_rotation_chain,\n", - " formulate_rotation_chain,\n", - " formulate_spin_alignment,\n", - ")\n", - "\n", - "\n", "def show_all_spin_matrices(transition, functor, cleanup: bool) -> None:\n", " for i in transition.final_states:\n", " state = transition.states[i]\n", @@ -1136,8 +1143,6 @@ } ], "source": [ - "from ampform.kinematics import compute_boost_chain, create_four_momentum_symbols\n", - "\n", "momenta = create_four_momentum_symbols(topology)\n", "for state_id in topology.outgoing_edge_ids:\n", " boosts = compute_boost_chain(topology, momenta, state_id)\n", @@ -1198,8 +1203,6 @@ } ], "source": [ - "from ampform.kinematics import compute_wigner_rotation_matrix\n", - "\n", "for state_id in topology.outgoing_edge_ids:\n", " expr = compute_wigner_rotation_matrix(topology, momenta, state_id)\n", " display(expr)" @@ -1218,8 +1221,6 @@ "metadata": {}, "outputs": [], "source": [ - "from ampform.kinematics import compute_wigner_angles\n", - "\n", "angles = {}\n", "for state_id in topology.outgoing_edge_ids:\n", " angle_definitions = compute_wigner_angles(topology, momenta, state_id)\n", @@ -1326,8 +1327,6 @@ } ], "source": [ - "import inspect\n", - "\n", "beta = sp.Symbol(\"beta_1^12\", real=True)\n", "beta_expr = angles[beta]\n", "\n", @@ -1368,8 +1367,6 @@ "metadata": {}, "outputs": [], "source": [ - "import numpy as np\n", - "\n", "phsp = {\n", " \"p0\": np.array([\n", " [0.63140486, 0.13166435, -0.35734744, 0.07760603],\n", @@ -1591,8 +1588,6 @@ } ], "source": [ - "from qrules.topology import create_isobar_topologies\n", - "\n", "topology_4body = create_isobar_topologies(4)[1]\n", "momenta_4body = create_four_momentum_symbols(topology_4body)\n", "compute_wigner_rotation_matrix(topology_4body, momenta_4body, state_id=3)" diff --git a/docs/report/017.ipynb b/docs/report/017.ipynb index bf3a838b..12777c0e 100644 --- a/docs/report/017.ipynb +++ b/docs/report/017.ipynb @@ -61,8 +61,6 @@ }, "outputs": [], "source": [ - "%config InlineBackend.figure_formats = ['svg']\n", - "\n", "from __future__ import annotations\n", "\n", "import os\n", @@ -91,6 +89,22 @@ "warnings.filterwarnings(\"ignore\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "jupyter": { + "source_hidden": true + }, + "tags": [ + "remove-cell" + ] + }, + "outputs": [], + "source": [ + "%config InlineBackend.figure_formats = ['svg']" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/docs/report/021.ipynb b/docs/report/021.ipynb index 0db2b6e1..e1c94407 100644 --- a/docs/report/021.ipynb +++ b/docs/report/021.ipynb @@ -77,9 +77,9 @@ "source": [ "from __future__ import annotations\n", "\n", - "import os\n", "import itertools\n", "import logging\n", + "import os\n", "from typing import TYPE_CHECKING\n", "\n", "import jax.numpy as jnp\n", @@ -97,15 +97,7 @@ ")\n", "from attrs import frozen\n", "from IPython.display import HTML, Image, Math, display\n", - "from ipywidgets import (\n", - " Button,\n", - " Combobox,\n", - " HBox,\n", - " HTMLMath,\n", - " Tab,\n", - " VBox,\n", - " interactive_output,\n", - ")\n", + "from ipywidgets import Button, Combobox, HBox, HTMLMath, Tab, VBox, interactive_output\n", "from matplotlib.colors import LogNorm\n", "from symplot import create_slider\n", "from sympy.core.symbol import Str\n", diff --git a/docs/report/026.ipynb b/docs/report/026.ipynb index e0ee3d1f..f347f5db 100644 --- a/docs/report/026.ipynb +++ b/docs/report/026.ipynb @@ -83,6 +83,7 @@ "import plotly.graph_objects as go\n", "import sympy as sp\n", "from ampform.io import aslatex\n", + "from ampform.kinematics.phasespace import Kallen\n", "from ampform.sympy import unevaluated\n", "from IPython.display import Math\n", "\n", @@ -112,9 +113,6 @@ "outputs": [], "source": [ "# @title\n", - "from ampform.kinematics.phasespace import Kallen\n", - "\n", - "\n", "@unevaluated(real=False)\n", "class PhaseSpaceFactor(sp.Expr):\n", " s: Any\n", diff --git a/docs/report/033.ipynb b/docs/report/033.ipynb index 63c9d5ea..ccde37f2 100644 --- a/docs/report/033.ipynb +++ b/docs/report/033.ipynb @@ -94,7 +94,7 @@ "source_hidden": true }, "mystnb": { - "code_prompt_show": "Hide warnings" + "code_prompt_show": "Import Python libraries" }, "tags": [ "hide-input" @@ -108,27 +108,6 @@ "import os\n", "import warnings\n", "\n", - "os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n", - "logging.disable(logging.WARNING)\n", - "warnings.filterwarnings(\"ignore\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "jupyter": { - "source_hidden": true - }, - "mystnb": { - "code_prompt_show": "Import Python libraries" - }, - "tags": [ - "hide-input" - ] - }, - "outputs": [], - "source": [ "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -140,7 +119,11 @@ "from iminuit import Minuit\n", "from matplotlib import gridspec\n", "from tqdm.auto import tqdm\n", - "from vector.backends.numpy import MomentumNumpy4D" + "from vector.backends.numpy import MomentumNumpy4D\n", + "\n", + "os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\"\n", + "logging.disable(logging.WARNING)\n", + "warnings.filterwarnings(\"ignore\")" ] }, { diff --git a/pyproject.toml b/pyproject.toml index bc45b566..654b60a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,6 +108,9 @@ local_scheme = "no-local-version" version_scheme = "post-release" write_to = "version.py" +[tool.isort] +profile = "black" + [tool.pixi.project] channels = ["conda-forge"] platforms = ["linux-64"]