Skip to content

Commit

Permalink
MAINT: update lock files and allow NumPy v2 (#147)
Browse files Browse the repository at this point in the history
* DX: ignore all `PytestUnraisableExceptionWarning`s
* DX: move NumPy version constraint to `uv ` table
* DX: run `pytest` in double verbose mode in vscode
* DX: set `PYTHONHASHSEED=0`
* MAINT: apply autofixes by pre-commit hooks
* MAINT: sort cSpell config
  • Loading branch information
redeboer authored Dec 24, 2024
1 parent 09cbf7d commit a1f1a5f
Show file tree
Hide file tree
Showing 10 changed files with 1,390 additions and 923 deletions.
13 changes: 7 additions & 6 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"enableFiletypes": [
"git-commit",
"github-actions-workflow",
"julia",
"jupyter"
],
"flagWords": [
"analyse",
"colour",
Expand Down Expand Up @@ -130,6 +136,7 @@
"yticks"
],
"language": "en-US",
"useGitignore": true,
"version": "0.2",
"words": [
"AmpForm",
Expand Down Expand Up @@ -168,11 +175,5 @@
"SymPy",
"TensorWaves",
"Weisskopf"
],
"enableFiletypes": [
"git-commit",
"github-actions-workflow",
"julia",
"jupyter"
]
}
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
uv sync --all-extras --quiet
source .venv/bin/activate

export PYTHONHASHSEED=0
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/ComPWA/policy
rev: 0.5.5
rev: 0.5.8
hooks:
- id: check-dev-files
args:
- --doc-apt-packages=graphviz
- --environment-variables=PYTHONHASHSEED=0
- --github-pages
- --repo-name=ampform-dpd
- --repo-title=AmpForm-DPD
- id: colab-toc-visible
- id: remove-empty-tags

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
args:
Expand Down Expand Up @@ -53,7 +54,7 @@ repos:
metadata.vscode
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.8.4
hooks:
- id: ruff
args: [--fix]
Expand All @@ -77,7 +78,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/ComPWA/prettier-pre-commit
rev: v3.3.3
rev: v3.4.2
hooks:
- id: prettier

Expand All @@ -87,14 +88,14 @@ repos:
- id: taplo-format

- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
rev: v0.24.2
hooks:
- id: toml-sort
args:
- --in-place

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.15.2
rev: v8.17.0
hooks:
- id: cspell

Expand All @@ -120,11 +121,11 @@ repos:
- python

- repo: https://github.com/ComPWA/pyright-pre-commit
rev: v1.1.386
rev: v1.1.391
hooks:
- id: pyright

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.27
rev: 0.5.11
hooks:
- id: uv-lock
2 changes: 2 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ms-python.mypy-type-checker",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-toolsai.vscode-jupyter-cell-tags",
"ms-vscode.live-server",
"ms-vsliveshare.vsliveshare",
Expand All @@ -30,6 +31,7 @@
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
"ms-toolsai.vscode-jupyter-slideshow",
"travisillig.vscode-json-stable-stringify",
"tyriar.sort-lines"
]
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"python.analysis.autoImportCompletions": false,
"python.analysis.inlayHints.pytestParameters": true,
"python.terminal.activateEnvironment": false,
"python.testing.pytestArgs": ["--color=no"],
"python.testing.pytestArgs": ["--color=no", "--verbose", "--verbose"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"redhat.telemetry.enabled": false,
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"ampform >=0.15.1", # aslatex with keyword arguments
"attrs >=20.1.0", # on_setattr and https://www.attrs.org/en/stable/api.html#next-gen
"cloudpickle",
"numpy~=1.0",
"numpy",
"qrules >=0.10.0",
"sympy >=1.10", # module sympy.printing.numpy and array expressions with shape kwarg
"tensorwaves[jax]",
Expand Down Expand Up @@ -188,6 +188,7 @@ doctest_optionflags = [
]
filterwarnings = [
"error",
"ignore::pytest.PytestUnraisableExceptionWarning",
"ignore:The `hash` argument is deprecated in favor of `unsafe_hash` and will be removed in or after August 2025.:DeprecationWarning",
"ignore:the imp module is deprecated in favour of importlib.*:DeprecationWarning",
]
Expand Down Expand Up @@ -300,7 +301,7 @@ ignore-names = [
"PLW2901",
"S101",
"T20",
"TCH00",
"TC00",
]
"docs/*" = [
"E402",
Expand Down Expand Up @@ -469,3 +470,6 @@ commands =
pre-commit run --all-files {posargs}
description = Perform all linting, formatting, and spelling checks
"""

[tool.uv]
constraint-dependencies = ["numpy~=1.0"]
10 changes: 5 additions & 5 deletions src/ampform_dpd/io/serialization/amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _get_resonance_helicity(
node = vertex["node"]
if all(isinstance(i, int) for i in node):
continue
vertex = cast(HelicityVertex, vertex)
vertex = cast("HelicityVertex", vertex)
helicities = vertex.get("helicities")
if helicities is None: # pyright:ignore[reportUnnecessaryComparison]
msg = "Vertex does not contain helicities. Is it an LS vertex?"
Expand All @@ -243,7 +243,7 @@ def _get_final_state_helicities(
vertices = chain_definition["vertices"]
collected_helicities: dict[FinalStateID, sp.Rational] = {}
for vertex in vertices:
vertex = cast(HelicityVertex, vertex)
vertex = cast("HelicityVertex", vertex)
helicities = vertex.get("helicities")
if helicities is None: # pyright:ignore[reportUnnecessaryComparison]
msg = "Vertex does not contain helicities. Is it an LS vertex?"
Expand Down Expand Up @@ -271,15 +271,15 @@ def formulate_recoupling( # noqa: PLR0914
node = vertex["node"]
λa, λb = map(_get_helicity_symbol, node)
if vertex_type in {"helicity", "parity"}:
vertex = cast(HelicityVertex, vertex)
vertex = cast("HelicityVertex", vertex)
λa0, λb0 = (sp.Rational(v) for v in vertex["helicities"])
if vertex_type == "parity":
vertex = cast(ParityVertex, vertex)
vertex = cast("ParityVertex", vertex)
f = _sign_to_value(vertex.get("parity_factor", "+"))
return ParityRecoupling(λa, λb, λa0, λb0, f)
return HelicityRecoupling(λa, λb, λa0, λb0)
if vertex_type == "ls":
vertex = cast(LSVertex, vertex)
vertex = cast("LSVertex", vertex)
l = int(vertex["l"])
s = sp.Rational(vertex["s"])
ja, jb = _get_child_spins(model, chain_idx, vertex_idx)
Expand Down
6 changes: 3 additions & 3 deletions src/ampform_dpd/io/serialization/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def formulate_form_factor(vertex: Vertex, model: ModelDefinition) -> DefinedExpr
if not function_name:
return DefinedExpression()
function_definition = get_function_definition(function_name, model)
function_definition = cast(BlattWeisskopfDefinition, function_definition)
function_definition = cast("BlattWeisskopfDefinition", function_definition)
function_type = function_definition["type"]
if function_type == "BlattWeisskopf":
node = vertex["node"]
Expand All @@ -103,7 +103,7 @@ def formulate_breit_wigner(
propagator: Propagator, resonance: str, model: ModelDefinition
) -> DefinedExpression:
function_definition = get_function_definition(propagator["parametrization"], model)
function_definition = cast(BreitWignerDefinition, function_definition)
function_definition = cast("BreitWignerDefinition", function_definition)
node = propagator["node"]
i, j = node
s = to_mandelstam_symbol(node)
Expand All @@ -129,7 +129,7 @@ def formulate_multichannel_breit_wigner( # noqa: PLR0914
propagator: Propagator, resonance: str, model: ModelDefinition
) -> DefinedExpression:
function_definition = get_function_definition(propagator["parametrization"], model)
function_definition = cast(MultichannelBreitWignerDefinition, function_definition)
function_definition = cast("MultichannelBreitWignerDefinition", function_definition)
channel_definitions = function_definition["channels"]
if len(channel_definitions) < 2: # noqa: PLR2004
msg = "Need at least two channels for a multi-channel Breit-Wigner"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def test_get_readable_hash(
assert "PYTHONHASHSEED has not been set." in caplog.text
caplog.clear()
elif python_hash_seed == "0":
if sys.version_info < (3, 11):
expected_hash = expected_hash[0] # type:ignore[assignment]
else:
if sys.version_info >= (3, 11):
expected_hash = expected_hash[1] # type:ignore[assignment]
else:
expected_hash = expected_hash[0] # type:ignore[assignment]
expected = f"pythonhashseed-0{expected_hash:+d}"
assert h == expected
else:
Expand Down
Loading

0 comments on commit a1f1a5f

Please sign in to comment.