Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions swanlab/data/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def init(
if mode in ["offline", "local"] and user_settings.backup is False:
raise RuntimeError("You can't use offline or local mode with backup=False!")
# 6. 校验 resume 与 id
id = check_run_id_format(id)
resume = resume or 'never'
if resume == 'never':
# 不允许传递 id
Expand All @@ -314,8 +315,6 @@ def init(
raise RuntimeError("You can only use resume in cloud mode.")
if resume == "must" and id is None:
raise ValueError('You must pass id when resume=must.')
if id is not None:
check_run_id_format(id)
run_store = get_run_store()
# ---------------------------------- 初始化swanlog文件夹 ----------------------------------
env_key = SwanLabEnv.SWANLOG_FOLDER.value
Expand Down
2 changes: 1 addition & 1 deletion swanlab/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def check_run_id_format(run_id: str = None) -> Optional[str]:
:return: str 检查后的字符串
:raises ValueError: 如果运行ID不符合要求
"""
if run_id is None:
if not run_id:
return None
run_id_str = str(run_id)
if not re.match(r"^[a-z0-9]{21}$", run_id_str):
Expand Down
2 changes: 1 addition & 1 deletion test/unit/data/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def test_never_with_id(self):
never 模式不允许传递 id 参数
"""
with pytest.raises(RuntimeError) as e:
S.init(resume='never', id='test_id')
S.init(resume='never', id='abcdefghijklmnopqrstu')
assert str(e.value) == "You can't pass id when resume=never or resume=False."

# ---------------------------------- allow 部分 ----------------------------------
Expand Down
5 changes: 1 addition & 4 deletions test/unit/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,4 @@ def test_run_id_format_numeric_input():

@staticmethod
def test_run_id_format_empty_string():
with pytest.raises(
ValueError, match=r"id .* is invalid, it must be 21 characters of lowercase letters and digits"
):
check_run_id_format("")
assert check_run_id_format("") is None