diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..bd28b9c --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.9 diff --git a/pycoupler/config.py b/pycoupler/config.py index 778d14d..9838cd9 100644 --- a/pycoupler/config.py +++ b/pycoupler/config.py @@ -186,7 +186,7 @@ def run_model_bin( detach: bool = False, # pyright: ignore[reportExplicitAny] subprocess_args: dict[str, Any] = {}, - ) -> CompletedProcess[str] | CompletedProcess[bytes] | Popen[str] | Popen[bytes]: + ): # -> CompletedProcess[str] | CompletedProcess[bytes] | Popen[str] | Popen[bytes]: """Runs the LPJmL model binaries in the configured environment Parameters @@ -1362,7 +1362,7 @@ def parse_config( "cc1: fatal error: .*: No such file or directory", json_str.stdout.decode() ): raise FileNotFoundError( - f"Config file '{file_name}' does not exists{" in the container" if in_container else ""}." + f"Config file '{file_name}' does not exists{' in the container' if in_container else ''}." ) else: json_str.check_returncode() diff --git a/pycoupler/run.py b/pycoupler/run.py index 947552c..338d544 100644 --- a/pycoupler/run.py +++ b/pycoupler/run.py @@ -102,19 +102,21 @@ def run_lpjml(config_file: str, std_to_file=False): return operate_lpjml(config_file, std_to_file, False) +# TODO: Removed tpe hints for Python 3.9 support, should be changed back after upgrade of the base python version. +# Because Python 3.9 doesn’t support type unions: https://bugs.python.org/issue42233 def submit_lpjml( config_file, - group: str | None = None, - sclass: str | None = None, + group=None, # str | None + sclass=None, # str | None ntasks: int = 256, - wtime: str | None = None, - dependency: int | str | None = None, - blocking: str | None = None, - option: str | list[str] | None = None, - couple_to: str | Path | None = None, - venv_path: str | Path | None = None, - modules: str | None = None, - partition: str | None = None, + wtime=None, # str | None + dependency=None, # int | str | None + blocking=None, # str | None + option=None, # str | list[str] | None + couple_to=None, # str | Path | None + venv_path=None, # str | Path | None + modules=None, # str | None + partition=None, # str | None ): """Submit LPJmL run to Slurm using `lpjsubmit` and a generated (class LpjmlConfig) config file. @@ -252,7 +254,7 @@ def submit_lpjml( ) job_control_file = job_control_file.rename( - job_control_file.with_stem(f"slurm_{getattr(config, "sim_name", "")}") + job_control_file.with_stem(f"slurm_{getattr(config, 'sim_name', '')}") ) sbatch_cmd = ["sbatch"] diff --git a/tests/test_run.py b/tests/test_run.py index 386db45..1efd397 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -130,7 +130,8 @@ def test_command( "-wtime", self.wtime, "-couple", - f"{f"{mock_venv}/bin/python" if mock_venv else sys.executable} {couple_script} {config_coupled_json}", + (f"{mock_venv}/bin/python" if mock_venv else sys.executable) + + f" {couple_script} {config_coupled_json}", str(self.ntasks), config_coupled_json, ] diff --git a/tests/utils.py b/tests/utils.py index 7ad2680..7788b2d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,25 +1,27 @@ -from typing import NotRequired, TypedDict +from typing import TypedDict # , NotRequired TODO: Was added in python 3.11 import struct class ClmHeader(TypedDict): - name: NotRequired[str] - version: NotRequired[int] - order: NotRequired[int] - firstyear: NotRequired[int] - nyear: NotRequired[int] - firstcell: NotRequired[int] - ncell: NotRequired[int] - nbands: NotRequired[int] - cellsize_lon: NotRequired[float] - scalar: NotRequired[float] - cellsize_lat: NotRequired[float] - datatype: NotRequired[int] - nstep: NotRequired[int] - timestep: NotRequired[int] - - -def clm_file(header: ClmHeader, big_endian: bool = False, data: list[int | float] = []): + name: str # NotRequired[str] + version: int # NotRequired[int] + order: int # NotRequired[int] + firstyear: int # NotRequired[int] + nyear: int # NotRequired[int] + firstcell: int # NotRequired[int] + ncell: int # NotRequired[int] + nbands: int # NotRequired[int] + cellsize_lon: float # NotRequired[float] + scalar: float # NotRequired[float] + cellsize_lat: float # NotRequired[float] + datatype: int # NotRequired[int] + nstep: int # NotRequired[int] + timestep: int # NotRequired[int] + + +def clm_file( + header: ClmHeader, big_endian: bool = False, data=[] +): # data: list[int | float] version = header.get("version", 4) name = header.get("name", "LPJGRID")