在首次安装时创建并填充应用程序的配置。
figg的Python项目详细描述
在首次安装时创建并填充应用程序的配置。
你是否厌倦了编写超级棒的软件包或应用程序 但是,除非你的最终用户仔细阅读你的自述以获得指导,否则不要工作。 如何构造配置文件以及如何在何处实例化它们?
figgy允许您发送代码并安装最终用户开发人员 通过运行你的应用程序或包来配置它。你可以叫它 从setup.py或将其绑定到代码中您喜欢的任何内容,以便 新配置的结果将立即提供给 无论应用程序或包将在什么上下文中使用。
警告
这个软件正在开发中。也就是说,这个包裹应该 工作。请报告错误。
关键注意事项: -将配置数据以 案例。 -只支持json。 -仅适用于Python3。 -您希望此模块从tty提示。 -你是在一个“尼克斯系统”。
它们旨在指导未来版本的特性开发,但是 在这种情况下,它应该是有用的。
安装
pip install figgy
用法
第一次导入figgy
import figgy
然后定义配置模板
template = { 'username': 'default', 'password': 'anotherdefault' }
您只需调用make()。
figgy.make(template)
系统将提示最终用户:
Enter value for "username" (return for default "default")': ▋userinput Enter value for "username" (return for default "default")': Set "username" to "userinput" in ./config.json Enter value for "password" (return for default "anotherdefault")': ▋anotheruserinput Enter value for "password" (return for default "anotherdefault")': Set "password" to "anotheruserinput" in ./config.json
并生成一个config.json文件:
{"username": "userinput", "password": "anotheruserinput"}
如果希望在创建应用程序后在其中使用数据 使用
config = figgy.make(template)
以便您可以像这样访问数据
username = config['username'] password = config['password']
默认情况下,figgy假设以下几点:
- 您希望文件名为config.json
- 您希望在执行python代码的路径生成文件 它从
- 您希望函数返回配置数据
- 用户界面为tty
但你可以改变大部分:
源代码:
template = { 'PORT': '3000', 'DEBUG': 'True' } figgy.make(data=template, filename='appconfig')
提示:
Enter value for "PORT" (return for default "3000")': ▋8080 Set "PORT" to "8080" in ./appconfig.json Enter value for "DEBUG" (return for default "True")': ▋False
返回:
Set "DEBUG" to "False" in ./appconfig.json {'./appconfig.json': {'PORT': '3000', 'DEBUG': 'True'}}
源代码:
figgy.make(data=template, get=False)
生成提示:
Enter value for "username" (return for default "default")': ▋userinput Set "username" to "userinput" in ./config.json Enter value for "password" (return for default "anotherdefault")': ▋anotheruserinput Set "password" to "anotheruserinput" in ./config.json
返回:
None
贡献
- 分叉源存储库https://github.com/dyspop/figgy
- 创建新分支
- 编写功能部件代码
- 确保添加了一些测试
- 提交一个请求,其中包含有关您的功能和测试的有用注释