Skip to content

Commit 62410f3

Browse files
committed
perf: 优化项目模板版本号动态生成逻辑
1 parent cff0a50 commit 62410f3

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

magic_dash/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
__version__ = "0.5.0rc2"
1313

14+
1415
# 创建rich console实例
1516
console = Console()
1617

@@ -159,18 +160,19 @@ def _create(name, path):
159160
dst=os.path.join(path, name),
160161
)
161162

162-
# 替换版本号
163-
base_config_path = os.path.join(path, name, "configs", "base_config.py")
164-
if os.path.exists(base_config_path):
165-
with open(base_config_path, "r", encoding="utf-8") as f:
166-
content = f.read()
167-
content = re.sub(
168-
r'app_version: str = "[^"]*"',
169-
f'app_version: str = "{__version__}"',
170-
content,
171-
)
172-
with open(base_config_path, "w", encoding="utf-8") as f:
173-
f.write(content)
163+
# 替换版本号 (仅 magic-dash 系列模板)
164+
if name in ("magic-dash", "magic-dash-pro"):
165+
base_config_path = os.path.join(path, name, "configs", "base_config.py")
166+
if os.path.exists(base_config_path):
167+
with open(base_config_path, "r", encoding="utf-8") as f:
168+
content = f.read()
169+
content = re.sub(
170+
r'app_version: str = "[^"]*"',
171+
f'app_version: str = "{__version__}"',
172+
content,
173+
)
174+
with open(base_config_path, "w", encoding="utf-8") as f:
175+
f.write(content)
174176

175177
# 重命名项目
176178
os.rename(

magic_dash/templates/magic-dash-pro/configs/base_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BaseConfig:
88
app_title: str = "Magic Dash Pro"
99

1010
# 应用版本
11-
app_version: str = "0.5.0"
11+
app_version: str = "dev"
1212

1313
# 是否启用版本更新日志通知功能,每次的新版本更新日志将在用户点击“已阅”按钮后不再重复展示
1414
enable_version_changelog_modal: bool = False
@@ -53,8 +53,8 @@ class BaseConfig:
5353
enable_fullscreen_watermark: bool = False
5454

5555
# 当开启了全屏额外水印功能时,用于动态处理实际水印内容输出
56-
fullscreen_watermark_generator: Callable = (
57-
lambda current_user: current_user.user_name
56+
fullscreen_watermark_generator: Callable = lambda current_user: (
57+
current_user.user_name
5858
)
5959

6060
# 用于登录密码加密传输的RSA公钥文件路径

magic_dash/templates/magic-dash/configs/base_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BaseConfig:
88
app_title: str = "Magic Dash"
99

1010
# 应用版本
11-
app_version: str = "0.5.0"
11+
app_version: str = "dev"
1212

1313
# 是否启用版本更新日志通知功能,每次的新版本更新日志将在用户点击“已阅”按钮后不再重复展示
1414
enable_version_changelog_modal: bool = False

0 commit comments

Comments
 (0)