Skip to content

Commit

Permalink
Add workaround for old python not supporting ISO 8601 datetimes
Browse files Browse the repository at this point in the history
This should be removed when we drop python 3.10 support.
  • Loading branch information
jfrost-mo committed Aug 23, 2024
1 parent 4a7fa9d commit 62ec811
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/CSET/_workflow_utils/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import shutil
import sys
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timedelta
from typing import Literal
Expand Down Expand Up @@ -85,10 +86,16 @@ def get_file(self, file_path: str, output_dir: str) -> None:

def _get_needed_environment_variables() -> dict:
"""Load the needed variables from the environment."""
# Python 3.10 and older don't fully support ISO 8601 datetime formats.
# TODO: Remove once we drop python 3.10.
if sys.version_info.minor < 11:
_fromisoformat = isodate.parse_datetime
else:
_fromisoformat = datetime.fromisoformat
variables = {
"raw_path": os.environ["DATA_PATH"],
"date_type": os.environ["DATE_TYPE"],
"data_time": datetime.fromisoformat(os.environ["CYLC_TASK_CYCLE_POINT"]),
"data_time": _fromisoformat(os.environ["CYLC_TASK_CYCLE_POINT"]),
"forecast_length": isodate.parse_duration(os.environ["CSET_ANALYSIS_PERIOD"]),
"forecast_offset": isodate.parse_duration(os.environ["CSET_ANALYSIS_OFFSET"]),
"share_dir": os.environ["CYLC_WORKFLOW_SHARE_DIR"],
Expand Down

0 comments on commit 62ec811

Please sign in to comment.