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. lex 和 yacc 的区别与联系

    lex负责词法解析,而yacc负责语法解析,其实说白了就是lex负责根据指定的正则表达式,将输入的字符串匹配成一个一个的token,同时允许用户将当前匹配到的字符串进行处理,并且允许返回一个标识当前t ...

  2. python--getitme\setitem 支持索引与分片

    1.想要自己定义的python对象支持索引与分片操作就要重载__getitem__\__setitem__这两个方法. 2.__getitme__(self,index) 这里的index参数可能类型 ...

  3. Realview MDK 中不用手动开中断的原因

    startup.s启动代码文件: ; Enter Supervisor Mode and set its Stack Pointer MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR ...

  4. 文本导出到pdf文件

    程序中数据导出是经常有的需求,今天学习把文本导出到pdf文件.主要是用QPrinter,QPainter TextEditToPdf::TextEditToPdf(QWidget *parent, Q ...

  5. 【找规律】CodeForce #258 Problem A——Game With Sticks

    来源:点击打开链接 非常easy.找规律. 每去掉一个点,点的总数量就减去n+m-1,然后看谁最先减到没有点可减.就能够了. #include <iostream> #include &l ...

  6. java设计模式之——代理模式

    1,什么是代理模式? 代理模式的作用是:为其他对象提供一种代理以控制对这个对象的访问. 2,策略模式有什么好处? 在某些情况下,一个客户不想或者不能直接引用另一个对象,而代理对象可以在客户端和目标对象 ...

  7. SSH框架整合 日志处理Spring结合 log4j、slf4j

    1. 加入log4j和slf4j的jar包 2. web.xml: <context-param> <!--log4j配置地址 --> <param-name>lo ...

  8. 为何遍历Ldr会得到空项?

    转自:http://www.0xaa55.com/thread-1385-1-1.html 之前做过ldr遍历的操作,发现第一项竟然是空,也就是大部分元素都是0,下面来揭示一下原理: 经过研究,其实L ...

  9. ecshop开发日志之虚拟商品发送邮件通知

    购买虚拟商品,系统会在支付后自动发送邮件到用户填写的邮件地址中,追踪过程如下首先在订单列表中可以获得到处理订单的php文件为flow.php,之后在最后一步url地址显示为http://localho ...

  10. < meta > 元素 概要

    < meta > 元素 概要 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 we ...