From 54eac7c38ba39eca4b3edae188848d1f2f7cbf54 Mon Sep 17 00:00:00 2001 From: Toni Harzendorf Date: Sun, 2 Feb 2025 11:58:41 +0100 Subject: [PATCH 1/3] fix accidentally importing StrEnum --- pyslurm/core/reservation.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyslurm/core/reservation.pyx b/pyslurm/core/reservation.pyx index e208c095..109e7ded 100644 --- a/pyslurm/core/reservation.pyx +++ b/pyslurm/core/reservation.pyx @@ -32,7 +32,7 @@ from datetime import datetime from pyslurm import xcollections from pyslurm.utils.helpers import instance_to_dict from pyslurm.utils.enums import SlurmEnum, SlurmFlag -from enum import auto, StrEnum +from enum import auto from pyslurm.utils.ctime import ( _raw_time, timestr_to_mins, From 863cc1831036ad16042f54ce20f65473d682379b Mon Sep 17 00:00:00 2001 From: Toni Harzendorf Date: Sun, 2 Feb 2025 11:59:04 +0100 Subject: [PATCH 2/3] We can't use auto with multiple other values after it, sadly. Due to a bug in stdlib Enum, that is only fixed in 3.11 and 3.12 --- pyslurm/core/reservation.pyx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyslurm/core/reservation.pyx b/pyslurm/core/reservation.pyx index 109e7ded..7b25aba8 100644 --- a/pyslurm/core/reservation.pyx +++ b/pyslurm/core/reservation.pyx @@ -541,9 +541,9 @@ class ReservationReoccurrence(SlurmEnum): See {scontrol#OPT_Flags} for more info. """ - NO = auto() - DAILY = auto(), slurm.RESERVE_FLAG_DAILY, slurm.RESERVE_FLAG_NO_DAILY - HOURLY = auto(), slurm.RESERVE_FLAG_HOURLY, slurm.RESERVE_FLAG_NO_HOURLY - WEEKLY = auto(), slurm.RESERVE_FLAG_WEEKLY, slurm.RESERVE_FLAG_NO_WEEKLY - WEEKDAY = auto(), slurm.RESERVE_FLAG_WEEKDAY, slurm.RESERVE_FLAG_NO_WEEKDAY - WEEKEND = auto(), slurm.RESERVE_FLAG_WEEKEND, slurm.RESERVE_FLAG_NO_WEEKEND + NO = "NO" + DAILY = "DAILY", slurm.RESERVE_FLAG_DAILY, slurm.RESERVE_FLAG_NO_DAILY + HOURLY = "HOURLY", slurm.RESERVE_FLAG_HOURLY, slurm.RESERVE_FLAG_NO_HOURLY + WEEKLY = "WEEKLY", slurm.RESERVE_FLAG_WEEKLY, slurm.RESERVE_FLAG_NO_WEEKLY + WEEKDAY = "WEEKDAY", slurm.RESERVE_FLAG_WEEKDAY, slurm.RESERVE_FLAG_NO_WEEKDAY + WEEKEND = "WEEKEND", slurm.RESERVE_FLAG_WEEKEND, slurm.RESERVE_FLAG_NO_WEEKEND From 476ea76be71c780a140f2e3bfcb06b5d71d4ea6f Mon Sep 17 00:00:00 2001 From: Toni Harzendorf Date: Sun, 2 Feb 2025 11:59:52 +0100 Subject: [PATCH 3/3] fix SlurmFlag for Python < 3.10 --- pyslurm/utils/enums.pyx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyslurm/utils/enums.pyx b/pyslurm/utils/enums.pyx index f453d2f8..974a8386 100644 --- a/pyslurm/utils/enums.pyx +++ b/pyslurm/utils/enums.pyx @@ -87,7 +87,15 @@ class SlurmEnum(str, Enum, metaclass=DocstringSupport): class SlurmFlag(Flag, metaclass=DocstringSupport): def __new__(cls, flag, *args): - obj = super()._new_member_(cls) + parent = super() + if hasattr(parent, "_new_member_"): + # For Python >= 3.10, use _new_member_. + # We could very likely just also use object.__new__, but it works + # here, so no need to change it now. + obj = parent._new_member_(cls) + else: + obj = object.__new__(cls) + obj._value_ = int(flag) obj._clear_flag = int(args[0]) if len(args) >= 1 else 0 return obj