Skip to main content

简单的统一配置管理工具

Project description

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
    • 若都不存在,自动使用 ./.yucebioconfig/{name or config}.json5 作为配置文件
  • 配置管理

USAGE

  1. 加载配置
# 自动加载已有或默认配置
from yucebio_config import config
# 主动加载已有或默认配置
from yucebio_config import Config
config = Config()

# 加载指定名称的配置文件
config = Config('name')
  1. 更新配置内容
config['new_key'] = 'value'
config.save()                   # 保存,不重新加载

config.reload()                 # 保存并重新加载
  1. 重置配置内容
config['tmp_key'] = 'value'     # 临时生效
config.reset()                  # 重新读取配置内容
  1. 清除配置
config.clear('special_key')     # 清除指定key内容
config.clear()                  # 清除所有配置内容

config.clear('super/sub', sep='/')  # 清除嵌套内容
  1. 获取和打印配置内容
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配置文件

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Yucebio_Config-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file Yucebio_Config-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: Yucebio_Config-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for Yucebio_Config-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ffd7bc6ccfc4fe102c35afdce250372336ff52ec86cbb0291f7890213f8f180
MD5 fbe9b93b572e57bb0b3708fb3413d764
BLAKE2b-256 bbba523fa38c864464fa078a3a7fe317db721ed20f14af54a718d2e4b84d4b6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page