建立在Python最小的插件架构 [英] Building a minimal plugin architecture in Python

查看:134
本文介绍了建立在Python最小的插件架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用Python编写的,它是通过使用一个相当技术性的观众(科学家)。

I have an application, written in Python, which is used by a fairly technical audience (scientists).

我在找一个很好的方式由用户进行应用扩展,即脚本/插件架构。

I'm looking for a good way to make the application extensible by the users, i.e. a scripting/plugin architecture.

我要寻找的东西极其轻便。最脚本或插件,都不会被开发和由第三方分发和安装,但将是一些由用户在几分钟后刮起自动重复任务,添加一个文件格式的支持,等于是插件应该有绝对的最低样板code,并且不需要安装除了复制到一个文件夹(所以像setuptools的入口点,或Zope的插件架构似乎太多了。)

I am looking for something extremely lightweight. Most scripts, or plugins, are not going to be developed and distributed by a third-party and installed, but are going to be something whipped up by a user in a few minutes to automate a repeating task, add support for a file format, etc. So plugins should have the absolute minimum boilerplate code, and require no 'installation' other than copying to a folder (so something like setuptools entry points, or the Zope plugin architecture seems like too much.)

是否有任何这样的系统已经在那里,或者实施类似的计划,我应该看看的想法的任何项目/灵感?

Are there any systems like this already out there, or any projects that implement a similar scheme that I should look at for ideas / inspiration?

推荐答案

我的是,基本上,一个叫做插件,它的主要应用程序可以轮询,然后使用的 imp.load_module 拿起文件,以及模块级的配置PARAMS寻找一个知名的切入点可能,并从那里走。我使用文件监视工具和一定量的活力在插件是积极的,但是这是一个不错的到了。

Mine is, basically, a directory called "plugins" which the main app can poll and then use imp.load_module to pick up files, look for a well-known entry point possibly with module-level config params, and go from there. I use file-monitoring stuff for a certain amount of dynamism in which plugins are active, but that's a nice-to-have.

当然,沿着说来的任何要求我不需要[大的,复杂的事情] X;我只是想要的东西轻量级的运行的重新实施点¯x1发现需求在一个时间的风险。但是,这并不是说你不能有一些有趣的做也无妨:)

Of course, any requirement that comes along saying "I don't need [big, complicated thing] X; I just want something lightweight" runs the risk of re-implementing X one discovered requirement at a time. But that's not to say you can't have some fun doing it anyway :)

这篇关于建立在Python最小的插件架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆