Skip to content

feat: 添加部分环境变量以支持方便快捷获取data目录以及插件数据目录。 #1485

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 2 commits into
base: master
Choose a base branch
from

Conversation

teywat
Copy link
Collaborator

@teywat teywat commented May 28, 2025

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

Sourcery 总结

引入环境变量以实现灵活的数据和插件目录解析,并更新配置加载器以使用新的 DATA_PATH。

新特性:

  • 添加 DATA_PATH 环境变量以配置根数据目录,默认为 $PWD/data
  • 添加基于 DATA_PATH 的 PLUGIN_PATH,以便按照约定定位插件文件

增强功能:

  • 重构配置加载器以使用新的 DATA_PATH 变量解析 config.yaml 路径
Original summary in English

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

Sourcery 总结

引入 DATA_PATH 和 PLUGIN_PATH 环境变量,以便灵活地定位数据和插件目录,并更新配置加载器以使用 DATA_PATH 加载 config.yaml。

新特性:

  • 添加 DATA_PATH 环境变量,用于指定根数据目录,默认为 $PWD/data。
  • 添加基于 DATA_PATH 的 PLUGIN_PATH 变量,用于定位插件文件。

增强功能:

  • 重构配置加载器,以使用 DATA_PATH 解析 config.yaml 路径。
Original summary in English

Summary by Sourcery

Introduce DATA_PATH and PLUGIN_PATH environment variables to flexibly locate the data and plugin directories, and update the config loader to use DATA_PATH for loading config.yaml.

New Features:

  • Add DATA_PATH environment variable for root data directory, defaulting to $PWD/data.
  • Add PLUGIN_PATH variable based on DATA_PATH to locate plugin files.

Enhancements:

  • Refactor config loader to resolve config.yaml path using DATA_PATH.

Copy link
Contributor

sourcery-ai bot commented May 28, 2025

## 审查者指南

引入环境变量 (DATA_PATH 和 PLUGIN_PATH) 以实现灵活的数据和插件目录解析,并重构配置加载器以使用 DATA_PATH 而不是硬编码路径来查找配置文件。

#### 配置文件路径解析的序列图

```mermaid
sequenceDiagram
    participant CL as ConfigLoader
    participant OS as OperatingSystem
    participant FS as FileSystem

    activate CL
    CL->>OS: Get DATA_PATH environment variable
    activate OS
    OS-->>CL: DATA_PATH value (e.g., "$PWD/data")
    deactivate OS

    CL->>OS: Construct path: os.path.join(DATA_PATH, "config.yaml")
    activate OS
    OS-->>CL: CONFIG_FILE path (e.g., "$PWD/data/config.yaml")
    deactivate OS

    CL->>FS: Read CONFIG_FILE from constructed path
    activate FS
    FS-->>CL: Configuration data
    deactivate FS
    deactivate CL

类图:配置模块更新

classDiagram
    class `kirara_ai.config` {
        <<Module>>
        +DATA_PATH: string
        +PLUGIN_PATH: string
    }

    class `kirara_ai.config.config_loader` {
        <<Module>>
        ~CONFIG_FILE: string
    }

    `kirara_ai.config.config_loader` ..> `kirara_ai.config` : uses DATA_PATH
Loading

文件级别变更

Change Details Files
定义并初始化 DATA_PATH 和 PLUGIN_PATH 以实现可配置的目录路径
  • 从环境变量读取 DATA_PATH,或者默认为 $PWD/data
  • 定义 PLUGIN_PATH 作为 DATA_PATH 的子目录
kirara_ai/config/__init__.py
重构配置加载器以使用 DATA_PATH
  • 将 DATA_PATH 导入到 config_loader
  • 将硬编码的配置路径替换为 os.path.join(DATA_PATH, "config.yaml")
kirara_ai/config/config_loader.py

提示和命令

与 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 以触发新的审查!

自定义您的体验

访问您的 仪表板 以:

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

获取帮助

```
Original review guide in English

Reviewer's Guide

Introduce environment variables (DATA_PATH and PLUGIN_PATH) for flexible data and plugin directory resolution and refactor the configuration loader to use DATA_PATH instead of a hardcoded path for config files.

Sequence Diagram for Configuration File Path Resolution

sequenceDiagram
    participant CL as ConfigLoader
    participant OS as OperatingSystem
    participant FS as FileSystem

    activate CL
    CL->>OS: Get DATA_PATH environment variable
    activate OS
    OS-->>CL: DATA_PATH value (e.g., "$PWD/data")
    deactivate OS

    CL->>OS: Construct path: os.path.join(DATA_PATH, "config.yaml")
    activate OS
    OS-->>CL: CONFIG_FILE path (e.g., "$PWD/data/config.yaml")
    deactivate OS

    CL->>FS: Read CONFIG_FILE from constructed path
    activate FS
    FS-->>CL: Configuration data
    deactivate FS
    deactivate CL
Loading

Class Diagram: Configuration Module Updates

classDiagram
    class `kirara_ai.config` {
        <<Module>>
        +DATA_PATH: string
        +PLUGIN_PATH: string
    }

    class `kirara_ai.config.config_loader` {
        <<Module>>
        ~CONFIG_FILE: string
    }

    `kirara_ai.config.config_loader` ..> `kirara_ai.config` : uses DATA_PATH
Loading

File-Level Changes

Change Details Files
Define and initialize DATA_PATH and PLUGIN_PATH for configurable directory paths
  • Read DATA_PATH from environment or default to $PWD/data
  • Define PLUGIN_PATH as a subdirectory of DATA_PATH
kirara_ai/config/__init__.py
Refactor configuration loader to use DATA_PATH
  • Import DATA_PATH into config_loader
  • Replace hardcoded config path with os.path.join(DATA_PATH, "config.yaml")
kirara_ai/config/config_loader.py

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

github-actions bot commented May 28, 2025

MyPy 类型检查通过 ✅

PR 修改的代码行通过了类型检查。

@teywat teywat marked this pull request as ready for review May 28, 2025 09:23
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.

@teywat - 我已经审查了你的更改 - 这里有一些反馈:

  • config_loader.py 使用了 os.path.join,但从未导入 os - 添加缺失的导入以避免运行时错误。
  • 考虑在启动时验证或自动创建 DATA_PATH 和 PLUGIN_PATH,以防止“找不到目录”问题。
  • 规范化 DATA_PATH 和 PLUGIN_PATH(例如,通过 os.path.expanduser 和 abspath)以正确处理相对路径或 ~ 扩展。
以下是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

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

Hey @teywat - I've reviewed your changes - here's some feedback:

  • config_loader.py uses os.path.join but never imports os—add the missing import to avoid runtime errors.
  • Consider validating or auto-creating DATA_PATH and PLUGIN_PATH at startup to prevent “directory not found” issues.
  • Normalize DATA_PATH and PLUGIN_PATH (e.g. via os.path.expanduser and abspath) to handle relative paths or ~ expansions correctly.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 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.

@teywat
Copy link
Collaborator Author

teywat commented May 28, 2025

需要添加创建目录的功能吗?

refactor: 重写了DATA_PATH部分。考虑到用户编写的DATA_PATH 可能使用相对路径,增加了绝对路径转换,避免未知bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant