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)将上面二者进行&运算. ...
随机推荐
- box-shadow 给图片添加内部阴影
box-shadow 是css3中定义的设置元素阴影的属性,其语法结构如下: <shadow> = inset? && <length>{2,4} && ...
- Database.SetInitializer的几种参数
一:数据库不存在时重新创建数据库 Database.SetInitializer<testContext>(new CreateDatabaseIfNotExists<testCon ...
- JS中如何使用Cookie
1.关于JS设置Cookie的说明 在Javascript脚本里,一个cookie 实际就是一个字符串属性.当你读取cookie的值时,就得到一个字符串,里面当前WEB页使用的所有cookies的名称 ...
- js cookie读取
/**存放Cookies: 两个参数,一个是cookie的名子,一个是值*/ function SetCookie(name,value){ var Days = 30; //此 cookie 将被保 ...
- VS2008下WinRar源码生成dll和 lib总结
WinRar官方提供了源码(http://www.rarlab.com/rar_add.htm):如果自己想要修改里面的内容就要重新生成DLL和LIB,我在网上找了很多资料都没有说得很清楚.花一两天的 ...
- GetLastError来获得错误信息转成文本描述
我们一般在调用了一些API后都会用GetLastError来获得错误信息,但是信息都是Integer的,我们知道是什么意思么?嘿嘿,是的,有msdn呀,当然还可以用FormatMessage函数来.正 ...
- perl 继承写法
use base (Critter); 和 BEGIN{ require Critter; @ISA=qw/Critter/; } 这两种写法是等价
- app被Rejected 的各种原因翻译(转)
原文:http://www.cnblogs.com/sell/archive/2013/02/16/2913341.html 1. Terms and conditions(法律与条款) 1.1 As ...
- wamp 虚拟目录的设置(转载)
现在先来配置虚拟主机:1.先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#!!2.打开apache的apach ...
- 切换tab,并且动态添加标签
<script type="text/javascript"> /*处理ie7.ie8不兼容getElementsByClassName*/ if(!document. ...