Skip to content

Commit

Permalink
[dev] update utils
Browse files Browse the repository at this point in the history
  • Loading branch information
HAOCHENYE committed Nov 1, 2024
1 parent e352262 commit 9ba52c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions opencompass/runners/volc.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ def _run_task(self, cmd, log_path, poll_interval):
task_status = json.loads(ret.stdout)[0]['Status']
except JSONDecodeError:
print('The task is not yet in the queue for '
f"{ret.stdout}, waiting...")
f'{ret.stdout}, waiting...')
time.sleep(poll_interval)
continue
finally:
if task_status not in VolcStatus.__members__.values():
warnings.warn(
f"Unrecognized task status: {task_status}. "
f'Unrecognized task status: {task_status}. '
'This might be due to a newer version of Volc. '
'Please report this issue to the OpenCompass.')

Expand Down Expand Up @@ -281,9 +281,9 @@ def _run_task(self, cmd, log_path, poll_interval):
time.sleep(poll_interval)
continue
else:
print(f"Failed to submit the task for:{result.stdout}")
print(f'Failed to submit the task for:{result.stdout}')
task_status = VolcStatus.exception
f.write(f"{result.stdout}: {result.returncode}")
f.write(f'{result.stdout}: {result.returncode}')

f.close()
return task_status, result.returncode
Expand Down
33 changes: 33 additions & 0 deletions opencompass/utils/enum_extention.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copied from the source code of `enum.StrEnum` to support Python<3.11
from enum import Enum


class StrEnum(str, Enum):
"""Enum where members are also (and must be) strings."""

def __new__(cls, *values):
"""values must already be of type `str`"""
if len(values) > 3:
raise TypeError('too many arguments for str(): %r' % (values, ))
if len(values) == 1:
# it must be a string
if not isinstance(values[0], str):
raise TypeError('%r is not a string' % (values[0], ))
if len(values) >= 2:
# check that encoding argument is a string
if not isinstance(values[1], str):
raise TypeError('encoding must be a string, not %r' %
(values[1], ))
if len(values) == 3:
# check that errors argument is a string
if not isinstance(values[2], str):
raise TypeError('errors must be a string, not %r' %
(values[2]))
value = str(*values)
member = str.__new__(cls, value)
member._value_ = value
return member

def _generate_next_value_(name, start, count, last_values):
"""Return the lower-cased version of the member name."""
return name.lower()

0 comments on commit 9ba52c9

Please sign in to comment.