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

Commit 2440703

Browse files
authored
chore: echarts type and add settings property (#28)
* chore: echarts type and add settings property
1 parent 47a42d9 commit 2440703

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

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: 16 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

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

63+
@property
64+
def tags(self) -> Optional[List[str]]:
65+
"""实验标签"""
66+
return self.__tags
67+
68+
@tags.setter
69+
def tags(self, tags: List[str]) -> None:
70+
"""实验标签"""
71+
if self.__tags is not None:
72+
raise ValueError("tags can only be set once")
73+
self.__tags = tags
74+
6275

6376
class SwanLabSharedSettings(LazySettings):
6477
"""

test/unit/core/test_settings.py

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

0 commit comments

Comments
 (0)