diff --git a/generator.py b/generator.py index 30d3614..71ea8eb 100644 --- a/generator.py +++ b/generator.py @@ -234,7 +234,7 @@ def main(): print("\n操作完成!") - except Exception as e: # noqa: BLE001 - CLI 顶层兜底,输出可读错误 + except Exception as e: print(f"\n操作失败: {str(e)}") import traceback traceback.print_exc() diff --git a/migrations/env.py b/migrations/env.py index cae540a..55c7251 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -8,13 +8,20 @@ from alembic import context from sqlalchemy import create_mock_engine, engine_from_config, pool # 将 src 加入 sys.path(与 scripts/init_db.py 一致),使 core / modules 可导入 -SRC_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src") -sys.path.insert(0, SRC_DIR) +_SRC_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src") -from core.config import SQLALCHEMY_DATABASE_URL # noqa: E402 -from core.database import Base # noqa: E402 + +def _setup_src_path(): + if _SRC_DIR not in sys.path: + sys.path.insert(0, _SRC_DIR) + + +_setup_src_path() + +from core.config import SQLALCHEMY_DATABASE_URL +from core.database import Base # 加载全部模型以填充 metadata(create_app 会连带导入所有业务模块) -from core.app import create_app # noqa: E402 +from core.app import create_app create_app() diff --git a/src/constants/__init__.py b/src/constants/__init__.py index c326bca..3fdb4ae 100644 --- a/src/constants/__init__.py +++ b/src/constants/__init__.py @@ -46,7 +46,7 @@ """常量与枚举统一入口(原 shared/__init__.py 迁移)。""" -from constants.constants import ( # noqa: F401 +from constants.constants import ( PAGE_SIZE, # 默认每页显示记录数 DEFAULT_PASSWORD, # 默认密码 MESSAGE_OK, # 操作成功提示 @@ -58,4 +58,18 @@ from constants.constants import ( # noqa: F401 BANNED_UPLOAD_EXTS, # 禁止上传扩展名 BANNED_UPLOAD_EXTS_MSG, # 禁止上传扩展名提示信息 JWT_SALT_MIN_LENGTH, # JWT 密钥最短长度 -) \ No newline at end of file +) + +__all__ = [ + "PAGE_SIZE", + "DEFAULT_PASSWORD", + "MESSAGE_OK", + "MESSAGE_FAIL", + "SERIALIZE_EXCLUDE_FIELDS", + "SUPERADMIN_ID", + "BUILTIN_ROLE_IDS", + "BUILTIN_UPLOAD_EXTS", + "BANNED_UPLOAD_EXTS", + "BANNED_UPLOAD_EXTS_MSG", + "JWT_SALT_MIN_LENGTH", +] \ No newline at end of file diff --git a/src/core/database.py b/src/core/database.py index f25e02a..7eaacd0 100644 --- a/src/core/database.py +++ b/src/core/database.py @@ -134,7 +134,7 @@ def build_engine(driver: str | None = None, database_url: str | None = None): if drv == 'oracle': # 懒加载:仅 oracle 分支需要 oracledb(thin 模式,无需 Oracle Instant Client) - import oracledb # noqa: F401 + import oracledb # 副作用:注册 SQLAlchemy Oracle 方言 return create_engine( url, pool_size=DB_POOL_SIZE, diff --git a/tests/unit/scripts/test_init_db.py b/tests/unit/scripts/test_init_db.py index ebd3382..a278540 100644 --- a/tests/unit/scripts/test_init_db.py +++ b/tests/unit/scripts/test_init_db.py @@ -9,10 +9,16 @@ from pathlib import Path # scripts/ 下无 __init__.py,把 scripts 目录加进 sys.path 以便直接 import _SCRIPTS_DIR = Path(__file__).resolve().parents[3] / "scripts" -if str(_SCRIPTS_DIR) not in sys.path: - sys.path.insert(0, str(_SCRIPTS_DIR)) -import init_db # noqa: E402 + +def _setup_scripts_path(): + if str(_SCRIPTS_DIR) not in sys.path: + sys.path.insert(0, str(_SCRIPTS_DIR)) + + +_setup_scripts_path() + +import init_db def test_oracle_sequence_sql(): diff --git a/ui/index.html b/ui/index.html index c5e5941..55cba55 100644 --- a/ui/index.html +++ b/ui/index.html @@ -14,7 +14,7 @@ var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); - hm.src = "https://hm.baidu.com/hm.js?3025f35e9071c58643123b5f795c1e5e"; + hm.src = "https://hm.baidu.com/hm.js?8d53050ad5cec3e955fce673f53d1032"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();