Skip to content

让CLI组织结构更整洁+来点颜色+子命令组功能增强! #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

LIghtJUNction
Copy link
Contributor

@LIghtJUNction LIghtJUNction commented May 31, 2025

解决了 #XYZ

Motivation

Modifications

规范性改动
并修复了一个导入错误,因为函数被弃用

Check

  • 😊 我的 Commit Message 符合良好的规范
  • 👀 我的更改经过良好的测试
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。
  • 😮 我的更改没有引入恶意代码

好的,这是翻译成中文的 pull request 总结:

Sourcery 总结

模块化并改进 AstrBot CLI,将命令重组为不同的模块,引入配置和插件管理组,修复导入问题,并增强验证和文档。

新特性:

  • 添加 'conf' 命令组,包含 'set' 和 'get' 子命令,用于 CLI 配置管理
  • 在 'plug' 组下实现全面的插件管理,包含以下命令:new, list, install, update, remove, 和 search

Bug 修复:

  • 修复已弃用的相对导入,通过在 CLI 入口点切换到绝对导入来解决导入错误

增强:

  • 将 CLI 代码重构为模块化的目录和文件,整合命令和导出,以实现更清晰的组织
  • 引入配置值的验证实用程序,并重新导出现有的实用程序,以实现更强大的输入处理

文档:

  • 添加 README.md,详细说明 CLI 包结构和命令组织
Original summary in English

Summary by Sourcery

Modularize and refine the AstrBot CLI by reorganizing commands into distinct modules, introducing configuration and plugin management groups, fixing import issues, and enhancing validation and documentation.

New Features:

  • Add 'conf' command group with 'set' and 'get' subcommands for CLI configuration management
  • Implement comprehensive plugin management under 'plug' group with commands: new, list, install, update, remove, and search

Bug Fixes:

  • Fix deprecated relative imports by switching to absolute imports in CLI entrypoints to resolve import errors

Enhancements:

  • Restructure CLI code into modular directories and files, consolidating commands and exports for cleaner organization
  • Introduce validation utilities for config values and re-export existing utils for more robust input handling

Documentation:

  • Add README.md detailing the CLI package structure and command organization

Copy link
Contributor

sourcery-ai bot commented May 31, 2025

## 审查者指南

此 PR 通过将命令注册集中在根模块中,将 `conf` 和 `plug` 子命令组模块化为独立文件,使用验证助手增强实用程序导出,修复导入路径,并添加 README 来记录新结构,从而重构了 CLI 包。

#### 流程图:更新后的 CLI 命令结构

```mermaid
graph TD
    A[astrbot cli] --> help_cmd("help [command_name]")
    A --> init_cmd("init")
    A --> run_cmd("run [--reload] [--port]")
    A --> conf_group("conf")
    A --> plug_group("plug")

    conf_group --> conf_set("set <key> <value>")
    conf_group --> conf_get("get [key]")

    plug_group --> plug_new("new <name>")
    plug_group --> plug_list("list [--all]")
    plug_group --> plug_install("install <name> [--proxy]")
    plug_group --> plug_update("update [name] [--proxy]")
    plug_group --> plug_remove("remove <name>")
    plug_group --> plug_search("search <query>")

文件级别更改

变更 详情 文件
重构根 CLI 以实现基于组的命令注册和导入清理
  • main.py 中用绝对导入替换了多个相对导入
  • 将 help 命令装饰器从 @click.command 切换到 @cli.command
  • 将 init 和 run 命令从 commands/ 移到专用模块中
  • 更新了 init.py 以导出 cli 组以及 version
  • 清理了旧的 commands 目录引用
astrbot/cli/__main__.py
astrbot/cli/__init__.py
astrbot/cli/init.py
astrbot/cli/run.py
astrbot/cli/commands/*
引入带有独立模块的 conf 子命令组
  • 创建了 conf/utils.py 用于配置加载/保存和嵌套的 get/set
  • 添加了 conf/set.py 和 conf/get.py 用于设置和检索配置键
  • 将 conf/main.py 定义为 click.command 组并注册 get/set
  • 在 conf/init.py 中导出了 conf 组
astrbot/cli/conf/utils.py
astrbot/cli/conf/set.py
astrbot/cli/conf/get.py
astrbot/cli/conf/__main__.py
astrbot/cli/conf/__init__.py
引入带有专用命令文件的 plug 子命令组
  • 将 plug/main.py 定义为 click.group 并注册子命令
  • 为 new、list、install、update、remove 和 search 操作添加了单独的模块
  • 确保每个插件命令都使用延迟的相对导入来获取实用程序函数
astrbot/cli/plug/__main__.py
astrbot/cli/plug/__init__.py
astrbot/cli/plug/new.py
astrbot/cli/plug/list.py
astrbot/cli/plug/install.py
astrbot/cli/plug/update.py
astrbot/cli/plug/remove.py
astrbot/cli/plug/search.py
使用验证助手增强 CLI 实用程序
  • 创建了 valutils.py,其中包含多个 validate_* 函数,用于端口、日志级别、时区等
  • 更新了 utils/init.py 以导出新的验证器以及现有的实用程序
astrbot/cli/utils/valutils.py
astrbot/cli/utils/__init__.py
添加 CLI 包结构文档
  • 在 cli/ 下添加了 README.MD,以解释文件夹组织、导入约定和安装技巧
astrbot/cli/README.MD

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从审查评论创建一个 issue。您也可以回复审查评论并使用 @sourcery-ai issue 从中创建一个 issue。
  • 生成 pull request 标题: 在 pull request 标题中的任何位置写入 @sourcery-ai 以随时生成标题。您也可以在 pull request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中的任何位置写入 @sourcery-ai summary 以随时在您想要的位置生成 PR 摘要。您也可以在 pull request 上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审查者指南: 在 pull request 上评论 @sourcery-ai guide 以随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
  • 驳回所有 Sourcery 审查: 在 pull request 上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 @sourcery-ai review 以触发新的审查!

自定义您的体验

访问您的 dashboard 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

```
Original review guide in English

Reviewer's Guide

This PR restructures the CLI package by centralizing command registration in the root module, modularizing conf and plug subcommand groups into standalone files, enhancing utility exports with validation helpers, fixing import paths, and adding a README to document the new structure.

Flow Diagram: Updated CLI Command Structure

graph TD
    A[astrbot cli] --> help_cmd("help [command_name]")
    A --> init_cmd("init")
    A --> run_cmd("run [--reload] [--port]")
    A --> conf_group("conf")
    A --> plug_group("plug")

    conf_group --> conf_set("set <key> <value>")
    conf_group --> conf_get("get [key]")

    plug_group --> plug_new("new <name>")
    plug_group --> plug_list("list [--all]")
    plug_group --> plug_install("install <name> [--proxy]")
    plug_group --> plug_update("update [name] [--proxy]")
    plug_group --> plug_remove("remove <name>")
    plug_group --> plug_search("search <query>")
Loading

File-Level Changes

Change Details Files
Refactor root CLI for group-based command registration and import cleanup
  • Replaced multiple relative imports with absolute imports in main.py
  • Switched help command decorator from @click.command to @cli.command
  • Moved init and run commands out of commands/ into dedicated modules
  • Updated init.py to export cli group alongside version
  • Cleaned up old commands directory references
astrbot/cli/__main__.py
astrbot/cli/__init__.py
astrbot/cli/init.py
astrbot/cli/run.py
astrbot/cli/commands/*
Introduce conf subcommand group with standalone modules
  • Created conf/utils.py for config load/save and nested get/set
  • Added conf/set.py and conf/get.py for setting and retrieving config keys
  • Defined conf/main.py as click.command group and registered get/set
  • Exported conf group in conf/init.py
astrbot/cli/conf/utils.py
astrbot/cli/conf/set.py
astrbot/cli/conf/get.py
astrbot/cli/conf/__main__.py
astrbot/cli/conf/__init__.py
Introduce plug subcommand group with dedicated command files
  • Defined plug/main.py as click.group and registered subcommands
  • Added individual modules for new, list, install, update, remove, and search operations
  • Ensured each plugin command uses delayed relative imports for utility functions
astrbot/cli/plug/__main__.py
astrbot/cli/plug/__init__.py
astrbot/cli/plug/new.py
astrbot/cli/plug/list.py
astrbot/cli/plug/install.py
astrbot/cli/plug/update.py
astrbot/cli/plug/remove.py
astrbot/cli/plug/search.py
Enhance CLI utilities with validation helpers
  • Created valutils.py with several validate_* functions for port, log level, timezone, etc.
  • Updated utils/init.py to export new validators alongside existing utilities
astrbot/cli/utils/valutils.py
astrbot/cli/utils/__init__.py
Add documentation for CLI package structure
  • Added README.MD under cli/ to explain folder organization, import conventions and installation tips
astrbot/cli/README.MD

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LIghtJUNction - 我已经审查了你的更改,并发现了一些需要解决的问题。

阻塞问题:

  • 导入不存在的 CONFIG_VALIDATORS 将导致命令中断 (link)

一般评论:

  • astrbot.cli.plug.list 中的 list 命令隐藏了内置的 list 名称——考虑重命名它(例如 list_plugins)以避免混淆。
  • conf/get.py 中,你从 utils 导入 CONFIG_VALIDATORS,但它只在 conf/set.py 中定义——将该映射提取到一个共享模块中,以便 get 和 set 都可以一致地引用它。
  • PR 在同一模块中混合了绝对导入和相对导入——选择一种样式(对于包内导入,首选相对导入)并始终如一地应用它,以提高可读性。
以下是我在审查期间查看的内容
  • 🔴 一般问题:1 个阻塞问题,1 个其他问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟡 复杂性:发现 1 个问题
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @LIghtJUNction - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Importing non-existent CONFIG_VALIDATORS will break command (link)

General comments:

  • The list command in astrbot.cli.plug.list shadows the built-in list name—consider renaming it (e.g. list_plugins) to avoid confusion.
  • In conf/get.py you import CONFIG_VALIDATORS from utils but it’s only defined in conf/set.py—extract that mapping into a shared module so both get and set can reference it consistently.
  • The PR mixes absolute and relative imports within the same modules—pick one style (prefer relative for intra‐package imports) and apply it consistently to improve readability.
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 1 other issue
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

validate_callback_api_base,
)
# 可通过CLI设置的配置项,配置键到验证器函数的映射
CONFIG_VALIDATORS: dict[str, Callable[[str], Any]] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): 考虑将 CONFIG_VALIDATORS 移动到模块级别,并简化 set_config 函数,以提高效率和清晰度。

Suggested change
CONFIG_VALIDATORS: dict[str, Callable[[str], Any]] = {
# 将 CONFIG_VALIDATORS 移动到模块级别,这样它就不会在每次调用时重建
# config/commands/set.py
from typing import Callable, Any
import click
from .utils import load_config, save_config
from ..utils import (
validate_timezone,
validate_log_level,
validate_dashboard_port,
validate_dashboard_username,
validate_dashboard_password,
validate_callback_api_base,
)
CONFIG_VALIDATORS: dict[str, Callable[[str], Any]] = {
"timezone": validate_timezone,
"log_level": validate_log_level,
"dashboard.port": validate_dashboard_port,
"dashboard.username": validate_dashboard_username,
"dashboard.password": validate_dashboard_password,
"callback_api_base": validate_callback_api_base,
}
@click.command("set")
@click.argument("key")
@click.argument("value")
def set_config(key: str, value: str):
if key not in CONFIG_VALIDATORS:
raise click.ClickException(f"不支持的配置项: {key}")
# 1) 尽早且单独验证
try:
validated = CONFIG_VALIDATORS[key](value)
except Exception as e:
raise click.UsageError(f"验证失败: {e}")
# 2) 加载和更新配置,使用简单的扁平/点状逻辑
config = load_config()
parts = key.split(".", 1)
if len(parts) == 2:
section, field = parts
old = config.get(section, {}).get(field)
config.setdefault(section, {})[field] = validated
else:
old = config.get(key)
config[key] = validated
# 3) 保存并报告
save_config(config)
click.echo(f"配置已更新: {key}")
if key == "dashboard.password":
click.echo(" 原值: ********")
click.echo(" 新值: ********")
else:
click.echo(f" 原值: {old}")
click.echo(f" 新值: {validated}")
Original comment in English

issue (complexity): Consider moving CONFIG_VALIDATORS to the module level and simplifying the set_config function for better efficiency and clarity.

Suggested change
CONFIG_VALIDATORS: dict[str, Callable[[str], Any]] = {
# Move CONFIG_VALIDATORS to module‐level so it's not rebuilt on every call
# config/commands/set.py
from typing import Callable, Any
import click
from .utils import load_config, save_config
from ..utils import (
validate_timezone,
validate_log_level,
validate_dashboard_port,
validate_dashboard_username,
validate_dashboard_password,
validate_callback_api_base,
)
CONFIG_VALIDATORS: dict[str, Callable[[str], Any]] = {
"timezone": validate_timezone,
"log_level": validate_log_level,
"dashboard.port": validate_dashboard_port,
"dashboard.username": validate_dashboard_username,
"dashboard.password": validate_dashboard_password,
"callback_api_base": validate_callback_api_base,
}
@click.command("set")
@click.argument("key")
@click.argument("value")
def set_config(key: str, value: str):
if key not in CONFIG_VALIDATORS:
raise click.ClickException(f"不支持的配置项: {key}")
# 1) Validate early and separately
try:
validated = CONFIG_VALIDATORS[key](value)
except Exception as e:
raise click.UsageError(f"验证失败: {e}")
# 2) Load and update config with simple flat/dotted logic
config = load_config()
parts = key.split(".", 1)
if len(parts) == 2:
section, field = parts
old = config.get(section, {}).get(field)
config.setdefault(section, {})[field] = validated
else:
old = config.get(key)
config[key] = validated
# 3) Save and report
save_config(config)
click.echo(f"配置已更新: {key}")
if key == "dashboard.password":
click.echo(" 原值: ********")
click.echo(" 新值: ********")
else:
click.echo(f" 原值: {old}")
click.echo(f" 新值: {validated}")

Comment on lines 14 to 22
try:
value = get_nested_item(config, key)
if key == "dashboard.password":
value = "********"
click.echo(f"{key}: {value}")
except KeyError:
raise click.ClickException(f"未知的配置项: {key}")
except Exception as e:
raise click.UsageError(f"获取配置失败: {str(e)}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): 从先前的错误显式引发 [×2] (raise-from-previous-error)

Original comment in English

issue (code-quality): Explicitly raise from a previous error [×2] (raise-from-previous-error)


config = load_config()

try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): 从先前的错误显式引发 [×2] (raise-from-previous-error)

Original comment in English

issue (code-quality): Explicitly raise from a previous error [×2] (raise-from-previous-error)

shutil.rmtree(plugin_path)
click.echo(f"插件 {name} 已卸载")
except Exception as e:
raise click.ClickException(f"卸载插件 {name} 失败: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): 显式地从先前的错误中引发 (raise-from-previous-error)

Suggested change
raise click.ClickException(f"卸载插件 {name} 失败: {e}")
raise click.ClickException(f"卸载插件 {name} 失败: {e}") from e
Original comment in English

suggestion (code-quality): Explicitly raise from a previous error (raise-from-previous-error)

Suggested change
raise click.ClickException(f"卸载插件 {name} 失败: {e}")
raise click.ClickException(f"卸载插件 {name} 失败: {e}") from e

Comment on lines 15 to 25
plugin = next(
(
p
for p in plugins
if p["name"] == name and p["status"] == PluginStatus.NEED_UPDATE
),
None,
)

if not plugin:
raise click.ClickException(f"插件 {name} 不需要更新或无法更新")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): 我们发现了这些问题:

Original comment in English

issue (code-quality): We've found these issues:

Comment on lines +8 to +11
if value not in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:
raise click.ClickException(
"日志级别必须是 DEBUG/INFO/WARNING/ERROR/CRITICAL 之一"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): 我们发现了这些问题:

Original comment in English

issue (code-quality): We've found these issues:

Comment on lines +22 to +23
except ValueError:
raise click.ClickException("端口必须是数字")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): 显式地从先前的错误中引发 (raise-from-previous-error)

Suggested change
except ValueError:
raise click.ClickException("端口必须是数字")
except ValueError as e:
raise click.ClickException("端口必须是数字") from e
Original comment in English

suggestion (code-quality): Explicitly raise from a previous error (raise-from-previous-error)

Suggested change
except ValueError:
raise click.ClickException("端口必须是数字")
except ValueError as e:
raise click.ClickException("端口必须是数字") from e

@LIghtJUNction LIghtJUNction changed the title 让CLI组织结构更整洁 让CLI组织结构更整洁+来点颜色+子命令组功能增强! May 31, 2025
@LIghtJUNction
Copy link
Contributor Author

修改完毕

@Soulter Soulter requested a review from Raven95676 June 4, 2025 14:23
Copy link
Member

@Raven95676 Raven95676 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.不建议占用~/.astrbot

2.init不建议提供指定root目录的选项,仅允许初始化当前目录为root目录即可,比较符合直觉

3.部分插件及部分逻辑依赖data.plugins这一导入路径,所有插件命令建议统一指向<ASTRBOT_ROOT>/data/<folder>

Comment on lines 3 to 14
@click.group(invoke_without_command=True)
@click.option("--timezone","-tz", default="Asia/Shanghai", help="设置时区,默认 Asia/Shanghai")
@click.option("--log-level", "-l", default="INFO", help="设置日志级别,默认 INFO")
@click.option("--dashboard-port", "-dp", default=8080, help="设置仪表盘端口,默认 8080")
@click.option("--dashboard-username", "-du", default="admin", help="设置仪表盘用户名,默认 admin")
@click.option("--dashboard-password", "-dpw", default="admin", help="设置仪表盘密码,默认 admin")
@click.option("--callback-api-base", "-cab", default="http://localhost:5000", help="设置回调 API 基础 URL,默认 http://localhost:5000")
@click.pass_context
def conf(ctx, timezone: str, log_level: str, dashboard_port: int, dashboard_username: str, dashboard_password: str, callback_api_base: str):
"""配置管理子命令组"""
if ctx.invoked_subcommand is None:
# 检查是否有参数被设置为非默认值
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议占用过多选项

Comment on lines 13 to 15
@click.option("--force", "-f", is_flag=True, help="强制设置,跳过验证器")
@click.option("--create", "-c", is_flag=True, help="如果键不存在则创建")
def set_config(key: str, value: str, type: str, force: bool, create: bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议提供强制设置的选项,当前无需提供--create flag

def validate_log_level(value: str) -> str:
"""验证日志级别"""
value = value.upper()
if value not in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里建议用集合

Comment on lines 32 to 36
import toml

with open(dot_astrbot,"w") as f:
toml.dump(metadata,f)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉没必要为了这个新增一个toml依赖,用yaml/json就可以

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@Raven95676
Copy link
Member

我不想使用cwd主要是方便随处启动。避免到处初始化

个人感觉让用户在这里指定路径不如让用户cd过去(

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@Raven95676
Copy link
Member

后面导入会很耗费时间的,启动CLI可能都会要接近1秒种。 现在启动就有一种很明显的顿挫感。解决办法最快捷的应该就是延迟导入了。

我并没有反对延迟导入

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@Raven95676
Copy link
Member

但是设置好环境变量就不用管了啊

@click.option("--root","-r",envvar="ASTRBOT_ROOT",required=True ,help="astrbot根目录,--root cwd表示使用当前目录",default=Path.home() / ".astrbot" )

从直觉上来说,init命令应该作用于当前目录而非其他目录

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

@Raven95676
Copy link
Member

站在用户角度,用户使用uv tool install astrbot,并且每次打开系统终端时 默认就是在$HOME 也就是 / 那么用户大概率就是在/初始化目录的,并不像我们开发者一样是源代码仓库内。 这就是为什么我不想设置为当前目录为根目录。 第二个原因就是,linux很多软件都是这个习惯,并不是我特意选这个目录,而是说这是一种习惯性的行为。 打开HOME目录,你可以看到很多软件都是类似的做法。 我个人觉得,~/.astrot可以仅存放一些元数据,大数据文件可以选择放到其他地方。

image

@LIghtJUNction
Copy link
Contributor Author

图片
初始化改回cwd
图片
不使用toml
图片
图片
图片
图片
改回/data/
图片
图片
移除这些option
直接回溯到改动之前

@LIghtJUNction
Copy link
Contributor Author

LIghtJUNction commented Jun 9, 2025 via email

LIghtJUNction and others added 6 commits June 9, 2025 21:45
Enhanced the README files (Chinese, English, Japanese) with updated installation instructions, including uv-based and one-click install methods, and improved deployment documentation. Added new badges, updated community links, and expanded feature and update sections to reflect recent changes such as built-in knowledge base, MCP server support, and upcoming features. Reformatted tables and improved clarity and consistency across all language versions.
@LIghtJUNction
Copy link
Contributor Author

本地同步上游更新,解决合并冲突问题

Bumped chardet to 5.2.0 and pydantic to 2.11.7 in pyproject.toml. Added a wildcard for '*.lock' files to .gitignore for broader lock file exclusion.
@LIghtJUNction LIghtJUNction requested a review from Raven95676 June 18, 2025 14:51
@LIghtJUNction
Copy link
Contributor Author

总结:
本地同步了上游
解决了冲突
用uv 导出
好处如下:
最高级别的安全性:防止供应链攻击 完全可重现 因为uv自动补充了hash值
之后安装时会对比hash值
pyproject.toml依赖版本升级

更新了README.MD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants