Skip to content

Commit 882c691

Browse files
committed
Use utils.enum_val_2_str() instead of naked str() call for enums across this library to ensure consistent rendering of enum to string across Python versions (is not the case for enum.IntEnum)
1 parent c0766f0 commit 882c691

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/glassesValidator/process/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DataQualityType(Enum):
4040
# so this get serialized in a user-friendly way by pandas..
4141
def __str__(self):
4242
return self.name
43-
utils.register_type(utils.CustomTypeEntry(DataQualityType,'glassesValidator.DataQualityType',str,lambda x: getattr(DataQualityType,x)))
43+
utils.register_type(utils.CustomTypeEntry(DataQualityType,'glassesValidator.DataQualityType',utils.enum_val_2_str,lambda x: getattr(DataQualityType,x)))
4444

4545
def get_DataQualityType_explanation(dq: DataQualityType):
4646
ler_name = "Left eye ray + pose"

src/glassesValidator/utils/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Task(utils.AutoName):
2525
Make_Video = enum.auto()
2626
Unknown = enum.auto()
2727
task_names = [x.value for x in Task]
28-
utils.register_type(utils.CustomTypeEntry(Task,'__enum.Task__',str, lambda x: getattr(Task, x.split('.')[1])))
28+
utils.register_type(utils.CustomTypeEntry(Task,'__enum.Task__', utils.enum_val_2_str, lambda x: getattr(Task, x.split('.')[1])))
2929

3030
def get_task_name_friendly(name: str | Task):
3131
if isinstance(name,Task):
@@ -85,12 +85,12 @@ class Status(utils.AutoName):
8585
Finished = enum.auto()
8686
Errored = enum.auto()
8787
status_names = [x.value for x in Status]
88-
utils.register_type(utils.CustomTypeEntry(Status,'__enum.Status__',str, lambda x: getattr(Status, x.split('.')[1])))
88+
utils.register_type(utils.CustomTypeEntry(Status,'__enum.Status__', utils.enum_val_2_str, lambda x: getattr(Status, x.split('.')[1])))
8989

9090

9191
_status_file = 'glassesValidator.recording'
9292
def _create_recording_status_file(file: pathlib.Path):
93-
task_status_dict = {str(getattr(Task,x)): Status.Not_Started for x in Task.__members__ if x not in ['Not_Imported', 'Make_Video', 'Unknown']}
93+
task_status_dict = {utils.enum_val_2_str(getattr(Task,x)): Status.Not_Started for x in Task.__members__ if x not in ['Not_Imported', 'Make_Video', 'Unknown']}
9494

9595
with open(file, 'w') as f:
9696
json.dump(task_status_dict, f, cls=utils.CustomTypeEncoder)
@@ -112,7 +112,7 @@ def get_recording_status(path: str | pathlib.Path, create_if_missing = False, sk
112112
def get_last_finished_step(status: dict[str,Status]):
113113
last = Task.Not_Imported
114114
while (next_task:=get_next_task(last)) is not None:
115-
if status[str(next_task)] != Status.Finished:
115+
if status[utils.enum_val_2_str(next_task)] != Status.Finished:
116116
break
117117
last = next_task
118118

@@ -124,11 +124,11 @@ def update_recording_status(path: str | pathlib.Path, task: Task, status: Status
124124
return None
125125

126126
# set status of indicated task
127-
rec_status[str(task)] = status
127+
rec_status[utils.enum_val_2_str(task)] = status
128128
# set all later tasks to not started as they would have to be rerun when an earlier tasks is rerun
129129
next_task = task
130130
while (next_task:=get_next_task(next_task)) is not None:
131-
rec_status[str(next_task)] = Status.Not_Started
131+
rec_status[utils.enum_val_2_str(next_task)] = Status.Not_Started
132132

133133
file = path / _status_file
134134
with open(file, 'w') as f:
@@ -140,7 +140,7 @@ def update_recording_status(path: str | pathlib.Path, task: Task, status: Status
140140
def readMarkerIntervalsFile(fileName) -> list[list[int]]:
141141
analyzeFrames = []
142142
if pathlib.Path(fileName).is_file():
143-
with open(str(fileName), 'r' ) as f:
143+
with open(fileName, 'r' ) as f:
144144
reader = csv.DictReader(f, delimiter='\t')
145145
for entry in reader:
146146
analyzeFrames.append([int(float(entry['start_frame'])), int(float(entry['end_frame']))])

0 commit comments

Comments
 (0)