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)将上面二者进行&运算. ...
随机推荐
- C++进程间通信(常用理解例子)-买票
#include "stdafx.h" #include <iostream>using namespace std; #include "windows.h ...
- 图解musk这个神人
- Java 按值传递
http://guhanjie.iteye.com/blog/1683637 http://www.zhihu.com/question/31203609 String类 1.String 类按照 J ...
- [Backbone.js]如何用backbone写一个仿网页版微信的webapp?
var Chat = Backbone.Model.extend({ idAttribute:'id', initialize:function(options){ var users = this. ...
- centos6.5图形界面NetworkManager 配置ip文件位置
请教一个关于网络配置的问题,如图:该网络连接图形界面中 有2个配置,其中System eth0 有对应的配置文件/etc/sysconfig/network-scripts/ifcfg-eth0,但是 ...
- 提高mindmanager 8的启动速度
提高mindmanager 8的启动速度一连串 发布于:2010-01-13 18:12不少人抱怨mindmanager 8的启动速度较慢,用以下办法配置一下就能解决:1.进入mindmanager ...
- java Zip文件解压缩
java Zip文件解压缩 为了解压缩zip都折腾两天了,查看了许多谷歌.百度来的code, 真实无语了,绝大多数是不能用的.这可能跟我的开发环境有关吧. 我用的是Ubuntu14.04,eclips ...
- umdh工具使用
先安装工具,http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx 选择其中的http://msdn.microsoft.com/ ...
- mysqldump --master-data
--master-data[=#] This causes the binary log position and filename to be appended to the output. If ...
- MFC的规则DLL中资源使用的问题
今天刚刚做了一个静态链接到MFC的规则dll,即“Use MFC in a static library“,该dll用来显示一个窗体.然后在一个mfc可执行程序A.exe中调用这个dll文件,可以正常 ...