diff --git a/pyproject.toml b/pyproject.toml index 2a64763..99751e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/swankit/core/data.py b/swankit/core/data.py index c0fa219..3ff5fae 100644 --- a/swankit/core/data.py +++ b/swankit/core/data.py @@ -153,6 +153,8 @@ def __init__(self, chart_type: str, column_type: str): MOLECULE = ChartItem("molecule", "MOLECULE") + ECHARTS = ChartItem("echarts", "ECHARTS") + # ---------------------------------- 需要子类实现的方法 ---------------------------------- @abstractmethod diff --git a/swankit/core/settings.py b/swankit/core/settings.py index ffa84ad..e681419 100644 --- a/swankit/core/settings.py +++ b/swankit/core/settings.py @@ -8,7 +8,7 @@ swankit 为 swanlab 定制的配置类 """ import os -from typing import Tuple +from typing import Tuple, List, Optional class LazySettings: @@ -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: @@ -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 @@ -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 @@ -59,6 +60,18 @@ def description(self, description: str) -> None: raise ValueError("description can only be set once") self.__description = description + @property + 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): """ diff --git a/test/unit/core/test_settings.py b/test/unit/core/test_settings.py new file mode 100644 index 0000000..3b9cf1a --- /dev/null +++ b/test/unit/core/test_settings.py @@ -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"