style: format all Python files with Black

Apply Black formatter to the entire codebase for consistent code style.

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-02-26 22:44:03 +08:00
parent 1b16842a2c
commit 3b7c00377f
46 changed files with 1488 additions and 974 deletions

View File

@@ -5,6 +5,7 @@
将现有的 JSON 配置文件迁移到 .env 环境变量文件
"""
import os
import sys
import json
@@ -21,7 +22,7 @@ from config.schema import AppConfig
def migrate_json_to_env(
json_file: str = "config/user_settings.json",
env_file: str = ".env",
backup: bool = True
backup: bool = True,
) -> bool:
"""
迁移 JSON 配置到 .env 文件
@@ -46,7 +47,7 @@ def migrate_json_to_env(
# 检查 .env 文件是否已存在
if env_path.exists():
response = input(f"⚠️ .env 文件已存在: {env_path}\n是否覆盖? (y/N): ")
if response.lower() != 'y':
if response.lower() != "y":
print("❌ 迁移已取消")
return False
@@ -63,6 +64,7 @@ def migrate_json_to_env(
# 使用 ConfigLoader 将字典转换为配置对象
from config.loader import ConfigLoader
config = ConfigLoader._dict_to_config(json_data)
# 保存到 .env 文件
@@ -95,13 +97,13 @@ def migrate_json_to_env(
except Exception as e:
print(f"❌ 迁移失败: {e}")
import traceback
traceback.print_exc()
return False
def create_env_from_example(
example_file: str = ".env.example",
env_file: str = ".env"
example_file: str = ".env.example", env_file: str = ".env"
) -> bool:
"""
从 .env.example 创建 .env 文件
@@ -122,7 +124,7 @@ def create_env_from_example(
if env_path.exists():
response = input(f"⚠️ .env 文件已存在: {env_path}\n是否覆盖? (y/N): ")
if response.lower() != 'y':
if response.lower() != "y":
print("❌ 操作已取消")
return False
@@ -160,7 +162,9 @@ def main():
elif command == "migrate":
# 从 JSON 迁移
print("\n📋 模式: 从 JSON 配置迁移")
json_file = sys.argv[2] if len(sys.argv) > 2 else "config/user_settings.json"
json_file = (
sys.argv[2] if len(sys.argv) > 2 else "config/user_settings.json"
)
env_file = sys.argv[3] if len(sys.argv) > 3 else ".env"
migrate_json_to_env(json_file, env_file)
return
@@ -192,7 +196,9 @@ def main():
choice = input("\n请输入选项 (1-3): ").strip()
if choice == "1":
json_file = input("JSON 配置文件路径 (默认: config/user_settings.json): ").strip()
json_file = input(
"JSON 配置文件路径 (默认: config/user_settings.json): "
).strip()
if not json_file:
json_file = "config/user_settings.json"
@@ -201,7 +207,7 @@ def main():
env_file = ".env"
backup_choice = input("是否备份原 JSON 文件? (Y/n): ").strip().lower()
backup = backup_choice != 'n'
backup = backup_choice != "n"
migrate_json_to_env(json_file, env_file, backup)