Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "hatchling.build"

[project]
name = "swankit"
version = "0.1.7"
version = "0.1.8"
dynamic = ["readme", "dependencies"]
description = "Base toolkit for SwanLab"
license = "Apache-2.0"
Expand Down
2 changes: 2 additions & 0 deletions swankit/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def __init__(self, chart_type: str, column_type: str):

MOLECULE = ChartItem("molecule", "MOLECULE")

ECHARTS = ChartItem("echarts", "ECHARTS")

# ---------------------------------- 需要子类实现的方法 ----------------------------------

@abstractmethod
Expand Down
19 changes: 16 additions & 3 deletions swankit/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
swankit 为 swanlab 定制的配置类
"""
import os
from typing import Tuple
from typing import Tuple, List, Optional


class LazySettings:
Expand All @@ -20,6 +20,7 @@ def __init__(self):
self.__exp_name = None
self.__exp_colors = None
self.__description = None
self.__tags = None

@property
def exp_name(self) -> str:
Expand All @@ -36,7 +37,7 @@ def exp_name(self, exp_name: str) -> None:
self.__exp_name = exp_name

@property
def exp_colors(self) -> Tuple[str, str]:
def exp_colors(self) -> Optional[Tuple[str, str]]:
"""实验颜色"""
return self.__exp_colors

Expand All @@ -48,7 +49,7 @@ def exp_colors(self, exp_colors: Tuple[str, str]) -> None:
self.__exp_colors = exp_colors

@property
def description(self) -> str:
def description(self) -> Optional[str]:
"""实验描述"""
return self.__description

Expand All @@ -59,6 +60,18 @@ def description(self, description: str) -> None:
raise ValueError("description can only be set once")
self.__description = description

@property
Comment thread
SAKURA-CAT marked this conversation as resolved.
def tags(self) -> Optional[List[str]]:
"""实验标签"""
return self.__tags

@tags.setter
def tags(self, tags: List[str]) -> None:
"""实验标签"""
if self.__tags is not None:
raise ValueError("tags can only be set once")
self.__tags = tags


class SwanLabSharedSettings(LazySettings):
"""
Expand Down
28 changes: 28 additions & 0 deletions test/unit/core/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
@author: cunyue
@file: test_settings.py
@time: 2025/5/15 18:15
@description: 测试 settings
"""

import pytest


def test_lazy_settings():
from swankit.core.settings import LazySettings

settings = LazySettings()
settings.exp_name = "test"
settings.exp_colors = ("red", "blue")
settings.description = "test description"

assert settings.exp_name == "test"
assert settings.exp_colors == ("red", "blue")
assert settings.description == "test description"

with pytest.raises(ValueError, match="exp_name can only be set once"):
settings.exp_name = "test2"
with pytest.raises(ValueError, match="exp_colors can only be set once"):
settings.exp_colors = ("green", "yellow")
with pytest.raises(ValueError, match="description can only be set once"):
settings.description = "test description 2"