OPENSTACK:15, openstack-Development Foundation Entry_points Learning

Source: Internet
Author: User

Reference: http://blog.csdn.net/pfm685757/article/details/48651389

Entry point is a dictionary that maps from the entry point group name to a list of strings or strings representing entry point. Entry points is used to support dynamic discovery Services and Plug-ins, and is also used to support automatic generation of scripts.

Here is a demo.

1, create a new directory MyProject, in this directory to create a new setup.py file, the contents are as follows

#!/usr/bin/env python #-*-coding:utf-8-*-# @Time: 6/2/17 2:39 PM # @Site: # @File: setup.py.py # @Softwa Re:pycharm ' If you use the command Python setup.py Bdist_egg, the Foo-1.0-py2.7.egg package will be generated in the Dist directory, and the first sentence in the setup.py should be changed from Setuptools Import Setup). After the user gets the package, unzip it and execute it into the foo-1.0 directory: Python setup.py install, then foo.py will be copied to the Python classpath and can be imported (if the installation is egg file,

The egg file is copied to the Dist-packages directory). ' From Setuptools import setup, find_packages # Name Package name, version number, packages included other packages # use Find_packages (): Default in setup.py same directory 
To search for packages containing __init__.py, you can place packages in the SRC directory, possibly with data folders # Execute Python setup.py bdist_egg generate egg files, execute Python setup.py install will generate the entry file ' [Root@localhost bin]# cat foo #!/usr/bin/python # easy-install-entry-script: ' demo==0.1 ', ' console_scripts ', ' foo ' __
        requires__ = ' demo==0.1 ' import sys from pkg_resources import load_entry_point if __name__ = = ' __main__ ': Sys.exit ( Load_entry_point (' demo==0.1 ', ' console_scripts ', ' foo ') ()) ' "' Setup (name =" Demo ", Version = "0.1", Packages = Find_packages (),) ' Setup (name = "Demo", Version = "0.1", Packages = find_packages (' src '), # contains all SRC Package Package_dir = {': ' src '}, # tell distutils packet src under package_data = {# Any package has a. txt file that contains it ': [' *.txt '] , # contains the *.dat ' demo ' in the Data folder of the demo: [' Data/*.dat '],}, entry_points = {' console_scripts ': [' foo = Demo:test ', ' bar = Demo:test ',], ' gui_scripts ': [' Baz = dem O:test ',]})

2, in the MyProject directory, a new directory src, under src New directory data, under the data new file __init__.py file, the contents are as follows

#!/usr/bin/env python
#-*-coding:utf-8-*-

def Test ():
    print "Hello World"

if __name__ = ' __main__ ': C4/>test ()


3. Build Egg Package

Go to the containing setup.py directory and execute the following command:

Python setup.py Bdist_egg

Then, install the module and execute the following command:

Python setup.py Install


4, use the package you created

Execute the following command:

Foo

'll get

Hello World
Execute command

Bar

will also get

Hello World






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.