From 66a73f43b52dbaa91bfd898656251574c6574ea0 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Mon, 1 Dec 2025 11:45:28 +0000 Subject: [PATCH 1/2] :recycle: add `get_config_manager()` for refactor --- nb_cli/handlers/meta.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nb_cli/handlers/meta.py b/nb_cli/handlers/meta.py index 9222fc35..4cc56128 100644 --- a/nb_cli/handlers/meta.py +++ b/nb_cli/handlers/meta.py @@ -37,12 +37,17 @@ def draw_logo() -> str: return figlet_format("NoneBot", font="basic").strip() -def get_nonebot_config() -> NoneBotConfig | LegacyNoneBotConfig: - return GLOBAL_CONFIG.get_nonebot_config() +def get_config_manager(cwd: Path | None = None) -> ConfigManager: + return ConfigManager(working_dir=cwd) if cwd is not None else GLOBAL_CONFIG + + +def get_nonebot_config(cwd: Path | None = None) -> NoneBotConfig | LegacyNoneBotConfig: + config = get_config_manager(cwd) + return config.get_nonebot_config() def get_project_root(cwd: Path | None = None) -> Path: - config = ConfigManager(working_dir=cwd) if cwd is not None else GLOBAL_CONFIG + config = get_config_manager(cwd) return config.project_root @@ -90,7 +95,7 @@ async def _get_env_python() -> str: async def get_default_python(cwd: Path | None = None) -> str: - config = ConfigManager(working_dir=cwd) if cwd is not None else GLOBAL_CONFIG + config = get_config_manager(cwd) if config.python_path is not None: return config.python_path From 0b604e98f6a9b5686771d144af9f06dd62bf64d0 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Mon, 1 Dec 2025 11:46:51 +0000 Subject: [PATCH 2/2] :bug: fix project format upgrade/downgrade always using `GLOBAL_CONFIG` --- nb_cli/handlers/project.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nb_cli/handlers/project.py b/nb_cli/handlers/project.py index 4d3e8e2d..4311e8ad 100644 --- a/nb_cli/handlers/project.py +++ b/nb_cli/handlers/project.py @@ -8,7 +8,6 @@ from nb_cli import _ from nb_cli.config import ( - GLOBAL_CONFIG, SimpleInfo, PackageInfo, NoneBotConfig, @@ -23,6 +22,7 @@ from .meta import ( get_project_root, requires_nonebot, + get_config_manager, get_default_python, get_nonebot_config, requires_project_root, @@ -127,8 +127,8 @@ def _index_by_module_name(data: Iterable[T_info]) -> dict[str, T_info]: @requires_project_root -async def upgrade_project_format() -> None: - bot_config = get_nonebot_config() +async def upgrade_project_format(*, cwd: Path | None = None) -> None: + bot_config = get_nonebot_config(cwd) if isinstance(bot_config, NoneBotConfig): click.echo(_("Current format is already the new format.")) return @@ -178,13 +178,14 @@ async def upgrade_project_format() -> None: builtin_plugins=bot_config.builtin_plugins, ) - GLOBAL_CONFIG.update_nonebot_config(new_config) - GLOBAL_CONFIG.update_dependency(nonebot_pkg, *packages) + manager = get_config_manager(cwd) + manager.update_nonebot_config(new_config) + manager.update_dependency(nonebot_pkg, *packages) @requires_project_root -async def downgrade_project_format() -> None: - bot_config = get_nonebot_config() +async def downgrade_project_format(*, cwd: Path | None = None) -> None: + bot_config = get_nonebot_config(cwd) if isinstance(bot_config, LegacyNoneBotConfig): click.echo(_("Current format is already the old format.")) return @@ -196,4 +197,5 @@ async def downgrade_project_format() -> None: builtin_plugins=bot_config.builtin_plugins, ) - GLOBAL_CONFIG.update_nonebot_config(old_config) + manager = get_config_manager(cwd) + manager.update_nonebot_config(old_config)