python entry points 例子
pbr的介绍不多,http://ju.outofmemory.cn/entry/156745
$ mkdir entry_test; cd entry_test; git init
$ mkdir -p mypackage/api/v1/
$ touch mypackage/__init__.py; touch mypackage/api/__init__.py; touch mypackage/api/v1/__init__.py;
$ tree mypackage
.
├── mypackage
│ ├── api
│ │ ├── __init__.py
│ │ └── v1
│ │ ├── databases.py
│ │ ├── hello.py
│ │ ├── __init__.py
│ ├── __init__.py
├── setup.cfg
└── setup.py
$ cat mypackage/api/v1/databases.py
def main():
print "this is databases main"
$ cat mypackage/api/v1/hello.py
def main():
print "this is hello main"
$ cat setup.cfg
[metadata]
name = mypackage
version = 12.0.0
summary = Cloud computing fabric controller [files]
packages =
mypackage [entry_points]
mypackage.api.v1 =
databases = mypackage.api.v1.databases:main
hello = mypackage.api.v1.hello:main [wheel]
universal = 1 [pbr]
autodoc_index_modules = 0
warnerrors = true
$ cat setup.py
import setuptools # In python < 2.7.4, a lazy loading of package `pbr` will break
# setuptools if some other modules registered functions in `atexit`.
# solution from: http://bugs.python.org/issue15881#msg170215 setuptools.setup(
name='mypackage',
packages=['mypackage'],
package_dir={'mypackage': 'mypackage'},
setup_requires=['pbr'],
pbr=True,
entry_points={
'mypackage.api.v1':[
'databases=mypackage.api.v1.databases:main',
'hello=mypackage.api.v1.hello:main',
],
}
)
调用方法1:
令贤的blog介绍 stevedore: http://blog.csdn.net/lynn_kong/article/details/9704413
opensatck 社区介绍stevedore http://docs.openstack.org/developer/stevedore/tutorial/index.html
教程: https://github.com/openstack/stevedore/tree/master/doc/source/tutorial
from stevedore import extension def test_detect_plugins():
em = extension.ExtensionManager('mypackage.api.v1')
names = sorted(em.names())
print names
em1 = extension.ExtensionManager('mypackage.api.v1')
eps1 = [ext.plugin for ext in em1] #plugin是被映射的函数,用于调用
em1 = extension.ExtensionManager('mypackage.api.v1')
eps1 = [ext.entry_point for ext in em1]
调用方法2:
import pkg_resources def run_entry_point(*argv):
group = 'mypackage.api.v1'
for entrypoint in pkg_resources.iter_entry_points(group=group):
# Grab the function that is the actual plugin.
plugin = entrypoint.load()
print plugin
type(plugin)
plugin(*argv)
调用方法3:
from pkg_resources import load_entry_point
load_entry_point('mypackage', 'mypackage.api.v1', 'database')()
在我的test 例子中需要导入pbr 才能工作,否则有些源代码打包不了。
http://blog.oddbit.com/2014/09/27/integrating-custom-code-with-n/
https://github.com/larsks/demo_nova_hooks
没有导入pbr, 也可以, 需要研究。
python entry points 例子的更多相关文章
- Scene is unreachable due to lack of entry points and does not have an identifier for runtime access
使用Storyboard时出现以下警告: warning: Unsupported Configuration: Scene is unreachable due to lack of entry p ...
- python多线程简单例子
python多线程简单例子 作者:vpoet mail:vpoet_sir@163.com import thread def childthread(threadid): print "I ...
- Python 发邮件例子
Python 发邮件例子 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-04-23 16:12:33 # @Autho ...
- python gevent使用例子
python gevent使用例子 from gevent.pool import Pool POOL_SIZE = 100 def process(func, param1_list, param2 ...
- Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier解决办法
使用Storyboard时出现以下警告: warning: Unsupported Configuration: Scene is unreachable due to lack of entry p ...
- XCode warning:“View Controller” is unreachable because it has no entry points
Unsupported Configuration: “View Controller” is unreachable because it has no entry points, and no i ...
- Python random模块 例子
最近用到随机数,就查询资料总结了一下Python random模块(获取随机数)常用方法和使用例子. 1.random.random random.random()用于生成一个0到1的随机符点数: ...
- Python练手例子(11)
61.打印出杨辉三角形. #python3.7 from sys import stdout if __name__ == '__main__': a = [] for i in range(10): ...
- Python练手例子(10)
55.学习使用按位取反~. 程序分析:~0=1; ~1=0; (1)先使a右移4位. (2)设置一个低4位全为1,其余全为0的数.可用~(~0<<4) (3)将上面二者进行&运算. ...
随机推荐
- jQuery粘性跟随滚动条滚动的导航栏源代码下载
jQuery粘性跟随滚动条滚动的导航栏源代码下载 作者:网页模板 大小:0.005MB 点击次数:3494 发布时间:2014-03-07 12:55 分享到:0 特效介绍 jQuery粘性跟随滚动条 ...
- 关于Char* ,CString ,WCHAR*之间的转换问题
GDI+所有类的接口函数如果要传递字符串作为参数的话,似乎都用UNICODE串,即WCHAR*.我开始也被整得晕头转向,因为窗口编程所用往往是CString,用IO流读文件数据又得到char *.得益 ...
- libiconv的静态编译
./configure --enable-static=yes --prefix=/usr/local/libiconv CentOS安装transmission » Nicky Blog 安装l ...
- AndroidUI 布局动画-点九PNG技术
下面是正常情况与使用点9切图以后的效果对比: <Button android:id="@+id/button1" android:layout_width="fil ...
- 调magento自定义模板发邮件
1. 设置邮件模板 <global> <template> <email> <custom_email_template1 module="Samp ...
- [转]Asp.Net MVC使用HtmlHelper渲染,并传递FormCollection参数的陷阱 【转】
在Asp.Net MVC 1.0编程中,我们经常遇见这样的场景,在新建一个对象时候,通过HtmlHelper的方式在View模型中渲染Html控件,当填写完相关内容后,通过Form把需要新建的内容Po ...
- Android创建启动画面[转]
每个Android应用启动之后都会出现一个Splash启动界面,显示产品的LOGO.公司的LOGO或者开发者信息.如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥 ...
- android_Intent对象初步(Activity传统的价值观念)
说明:初步Intent物.主要使用Intent对象在Activity之间传递数据的方法. 样例:由MainActivity→OtherActivity的跳转过程中,把数据传递给OtherActivit ...
- swift 用协议实现代理传值功能
1.功能简介 RootViewController中用个lable和一个按钮,点击按钮跳转到模态窗口.在模态窗口中有个TextField和一个按钮,输入文字点击关闭模态按钮后跳转到RootViewCo ...
- JavaScript 的DOM操作
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. Windows 对象操作 ...