Yucebio-Config 通用配置管理工具
- 自动加载和生成json格式的配置文件
- 首先检查当前目录是否存在config目录
- 检查是否存在 {
name}.json5, {name}.json 或 config.json5, config.json
- 检查是否存在 {
- 再次检查当前目录是否存在.yucebioconfig目录
- 检查是否存在 {
name}.json5, {name}.json 或 config.json5, config.json
- 检查是否存在 {
- 最后检查HOME目录是否存在.yucebioconfig目录
- 检查是否存在 {cur_work_dir_name|
name}.{json5|json} 文件 - 检查是否存在 {
name}.json5, {name}.json 或 {cur_work_dir_name}.json5, {cur_work_dir_name}.json
- 检查是否存在 {cur_work_dir_name|
- 若都不存在,自动使用 ./.yucebioconfig/{
nameor config}.json5 作为配置文件
- 首先检查当前目录是否存在config目录
- 配置管理
USAGE
- 加载配置
# 自动加载已有或默认配置
from yucebio_config import config
# 主动加载已有或默认配置
from yucebio_config import Config
config = Config()
# 加载指定名称的配置文件
config = Config('name')
- 更新配置内容
config['new_key'] = 'value'
config.save() # 保存,不重新加载
config.reload() # 保存并重新加载
- 重置配置内容
config['tmp_key'] = 'value' # 临时生效
config.reset() # 重新读取配置内容
- 清除配置
config.clear('special_key') # 清除指定key内容
config.clear() # 清除所有配置内容
config.clear('super/sub', sep='/') # 清除嵌套内容
- 获取和打印配置内容
config_data = config.config # 获取字典格式的配置内容
config_str = str(config) # 带缩进的json字符串形式的配置内容
print(config) # 打印带缩进的配置内容
属性
config = Config()
# 实际使用的配置文件路径
config.configpath
# 实际使用的配置文件
config.configfile
# 配置内容
config.config
配置查找和保存
首先按照以下顺序检查是否存在配置文件
- 检查当前目录是否存在config/{name}.{json5|json} 文件
- 检查当前目录是否存在.yucebioconfig/{name}.{json|json5} 文件
- 检查是否存在 ~/{name}.{json|json5}文件
若不存在则在当前目录创建配置文件
- 检查是否存在 config目录,若存在,创建 config/{name}.json5配置文件
- 否则,优先创建 .yucebioconfig/{name}.json5配置文件
Release files for Yucebio-Config 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Yucebio_Config-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / Yucebio_Config-0.1.0-py3-none-any.whl
| Download URL | Yucebio_Config-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ffd7bc6ccfc4fe102c35afdce250372336ff52ec86cbb0291f7890213f8f180
|
|
BLAKE2b-256 checksum How to use checksums |
bbba523fa38c864464fa078a3a7fe317db721ed20f14af54a718d2e4b84d4b6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4
|