一个强大的配置管理工具集
Project description
一个更加用户友好的配置插件(工具集),目前只适合开发者使用,后续我会开发一个自动读取所有插件可配置项并自动导出
(通过官方读取的实现方式序列化导出)
该项目改装自 localstore
📖 行为介绍
此插件会根据你的 nb_cli 位置获得工作目录 WORKSPACE,随后使用WORKSPACE该字段
拼接出 config data cache 目录到工作目录下。
💿 安装
使用 nb-cli 安装
在 nonebot2 项目的根目录下打开命令行, 输入以下指令即可安装nb plugin install nonebot-plugin-humanaticstore
使用包管理器安装
在 nonebot2 项目的插件目录下, 打开命令行, 根据你使用的包管理器, 输入相应的安装命令pip
pip install nonebot-plugin-humanaticstore
pdm
pdm add nonebot-plugin-humanaticstore
poetry
poetry add nonebot-plugin-humanaticstore
conda
conda install nonebot-plugin-humanaticstore
打开 nonebot2 项目根目录下的 pyproject.toml 文件, 在 [tool.nonebot] 部分追加写入
plugins = ["nonebot_plugin_humanaticstore"]
⚙️ 这么做的目的
更易于多个nonebot在同一个计算机或设备下,使用多种不同的配置,甚至你可以使用localstore 插件和本插件同时工作,由于本插件遵循面对对象的工作原则,只有实例化对象并使用对象和其他数据交互才有可能出现bug。
🎉 使开发者如何使用
首先,导入本包 import nonebot_plugin_humanaticstore
运行中导入时会自动获取nb_cli运行目录,
然后你就可以使用
BASE_CACHE_DIR
BASE_DATA_DIR
BASE_CONFIG_DIR
字段直接获取数据目录的 绝对路径
编写配置可以直接使用python对象-字典;
通过导入
from nonebot_plugin_humanaticstore import ConfigManger
先获取配置管理对象,
对象内也拥有基础路径字段可提供使用,
对象内常用方法
-
get_config/data/cache_file/dirfile 方法中需要 文件名参数 需要后缀 -
model_dump导出这个类中设置的所有字段,以python字典的形式导出 -
save_config参数:文件名不需要后缀,强制为yaml格式;data形如 model_dump 的字典格式
将 data 存入 文件中 -
load_config_yaml参数文件名不需要后缀 强制为 yaml ;
读取文件中的配置 返回 python字典对象 -
parse_obj参数 字典
用于更新对象中的字段
标准用法放入解包的原始对象字典,再放入解包的新对象 ->
{**config_manger.dict(), **new_data} 建议先处理重复字段
# 自定义更新逻辑的示例
for key, value in new_data.items():
if hasattr(config, key):
# 如果需要特殊处理重复字段,可以在这里实现
# 例如,合并列表,选择保留原始值等
pass
else:
# 如果字段不在原始配置中,直接设置新值
setattr(config, key, value)
后话
如果各位有需要想实现的功能,可以咨询我
邮箱: 1624910218@qq.com 只是做成了链接样式点不了的
效果图
如果有效果图的话
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_humanaticstore-0.1.2.tar.gz.
File metadata
- Download URL: nonebot_plugin_humanaticstore-0.1.2.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b80b1d107bb83290eebe825d357c712cb767471ed0b85fb9d0f759af46201a1d
|
|
| MD5 |
3426c53fbade6e760f957e7645d46190
|
|
| BLAKE2b-256 |
bfbf9b04bd7178aa6ec1eaaf85e3b5ac2a7cb077edb837dbf3d512e49e8ffaff
|
File details
Details for the file nonebot_plugin_humanaticstore-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_humanaticstore-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a72ef57dac4f5d8d8964a5b3f075d5b61f097b14946b582f1f484eef9612528
|
|
| MD5 |
29197cce54976e5b5b898addd6b9f765
|
|
| BLAKE2b-256 |
e323b2208a5ffcdbb5b13ae68a39ed15e630411ef06133bf2aa6dad634bcbc81
|