python的egg

The Quick Guide to Python Eggs


PythonEggs


Automatic Discovery


To find out what options an egg offers, you should consult its documentation, or unpack and read itsEGG-INFO/depends.txt file, which lists an egg's required and optional dependencies.

我还没有找到过这个文件:

    EGG-INFO/depends.txt

我只能找到xxx-xx-xx.egg-info目录下面有requires.txt,里面有对各种依赖模块的信息.


(Note: the pkg_resources module doesnot automatically look for eggs on PyPI or download them from anywhere; any needed eggs must already be available in a directory onsys.path, or require() will raise aDependencyNotFound error. You can of course trap this error in your code and attempt to find the needed eggs on PyPI or elsewhere. If you want to automatically install dependencies for a project you're working on, you should probably build it using setuptools, which lets you declare dependencies where they can be found by tools likeEasyInstall. Setuptools is also needed in order to build eggs.)

Building Eggs

To build an egg from a package's setup.py, you'll need to havesetuptools installed. If you haven't already installed it in order to use thepkg_resources runtime, just check it out of Python's Subversion sandbox and runsetup.pyinstall to install it, or see theEasyInstall page's installation instructions (). Now you're ready to build eggs.

Edit the target package's setup.py and add from setuptools import setup such that it replaces the existing import of thesetup function. Then runsetup.pybdist_egg.

That's it. A .egg file will be deposited in the dist directory, ready for use. If you want to add any special metadata files, you can do so in theSomePackage.egg-info directory thatbdist_egg creates. ("SomePackage" will of course be replacd by the name of the package you're building.) Any files placed in this directory are copied to anEGG-INFO directory within the egg file, for use at runtime. Other metadata files are automatically generated for you, so don't edit them, as the next time you run a setup command they may be overwritten with the automatically generated versions.

Declaring Dependencies

Some eggs need other eggs to function. However, there isn't always a meaningful place for a library to callrequire(), and in any case a library's source code is rarely the place to declare its version dependencies. Sosetuptools allows you to declare dependencies in your project's setup script, so that they will be bundled inside the egg's metadata directory, and both the runtime and EasyInstall can then automatically find the additional eggs needed, adding them tosys.path when your project is installed or requested at runtime viarequire(). (Note: the EasyInstall program will find and download dependencies from the internet automatically, but for security reasons simply usingrequire() in Python code does not do this. require() only locates eggs that are in directories on the local machine that are listed insys.path)

在egg的metadata目录里面的setup脚本,放置依赖的egg信息,运行时和EasyInstall都能够自动发现这些需要的依赖eggs,把他们加到sys.path当你的项目被安装或者通过require()函数在运行时被请求。

注意:EasyInstall程序从internet自动发现并且下载这些依赖包,但是因为安全原因仅仅在python代码里面使用require ()函数不会自动下载安装这些egg-而是仅仅在sys.path列表里面说明的本地机器目录定位这些eggs。

For more information on declaring your project's dependencies, see the setuptools documentation.


下面是几个setup.py的命令行命令和参数

Creating a dated "nightly build" snapshot egg:

python setup.py egg_info --tag-date --tag-build=DEV bdist_egg

Creating and uploading a release with no version tags, even if some defaulttags are specified insetup.cfg:

python setup.py egg_info -RDb "" sdist bdist_egg register upload
 
setup.py bdist_egg upload         # create an egg and upload it
setup.py sdist upload             # create a source distro and upload it
setup.py sdist bdist_egg upload   # create and upload both

 
setup.py register sdist bdist_egg upload

setup.py的内容举例:

from setuptools import setup, find_packages
setup(
    name = "HelloWorld",
    version = "0.1",
    packages = find_packages(),
    scripts = ['say_hello.py'],

    # Project uses reStructuredText, so ensure that the docutils get
    # installed or upgraded on the target machine
    install_requires = ['docutils>=0.3'],

    package_data = {
        # If any package contains *.txt or *.rst files, include them:
        '': ['*.txt', '*.rst'],
        # And include any *.msg files found in the 'hello' package, too:
        'hello': ['*.msg'],
    }

    # metadata for upload to PyPI
    author = "Me",
    author_email = "me@example.com",
    description = "This is an Example Package",
    license = "PSF",
    keywords = "hello world example examples",
    url = "http://example.com/HelloWorld/",   # project home page, if any

    # could also include long_description, download_url, classifiers, etc.
)

注意:

url,dowload_url,long_description经常被作为寻找internet链接以便下载的来源。


EggCookingTutorialTrac0.11



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值