博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python的egg
阅读量:2358 次
发布时间:2019-05-10

本文共 4547 字,大约阅读时间需要 15 分钟。

PythonEggs

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 , which lets you declare dependencies where they can be found by tools like. Setuptools is also needed in order to build 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 the (). 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.

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 .

下面是几个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 itsetup.py sdist upload             # create a source distro and upload itsetup.py sdist bdist_egg upload   # create and upload both

 
setup.py register sdist bdist_egg upload

setup.py的内容举例:

from setuptools import setup, find_packagessetup(    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链接以便下载的来源。

转载地址:http://lajtb.baihongyu.com/

你可能感兴趣的文章
浅谈Javac编译原理
查看>>
Java基础概念<最通俗易懂的讲解>
查看>>
Java中equals和==的区别
查看>>
oracle数据库表导出和导入csv文件操作
查看>>
asp.net中ObjectDataSource“”未能找到带参数的非泛型方法“DelnewsClass”: p1, id 问题
查看>>
Android各种屏幕尺寸
查看>>
Android模拟器无法上网问题
查看>>
抱歉,进程android.process.media,已停止运行的解决办法
查看>>
第一个helloword小例
查看>>
oracle新建方案
查看>>
android的坑
查看>>
java.net.SocketException:socket failed:EACCES (Permission denied)
查看>>
android.os.NetworkOnMainThreadException
查看>>
Android:单元测试Junit的配置
查看>>
国际产业
查看>>
制造业
查看>>
混沌的有关概念——1
查看>>
混沌的有关概念——2
查看>>
混沌理论的简要观点
查看>>
知识的经济学分析:一个文献综述——基于范式演进的视点
查看>>