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. JS中定义类的方法<转>

    转载地址:http://blog.csdn.net/sdlfx/article/details/1842218 PS(个人理解): 1) 类通过prototype定义的成员(方法或属性),是每个类对象 ...

  2. ApiGen4.1 windows安装教程

    一. ApiGen4.1版本介绍 1.ApiGen介绍 ApiGen是自动生成PHP项目的阅读文档工具. 用于从PHP源代码创建专业的API文档,类似于phpDocumentor/phpDoc. Ap ...

  3. 如何使用getopt()函数解析参数

    最近在写程序的过程中,把一部分时间都花费在程序对参数的处理上.今天听了学长说到getopt函数,才发现原来c里面还有一个专门解决参数处理的函数,查询了相关资料,这里简单总结一下. 使用int main ...

  4. Oracle EBS-SQL (WIP-10):检查车间任务状态“完成”但未发料数据.sql

    select WE.WIP_ENTITY_NAME                                               任务号,         MFG_LOOKUPS_WJS ...

  5. [Django 1.5] Django 开发学习资源链接

    jQuery : jQuery API introduction:http://api.jquery.com/ jQuery plugins: http://benalman.com/projects ...

  6. jsonarray----->list

    JSONArray--------------->List----------------->Adapter------------------>ListView

  7. 【IOS】在SDK中打开其他接入应用的解决方案

      在SDK中打开其他接入应用的解决方案 一直以来,在iOS的开发中,在程序中打开另外一个应用是不允许.后来有正义之士用class-dump在私有API中找到了这样的功能.那就是使用UIApplica ...

  8. Linux进程间通信——使用信号量

    这篇文章将讲述别一种进程间通信的机制——信号量.注意请不要把它与之前所说的信号混淆起来,信号与信号量是不同的两种事物.有关信号的更多内容,可以阅读我的另一篇文章:Linux进程间通信——使用信号.下面 ...

  9. mysql-bin.000001文件的来源及处理方法

    用ports安装了mysql以后,过一段时间发现/var空间不足了,查一下,会发现是mysql-bin.000001.mysql-bin.000002等文件占用了空间,那么这些文件是干吗的?这是数据库 ...

  10. C++面向对象编程初步

    1,使用const 指针; const int * pOne; //指向整型常量的指针,指向的值不能修改; int * const pTwo; //指向整型的常量指针,指向的值可以修改,但该指针不能再 ...