Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 2e22b02

Browse files
committed
chore: echarts type and add settings property
1 parent 47a42d9 commit 2e22b02

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build-backend = "hatchling.build"
99

1010
[project]
1111
name = "swankit"
12-
version = "0.1.7"
12+
version = "0.1.8"
1313
dynamic = ["readme", "dependencies"]
1414
description = "Base toolkit for SwanLab"
1515
license = "Apache-2.0"

swankit/core/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def __init__(self, chart_type: str, column_type: str):
153153

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

156+
ECHARTS = ChartItem("echarts", "ECHARTS")
157+
156158
# ---------------------------------- 需要子类实现的方法 ----------------------------------
157159

158160
@abstractmethod

swankit/core/settings.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
swankit 为 swanlab 定制的配置类
99
"""
1010
import os
11-
from typing import Tuple
11+
from typing import Tuple, List, Optional
1212

1313

1414
class LazySettings:
@@ -20,6 +20,7 @@ def __init__(self):
2020
self.__exp_name = None
2121
self.__exp_colors = None
2222
self.__description = None
23+
self.__tags = None
2324

2425
@property
2526
def exp_name(self) -> str:
@@ -36,7 +37,7 @@ def exp_name(self, exp_name: str) -> None:
3637
self.__exp_name = exp_name
3738

3839
@property
39-
def exp_colors(self) -> Tuple[str, str]:
40+
def exp_colors(self) -> Optional[Tuple[str, str]]:
4041
"""实验颜色"""
4142
return self.__exp_colors
4243

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

5051
@property
51-
def description(self) -> str:
52+
def description(self) -> Optional[str]:
5253
"""实验描述"""
5354
return self.__description
5455

@@ -58,6 +59,16 @@ def description(self, description: str) -> None:
5859
if self.__description is not None:
5960
raise ValueError("description can only be set once")
6061
self.__description = description
62+
63+
@property
64+
def tags(self) -> Optional[List[str]]:
65+
return self.__tags
66+
67+
@tags.setter
68+
def tags(self, tags:List[str]) -> None:
69+
if self.__tags is not None:
70+
raise ValueError("tags can only be set once")
71+
self.__tags = tags
6172

6273

6374
class SwanLabSharedSettings(LazySettings):

test/unit/core/test_settings.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
@author: cunyue
3+
@file: test_settings.py
4+
@time: 2025/5/15 18:15
5+
@description: 测试 settings
6+
"""
7+
8+
9+
def test_lazy_settings():
10+
from swankit.core.settings import LazySettings
11+
12+
settings = LazySettings()
13+
settings.exp_name = "test"
14+
settings.exp_colors = ("red", "blue")
15+
settings.description = "test description"
16+
17+
assert settings.exp_name == "test"
18+
assert settings.exp_colors == ("red", "blue")
19+
assert settings.description == "test description"
20+
21+
try:
22+
settings.exp_name = "test2"
23+
except ValueError as e:
24+
assert str(e) == "exp_name can only be set once"
25+
26+
try:
27+
settings.exp_colors = ("green", "yellow")
28+
except ValueError as e:
29+
assert str(e) == "exp_colors can only be set once"
30+
31+
try:
32+
settings.description = "test description 2"
33+
except ValueError as e:
34+
assert str(e) == "description can only be set once"

0 commit comments

Comments
 (0)