通用异步服务加载程序和依赖注入程序

buvar的Python项目详细描述


插件机制

我想要一个类似于Pyramidaproach的插件机制。它应该 提供生成要运行的任意任务的方法,其中每个生命周期阶段 应该交给开发人员控制。

引导程序如下:

frombuvarimportplugin,componentsplugin.run("some.module.with.plugin.function")
# some.module.with.plugin.functionfrombuvarimportcontext# you may omit include in argumentsasyncdefplugin(include):awaitinclude('.another.plugin')# create some long lasting componentsmy_component=context.add("some value")asyncdeftask():asyncio.sleep(1)asyncdefserver():awaitasyncio.Future()# you may run simple tasksyieldtask()# you may run server tasksyieldserver()

组件和依赖注入解决方案

我想要一些有用的东西来储存一些长期的帮助我 商业问题。我想要一个不冗长的查找。

frombuvarimportdiclassBar:passclassFoo:def__init__(self,bar:Bar=None):self.bar=bar@di.adapter_classmethodasyncdefadapt(cls,baz:str)->Foo:returnFoo()@di.adapterasyncdefadapt(bar:Bar)->Foofoo=Foo(bar)returnfooasyncdeftask():foo=awaitdi.nject(Foo,baz="baz")assertfoo.barisNonebar=Bar()foo=awaitdi.nject(Foo,bar=bar)assertfoo.barisbar

配置源

我想要一个配置源,它自动应用环境 变量设置为默认值。

配置toml

log_level="DEBUG"show_warnings="yes"[foobar]some="value"
exportAPP_FOOBAR_SOME=thing
importattrimporttomlfrombuvarimportconfig@attr.s(auto_attribs=True)classGeneralConfig:log_level:str="INFO"show_warnings:bool=config.bool_var(False)@attr.s(auto_attribs=True)classFoobarConfig:some:strsource=config.ConfigSource(toml.load('config.toml'),env_prefix="APP")general_config=source.load(GeneralConfig)assertgeneral_config==GeneralConfig(log_level="DEBUG",show_warnings=True)foobar_config=source.load(FoobarConfig,'foobar')assertfoobar_config.some=="thing"

结构日志

我想在我的终端中有一个漂亮且可读的structlog和一个json登录 生产。

importsysfrombuvarimportloglog.setup_logging(sys.stdout.isatty(),general_config.log_level)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用唯一的按钮标签单击按钮   代码生成如何使用Java codeModel为数组的特定索引赋值   java如何批量执行Camel SQL插入   java iText 7将ltv添加到现有签名   内存管理Java应用程序突然停止几天后(810)   带MySQL的java注册表单JavaFX在intellij中失败   如何使用eclipse为windows azure java项目启用远程调试   一种通用的java输入输出设计模式   java Android XML(RSS)忽略引号(“”)   java帮助:安卓中的8 X 10 2维按钮数组   java启动Android项目   JWrapper构建java应用程序   java如何在Android应用程序中设置基于日期/时间的默认页面加载?   java循环程序在完成后返回到起点   java Hibernate:更好的整体类还是多类映射?   回溯数独解算器的递归问题[Java]   java查找类用法   java如何在SpringWebFlow中将多个模型绑定到一个视图?