From 090854630744da70693d663dad662c648e11b512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sun, 11 Jun 2023 15:02:12 +0200 Subject: [PATCH 1/3] TST: add a test for user defined deposition method with metadata --- tests/test_deposit.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_deposit.py b/tests/test_deposit.py index 5447145..8f71157 100644 --- a/tests/test_deposit.py +++ b/tests/test_deposit.py @@ -98,6 +98,21 @@ def test_callable_method(sample_2D_dataset): sample_2D_dataset.deposit("mass", method=_deposit_ngp_2D) +def test_callable_method_with_metadata(sample_2D_dataset): + _is_used = False + _md_is_received = False + + def fake_dep(*args, metadata=None, **kwargs): + nonlocal _is_used, _md_is_received + _is_used = True + _md_is_received = metadata is not None + return _deposit_ngp_2D(*args, **kwargs) + + sample_2D_dataset.deposit("mass", method=fake_dep) + assert _is_used + assert _md_is_received + + @pytest.mark.parametrize("method", ["ngp", "cic", "tsc"]) @pytest.mark.mpl_image_compare def test_2D_deposit(sample_2D_dataset, method): From 0412c6a6b5a5858f92c40c643e33be41d242ebac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sun, 11 Jun 2023 15:04:19 +0200 Subject: [PATCH 2/3] ENH: add support for passing metadata to custom deposition methods --- src/gpgi/types.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gpgi/types.py b/src/gpgi/types.py index c49c2b9..6eeb5bf 100644 --- a/src/gpgi/types.py +++ b/src/gpgi/types.py @@ -5,7 +5,7 @@ import warnings from abc import ABC, abstractmethod from copy import deepcopy -from functools import cached_property, reduce +from functools import cached_property, partial, reduce from itertools import chain from time import monotonic_ns from typing import TYPE_CHECKING, Any, Dict, Literal, Protocol, Tuple, cast @@ -558,7 +558,13 @@ def deposit( method = "ngp" if callable(method): - func = method + from inspect import signature + + sig = signature(method) + if "metadata" in sig.parameters: + func = cast(DepositionMethodT, partial(method, metadata=self.metadata)) + else: + func = method else: if method not in _deposition_method_names: raise ValueError( From 6345b8a7858af2f744c90aa8e47848b1b0ef1f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sun, 11 Jun 2023 15:04:50 +0200 Subject: [PATCH 3/3] REL: prep release 0.13.0 --- pyproject.toml | 2 +- src/gpgi/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a6f0309..cbd9171 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" [project] name = "gpgi" -version = "0.12.0" +version = "0.13.0" description = "A Generic Particle+Grid Interface" authors = [ { name = "C.M.T. Robert" }, diff --git a/src/gpgi/__init__.py b/src/gpgi/__init__.py index 5ececdf..e4d735c 100644 --- a/src/gpgi/__init__.py +++ b/src/gpgi/__init__.py @@ -2,4 +2,4 @@ from .api import load -__version__ = "0.12.0" +__version__ = "0.13.0"