From 37c8c1b4fabce8fecd438b1119fb8b0f13224e4c Mon Sep 17 00:00:00 2001 From: Jorn Bruggeman Date: Wed, 8 Jul 2026 13:23:59 +0200 Subject: [PATCH 1/4] pyfabm.Model: support PathLike input --- src/pyfabm/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pyfabm/__init__.py b/src/pyfabm/__init__.py index 0337b690..c6c17cb8 100644 --- a/src/pyfabm/__init__.py +++ b/src/pyfabm/__init__.py @@ -1068,7 +1068,7 @@ def __init__(self, model: "Model", name: str): class Model(object): def __init__( self, - path: Union[str, dict] = "fabm.yaml", + path: Union[str, dict, os.PathLike[str]] = "fabm.yaml", shape: Tuple[int, ...] = (), libname: Optional[str] = None, start: Optional[Tuple[int, ...]] = None, @@ -1095,6 +1095,8 @@ def _none_representer(self: Dumper, _: None) -> Any: yaml.dump(path, wrapper, Dumper=Dumper) path = f.name delete = True + else: + path = os.fspath(path) if libname is None: # Pick one of the built-in FABM libraries (0D or 1D) From 0ba316d945a206860c398498db089db23c41313c Mon Sep 17 00:00:00 2001 From: Jorn Bruggeman Date: Wed, 8 Jul 2026 14:22:41 +0200 Subject: [PATCH 2/4] use PathLike instead of PathLike[str] as latter requires python >= 3.9 --- src/pyfabm/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyfabm/__init__.py b/src/pyfabm/__init__.py index c6c17cb8..2db2e77b 100644 --- a/src/pyfabm/__init__.py +++ b/src/pyfabm/__init__.py @@ -1068,7 +1068,7 @@ def __init__(self, model: "Model", name: str): class Model(object): def __init__( self, - path: Union[str, dict, os.PathLike[str]] = "fabm.yaml", + path: Union[str, dict, os.PathLike] = "fabm.yaml", shape: Tuple[int, ...] = (), libname: Optional[str] = None, start: Optional[Tuple[int, ...]] = None, From b2f01a02fc5904b6bdda75cbfb3a270b1e6a4d7a Mon Sep 17 00:00:00 2001 From: Jorn Bruggeman Date: Wed, 8 Jul 2026 16:27:08 +0200 Subject: [PATCH 3/4] extend PathLike support to save_settings --- src/pyfabm/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pyfabm/__init__.py b/src/pyfabm/__init__.py index 2db2e77b..00d265e9 100644 --- a/src/pyfabm/__init__.py +++ b/src/pyfabm/__init__.py @@ -23,6 +23,7 @@ # typing.Final not available in Python 3.7 from typing import Any + try: from typing import Final, SupportsIndex except ImportError: @@ -42,7 +43,6 @@ sys.exit(1) import numpy.typing as npt - LOG_CALLBACK = ctypes.CFUNCTYPE(None, ctypes.c_char_p) @@ -1294,9 +1294,11 @@ def setCellThickness(self, value: npt.ArrayLike): def getSubModel(self, name: str) -> SubModel: return SubModel(self, name) - def save_settings(self, path: str, display: int = DISPLAY_NORMAL): + def save_settings( + self, path: Union[str, os.PathLike], display: int = DISPLAY_NORMAL + ): """Write model configuration to yaml file""" - self.fabm.save_settings(self.pmodel, path.encode("ascii"), display) + self.fabm.save_settings(self.pmodel, os.fspath(path).encode("ascii"), display) def _save_state(self) -> Tuple[Mapping[str, np.ndarray], Mapping[str, np.ndarray]]: environment = {} From ef374703c0f93437b4f9d1f35e7a0af270868bff Mon Sep 17 00:00:00 2001 From: Jorn Bruggeman Date: Wed, 8 Jul 2026 17:43:19 +0100 Subject: [PATCH 4/4] further use of Path and PathLike --- src/pyfabm/complete_yaml.py | 7 +++++-- src/pyfabm/utils/fabm_complete_yaml.py | 3 +++ src/pyfabm/utils/fabm_configuration_gui.py | 4 +++- src/pyfabm/utils/fabm_describe_model.py | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pyfabm/complete_yaml.py b/src/pyfabm/complete_yaml.py index b9e142a0..eab5f054 100644 --- a/src/pyfabm/complete_yaml.py +++ b/src/pyfabm/complete_yaml.py @@ -1,9 +1,12 @@ +from typing import Union +import os + import pyfabm def processFile( - infile: str, - outfile: str, + infile: Union[str, os.PathLike], + outfile: Union[str, os.PathLike], subtract_background: bool = False, add_missing: bool = False, ): diff --git a/src/pyfabm/utils/fabm_complete_yaml.py b/src/pyfabm/utils/fabm_complete_yaml.py index 266e1a36..2f96db2d 100755 --- a/src/pyfabm/utils/fabm_complete_yaml.py +++ b/src/pyfabm/utils/fabm_complete_yaml.py @@ -7,6 +7,7 @@ """ import sys +from pathlib import Path try: import pyfabm.complete_yaml @@ -21,6 +22,7 @@ def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "path", + type=Path, help=( "Path to a YAML file with the model configuration that needs to" " be completed." @@ -28,6 +30,7 @@ def main() -> None: ) parser.add_argument( "output_path", + type=Path, help=( "Path to save the completed YAML file to. If not provided," " this defaults to the file from which the model configuration is read." diff --git a/src/pyfabm/utils/fabm_configuration_gui.py b/src/pyfabm/utils/fabm_configuration_gui.py index 3fe5085f..c4eaeb89 100755 --- a/src/pyfabm/utils/fabm_configuration_gui.py +++ b/src/pyfabm/utils/fabm_configuration_gui.py @@ -5,6 +5,7 @@ """ import sys +from pathlib import Path try: import pyfabm @@ -26,7 +27,8 @@ def main() -> None: "path", help="Path to a YAML file with the model configuration", nargs="?", - default="fabm.yaml", + type=Path, + default=Path("fabm.yaml"), ) args = parser.parse_args() diff --git a/src/pyfabm/utils/fabm_describe_model.py b/src/pyfabm/utils/fabm_describe_model.py index b42e5320..b694b6c8 100755 --- a/src/pyfabm/utils/fabm_describe_model.py +++ b/src/pyfabm/utils/fabm_describe_model.py @@ -6,6 +6,7 @@ """ import sys +from pathlib import Path try: import pyfabm @@ -22,7 +23,8 @@ def main() -> None: "path", help="Path to a YAML file with the model configuration", nargs="?", - default="fabm.yaml", + type=Path, + default=Path("fabm.yaml"), ) parser.add_argument( "--all",