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 例子的更多相关文章

  1. 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 ...

  2. python多线程简单例子

    python多线程简单例子 作者:vpoet mail:vpoet_sir@163.com import thread def childthread(threadid): print "I ...

  3. Python 发邮件例子

    Python 发邮件例子 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-04-23 16:12:33 # @Autho ...

  4. python gevent使用例子

    python gevent使用例子 from gevent.pool import Pool POOL_SIZE = 100 def process(func, param1_list, param2 ...

  5. 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 ...

  6. 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 ...

  7. Python random模块 例子

    最近用到随机数,就查询资料总结了一下Python random模块(获取随机数)常用方法和使用例子. 1.random.random  random.random()用于生成一个0到1的随机符点数: ...

  8. Python练手例子(11)

    61.打印出杨辉三角形. #python3.7 from sys import stdout if __name__ == '__main__': a = [] for i in range(10): ...

  9. Python练手例子(10)

    55.学习使用按位取反~. 程序分析:~0=1; ~1=0; (1)先使a右移4位. (2)设置一个低4位全为1,其余全为0的数.可用~(~0<<4) (3)将上面二者进行&运算. ...

随机推荐

  1. HTML5新属性

    1.contenteditable 属性指定元素内容是否可编辑. 注意: 当元素中没有设置 contenteditable 属性时,元素将从父元素继承. 所有主流浏览器都支持 contentedita ...

  2. 高性能PHP论坛 Carbon Forum

    Carbon Forum,一个高性能的.高安全性的.基于话题的PHP轻论坛. 优秀的架构,高效的代码,每个页面平均执行时间仅为1~5毫秒,同时恰当地使用异步加载技术,在SEO与用户体验间取得平衡. 论 ...

  3. HttpServletRequest 报错 myeclipese支持tomcat

    做WEB项目的时候,别人拷贝了一份源码给你导入myeclipse结果发现一堆报错 HttpServletRequest  一排红色波浪线..... 这个原因主要是没有tomcat下的一个jar包 se ...

  4. c# 中的 Trim

    1. 让用户输入字符串 并且判断是否是 'yes'(无关大小写) Console.WriteLine("input a string"); string userResponse ...

  5. 【Chromium中文文档】沙箱FAQ

    沙箱FAQ 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Sandbox ...

  6. CentOS Linux 语言环境设置

    程序运行使用一套语言需要有字符集(数据)和字体(显示),Locale是根据计算机用户所使用的语言,所在国家或者地区,以及当地的文化传统所定义的一个软件运行时的语言环境. 一.locale详解 在 Li ...

  7. MFC CWnd仿按钮

    CBtn::CBtn() { RegisterWndClass(); } bool CBtn::RegisterWndClass(void) { WNDCLASS n; HINSTANCE hInst ...

  8. Apache的Access.log分析总结

    Apache的Access.log分析总结 #查看80端口的tcp连接  #netstat -tan | grep "ESTABLISHED" | grep ":80&q ...

  9. php 获取汉字拼音首字母的函数

    function getFirstChar($string){ if($string{0}>="A" and $string{0}<="z" )re ...

  10. DDL

    在DDL(Data Definition Language)中,创建.删除.修改使用create.drop.alter关键字 数据库的创建 create database 数据库名选择数据库 use ...