-
-
Notifications
You must be signed in to change notification settings - Fork 647
Feature: 允许插件从环境变量中读取配置项并支持 alias #3673
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
Conversation
|
🚀 Deployed to https://deploy-preview-3673--nonebot2.netlify.app |
cb7a5aa to
f48d3a1
Compare
|
加载所有环境变量的意义是什么?为什么会有这个需求啊。。。插件就应该定义插件配置类通过 |
是为了不需要在 比如构建了一个Docker,里面安装了插件A,它有个配置
|
|
容器环境相对来说也比较可控,有这个配置确实会方便不少。不需要通过挂载 .env 文件来修改配置,也不需要每次添加新插件时都修改容器内的 .env 文件了,感觉确实是痛点。 |
|
如果是这种场景,我更倾向于修改 |
确实,很合理。 |
f48d3a1 to
8c8e865
Compare
8c8e865 to
80215b9
Compare
80215b9 to
6152704
Compare
|
现在插件会在get_plugin_config时从环境变量里查找配置项了 |
4793dd4 to
e5559d0
Compare
e5559d0 to
1093050
Compare
|
为什么不直接通过获取配置类的字段对应环境变量 dict 与 driver.config 直接 validate。dotenv file 里的配置已经加载到 driver.config 里了。 |
|
修改了亿点点 |
|
我理解这东西完全不需要修改 config source 吧,难道不是直接通过 |
不复用的话,插件 config fields 和 环境变量 之间的大小写敏感处理、配置项别名映射、嵌套字典解析到scope配置( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for plugins to read configuration from environment variables and supports field aliases. Previously, NoneBot wouldn't automatically read environment variables for plugin configurations unless declared in dotenv files. Now, get_plugin_config can directly read plugin configuration from environment variables following the same priority order as global configuration loading.
Key Changes:
- Modified
get_plugin_configto useBaseSettings._settings_build_valuesfor reading configuration from both global config and environment variables - Enhanced
DotEnvSettingsSourceto support pydantic field aliases with higher priority over regular field names - Refactored
BaseSettingsinitialization to store env file settings and made_settings_build_valuesa static method
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| nonebot/plugin/init.py | Updated get_plugin_config to read from environment variables using BaseSettings._settings_build_values |
| nonebot/config.py | Refactored settings sources to support aliases and made _settings_build_values static for reuse |
| tests/test_plugin/test_get.py | Added test cases for plugin config with environment variables and aliases |
| tests/test_config.py | Added test for aliased field in base config |
| tests/.env.example | Added example aliased environment variable |
| website/docs/appendices/config.mdx | Updated documentation to clarify plugin config loading behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
like
PLUGIN_CONFIG_A=true nb run