声明:
本博客欢迎转发,但请保留原作者信息!
博客地址:http://lingxiankong.github.io/
内容系本人及本人团队学习、研究和总结,如有雷同,实属荣幸!
Author:华为云计算工程师 孔令贤
Date: 2013-12-23
版本:2013.2
其实对于setup.py和setup.cfg的关注是从OpenStack的源码包中开始的,OpenStack每个组件的发布时都是一个tar.gz包,同样,我们直接从github上clone代码后也会发现两个文件的存在。当阅读Nova或Ceilometer(其他组件可能也会涉及)的代码时,发现setup.cfg中内容对于代码的理解有很大的影响。那么,到底setup.py和setup.cfg是干什么的?
我们从例子开始。假设你要分发一个叫foo的模块,文件名foo.py�e8C那么setup.py内容如下:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding%sA 0px; list-style-positio.: initial;"><li class="L0" style="margin: 0px 0px 5px; pa$ding: 0px; color: r'b(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal;%r0background-color: transparent;"><span class="kwd" style="color: rgb(147, 199, 99);">from</span><span class="pln" style="color: rgb(241, 242, 243);"> distutils</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">core </span><span class="kwd" style="color: rgb(147, 199, 99);">import</span><span class="pln" style="color: rgb(241, 242, 243);"> setup</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="pln" style="color: rgb(241, 242, 243);">name</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="str" style="color: rgb(236, 118, 0);">'foo'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> version</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="str" style="color: rgb(236, 118, 0);">'1.0'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> py_modules</span><span class="pun" style="color: rgb(241, 242, 243);">=[</span><span class="str" style="color: rgb(236, 118, 0);">'foo'</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">)</span><span class="pln" style="color: rgb(241, 242, 243);"> </span></code></li></ol>
然后,运行python setup.py sdist
为模块创建一个源码包
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">root@network</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="str" style="color: rgb(236, 118, 0);">/kong/</span><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="com" style="color: rgb(102, 116, 123);"># python setup.py sdist</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running sdist</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running check</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">warning</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> check</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> missing required meta</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">data</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> url </span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">warning</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> check</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> missing meta</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">data</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> either </span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="pln" style="color: rgb(241, 242, 243);">author </span><span class="kwd" style="color: rgb(147, 199, 99);">and</span><span class="pln" style="color: rgb(241, 242, 243);"> author_email</span><span class="pun" style="color: rgb(241, 242, 243);">)</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="kwd" style="color: rgb(147, 199, 99);">or</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="pln" style="color: rgb(241, 242, 243);">maintainer </span><span class="kwd" style="color: rgb(147, 199, 99);">and</span><span class="pln" style="color: rgb(241, 242, 243);"> maintainer_email</span><span class="pun" style="color: rgb(241, 242, 243);">)</span><span class="pln" style="color: rgb(241, 242, 243);"> must be supplied</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">warning</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> sdist</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> manifest </span><span class="kwd" style="color: rgb(147, 199, 99);">template</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'MANIFEST.in'</span><span class="pln" style="color: rgb(241, 242, 243);"> does </span><span class="kwd" style="color: rgb(147, 199, 99);">not</span><span class="pln" style="color: rgb(241, 242, 243);"> exist </span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="kwd" style="color: rgb(147, 199, 99);">using</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="kwd" style="color: rgb(147, 199, 99);">default</span><span class="pln" style="color: rgb(241, 242, 243);"> file list</span><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">warning</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> sdist</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> standard file </span><span class="kwd" style="color: rgb(147, 199, 99);">not</span><span class="pln" style="color: rgb(241, 242, 243);"> found</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> should have one of README</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> README</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">txt</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">writing manifest file </span><span class="str" style="color: rgb(236, 118, 0);">'MANIFEST'</span></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">creating foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">making hard links </span><span class="kwd" style="color: rgb(147, 199, 99);">in</span><span class="pln" style="color: rgb(241, 242, 243);"> foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span><span class="pun" style="color: rgb(241, 242, 243);">...</span></code></li><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">hard linking foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py </span><span class="pun" style="color: rgb(241, 242, 243);">-></span><span class="pln" style="color: rgb(241, 242, 243);"> foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">hard linking setup</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py </span><span class="pun" style="color: rgb(241, 242, 243);">-></span><span class="pln" style="color: rgb(241, 242, 243);"> foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">creating dist</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="typ" style="color: rgb(103, 140, 177);">Creating</span><span class="pln" style="color: rgb(241, 242, 243);"> tar archive</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">removing </span><span class="str" style="color: rgb(236, 118, 0);">'foo-1.0'</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="kwd" style="color: rgb(147, 199, 99);">and</span><span class="pln" style="color: rgb(241, 242, 243);"> everything under it</span><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
在当前目录下,会创建dist
目录,里面有个文件名为foo-1.0.tar.gz
,这个就是可以分发的包。使用者拿到这个包后,解压,到foo-1.0目录下执行:python setup.py install
,那么,foo.py就会被拷贝到python类路径下,可以被导入使用。
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">root@network</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="str" style="color: rgb(236, 118, 0);">/kong/</span><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">dist</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span><span class="com" style="color: rgb(102, 116, 123);"># python setup.py install</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running install</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running build</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running build_py</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">creating build</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">creating build</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">linux</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">x86_64</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">2.7</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">copying foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py </span><span class="pun" style="color: rgb(241, 242, 243);">-></span><span class="pln" style="color: rgb(241, 242, 243);"> build</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">linux</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">x86_64</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">2.7</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running install_lib</span></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">copying build</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">linux</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">x86_64</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">2.7</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py </span><span class="pun" style="color: rgb(241, 242, 243);">-></span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">/usr/</span><span class="kwd" style="color: rgb(147, 199, 99);">local</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">python2</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="lit" style="color: rgb(250, 205, 34);">7</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">dist</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">packages</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="kwd" style="color: rgb(147, 199, 99);">byte</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">compiling </span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">usr</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="kwd" style="color: rgb(147, 199, 99);">local</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">python2</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="lit" style="color: rgb(250, 205, 34);">7</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">dist</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">packages</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py to foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">pyc</span></code></li><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running install_egg_info</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="typ" style="color: rgb(103, 140, 177);">Removing</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">usr</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="kwd" style="color: rgb(147, 199, 99);">local</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">python2</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="lit" style="color: rgb(250, 205, 34);">7</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">dist</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">packages</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">egg</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">info</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="typ" style="color: rgb(103, 140, 177);">Writing</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">usr</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="kwd" style="color: rgb(147, 199, 99);">local</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">lib</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">python2</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="lit" style="color: rgb(250, 205, 34);">7</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">dist</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">packages</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">egg</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">info</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">root@network</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="str" style="color: rgb(236, 118, 0);">/kong/</span><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">dist</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span><span class="com" style="color: rgb(102, 116, 123);"># ll /usr/local/lib/python2.7/dist-packages/foo</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">foo</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="lit" style="color: rgb(250, 205, 34);">1.0</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">egg</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">info foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py foo</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">pyc </span></code></li></ol>
对于Windows,可以执行python setup.py bdist_wininst
生成一个exe文件;若要生成RPM包,执行python setup.py bdist_rpm
,但系统必须有rpm命令的支持。可以运行下面的命令查看所有格式的支持:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">root@network</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="str" style="color: rgb(236, 118, 0);">/kong/</span><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="com" style="color: rgb(102, 116, 123);"># python setup.py bdist --help-formats</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="typ" style="color: rgb(103, 140, 177);">List</span><span class="pln" style="color: rgb(241, 242, 243);"> of available distribution formats</span><span class="pun" style="color: rgb(241, 242, 243);">:</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">rpm RPM distribution</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">gztar gzip</span><span class="str" style="color: rgb(236, 118, 0);">'ed tar file</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="str" style="color: rgb(236, 118, 0);"> --formats=bztar bzip2'</span><span class="pln" style="color: rgb(241, 242, 243);">ed tar file</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">ztar compressed tar file</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">tar tar file</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">wininst </span><span class="typ" style="color: rgb(103, 140, 177);">Windows</span><span class="pln" style="color: rgb(241, 242, 243);"> executable installer</span></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">zip ZIP file</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">formats</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">msi </span><span class="typ" style="color: rgb(103, 140, 177);">Microsoft</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="typ" style="color: rgb(103, 140, 177);">Installer</span></code></li></ol>
setup函数还有一些参数:
1、packages
告诉Distutils需要处理那些包(包含__init__.py
的文件夹)
2、package_dir
告诉Distutils哪些目录下的文件被映射到哪个源码包。一个例% 5��:package_dir = {'': 'lib'}
,表示“root package”中的模块都在lib目录中。
3、ext_modules
是一个包含Extension实例的列表,Extension的定义也有一�e9B参数。
4、ext_package
定义extension的相对路径
5、requires
定义依赖哪些模块
6、provides
定义可以为哪些模块提供依赖
7、scripts
指定python源码文件,可以从命令行执行。在安装时指定--install-script
8、package_data
通常包含与包实现相关的一些数据文件或类似于readme的文件。如果没有提供模板,会被添加到MANIFEST文件中。
9、data_files
指定其他的一些文件(如配置文件)
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(...,</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> data_files</span><span class="pun" style="color: rgb(241, 242, 243);">=[(</span><span class="str" style="color: rgb(236, 118, 0);">'bitmaps'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'bm/b1.gif'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'bm/b2.gif'</span><span class="pun" style="color: rgb(241, 242, 243);">]),</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="str" style="color: rgb(236, 118, 0);">'config'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'cfg/data.cfg'</span><span class="pun" style="color: rgb(241, 242, 243);">]),</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="str" style="color: rgb(236, 118, 0);">'/etc/init.d'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'init-script'</span><span class="pun" style="color: rgb(241, 242, 243);">])]</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
规定了哪些文件被安装到哪些目录中。如果目录名是相对路径,则是相对于sys.prefix
或sys.exec_prefix
的路径。如果没有提供模板,会被添加到MANIFEST文件中。
执行sdist命令时,默认会打包哪些东西呢?
py_modules
或packages
指定的源码文件ext_modules
或libraries
指定的C源码文件scripts
指定的脚本文件package_data
或data_files
指定的文件 还有一种方式是写一个manifest template,名为MANIFEST.in
,定义如何生成MANIFEST文件,内容就是需要包含在分发包中的文件。一个MANIFEST.in文件如下:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">include </span><span class="pun" style="color: rgb(241, 242, 243);">*.</span><span class="pln" style="color: rgb(241, 242, 243);">txt</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">recursive</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">include examples </span><span class="pun" style="color: rgb(241, 242, 243);">*.</span><span class="pln" style="color: rgb(241, 242, 243);">txt </span><span class="pun" style="color: rgb(241, 242, 243);">*.</span><span class="pln" style="color: rgb(241, 242, 243);">py</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">prune examples</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">sample</span><span class="pun" style="color: rgb(241, 242, 243);">?/</span><span class="pln" style="color: rgb(241, 242, 243);">build</span></code></li></ol>
setup.cfg提供一种方式,可以让包的开发者提供命令的默认选项,同时为用户提供修改的机会。对setup.cfg的解析,是在setup.py之后,在命令行执行前。
setup.cfg文件的形式类似于
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="pln" style="color: rgb(241, 242, 243);">command</span><span class="pun" style="color: rgb(241, 242, 243);">]</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">option</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);">value</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">...</span></code></li></ol>
其中,command
是Distutils的命令参数,option
是参数选项,可以通过python setup.py --help build_ext
方式获取。
需要注意的是,比如一个选项是--foo-bar,在setup.cfg中必须改成foo_bar的格式
符合Distutils2的setup.cfg有些不同。包含一些sections:
1、global
定义Distutils2的全局选项,可能包含commands,compilers,setup_hook(定义脚本,在setup.cfg被读取后执行,可以修改setup.cfg的配置)
2、metadata
3、files
4、command sections
上面的setup.py和setup.cfg都是遵循python标准库中的Distutils,而setuptools工具针对Python官方的distutils做了很多针对性的功能增强,比如依赖检查,动态扩展等。很多高级功能我就不详述了,自己也没有用过,等用的时候再作补充。
一个典型的遵循setuptools的脚本:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="kwd" style="color: rgb(147, 199, 99);">from</span><span class="pln" style="color: rgb(241, 242, 243);"> setuptools </span><span class="kwd" style="color: rgb(147, 199, 99);">import</span><span class="pln" style="color: rgb(241, 242, 243);"> setup</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> find_packages</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> name </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"HelloWorld"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> version </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"0.1"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> packages </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> find_packages</span><span class="pun" style="color: rgb(241, 242, 243);">(),</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> scripts </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'say_hello.py'</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># Project uses reStructuredText, so ensure that the docutils get</span></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># installed or upgraded on the target machine</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> install_requires </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'docutils>=0.3'</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> package_data </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">{</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># If any package contains *.txt or *.rst files, include them:</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">''</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'*.txt'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'*.rst'</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># And include any *.msg files found in the 'hello' package, too:</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'hello'</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'*.msg'</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">},</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.qem;"><code style=%2rmargin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" st9le="color: rgb(241,%2p242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># metadata for upload to PyPI</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wra0: normal;e20background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> !uthor </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </spa.><span class="str" style="color: rgb(236, 118, 0);">"Me"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> author_email </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"[email protected]"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> description </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"This is an Example Package"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> license </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"PSF"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> keywords </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"hello world example examples"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> url </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"http://example.com/HelloWorld/"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># project home page, if any</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># could also include long_description, download_url, classifiers, etc.</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># other arguments here...</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> entry_points </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">{</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'setuptools.installation'</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'eggsecutable = my_package.some_module:main_func'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">]</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">}</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> name</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="str" style="color: rgb(236, 118, 0);">"Project-A"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">...</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> extras_require </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">{</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'PDF'</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">"ReportLab>=1.2"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"RXP"</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'reST'</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">"docutils>=0.3"</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">}</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
特性如何使用呢?需要与entry points结合使用:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> name</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="str" style="color: rgb(236, 118, 0);">"Project-A"</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">...</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> entry_points </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">{</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'console_scripts'</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'rst2pdf = project_a.tools.pdfgen [PDF]'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">'rst2html = project_a.tools.htmlgen'</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># more script entry points ...</span></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">}</span></code></li><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
或者被其他project依赖:install_requires = ["Project-A[PDF]"]
我想大家最熟悉的就是这个特性了吧。比如一个博客系统想用不同的插件支持不同的语言输出格式,那么就可以定义一个“entry point group”,不同的插件就可以注册“entry point”,插件注册的示例:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># ...</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> entry_points </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">{</span><span class="str" style="color: rgb(236, 118, 0);">'blogtool.parsers'</span><span class="pun" style="color: rgb(241, 242, 243);">:</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="str" style="color: rgb(236, 118, 0);">'.rst = some_module:a_func'</span><span class="pun" style="color: rgb(241, 242, 243);">]}</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="com" style="color: rgb(102, 116, 123);"># 或者</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="com" style="color: rgb(102, 116, 123);"># ...</span></code></li><li class="L7" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> entry_points </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"""</span></code></li><li class="L8" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="str" style="color: rgb(236, 118, 0);"> [blogtool.parsers]</span></code></li><li class="L9" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="str" style="color: rgb(236, 118, 0);"> .rst = some.nested.module:SomeClass.some_classmethod [reST]</span></code></li><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="str" style="color: rgb(236, 118, 0);"> """</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> extras_require </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> dict</span><span class="pun" style="color: rgb(241, 242, 243);">(</span><span class="pln" style="color: rgb(241, 242, 243);">reST </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> </span><span class="str" style="color: rgb(236, 118, 0);">"Docutils>=0.3.5"</span><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
Distutils is the standard tool used for packaging. It works rather well for simple needs, but is limited and not trivial to extend.
Setuptools is a project born from the desire to fill missing distutils functionality and explore new directions. In some subcommunities, it’s a de facto standard. It uses monkey-patching and magic that is frowned upon by Python core developers.
Distribute is a fork of Setuptools that was started by developers feeling that its development pace was too slow and that it was not possible to evolve it. Its development was considerably slowed when distutils2 was started by the same group. 2013-August update: distribute is merged back into setuptools and discontinued.
Distutils2 is a new distutils library, started as a fork of the distutils codebase, with good ideas taken from setup tools (of which some were thoro5ghly discusse$ in PEPs)%2 and a basic installer inspired by pip. The actual name you use to import Distutils2 is packaging in the Python 3.3+ standard library, or distutils2 in 2.4+ and%r03.1–3.r. (A backpo2t will be available soon.) Distutils2 did not make the Python 3.3 release, and it was put on hold.
pbr是setuptools的辅助工具,最初是为OpenStack开发,基于d2to1。
A library for managing setuptools packaging needs in a consistent manner.
pbr会读取和过滤setup.cfg中的数据,然后将解析后的数据提供给setup.py作为参数。包含如下功能:
1、从git中获取Version、AUTHORS and ChangeLog信息
2、Sphinx Autodoc。pbr会扫描project,找到所有模块,生成stub files
3、Requirements。pbr会读取requirements.txt,生成setup函数需要的install_requires/tests_require/dependency_links
4、long_description。从README.rst, README.txt or README file中生成long_description
参数
使用pbr很简单:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="kwd" style="color: rgb(147, 199, 99);">from</span><span class="pln" style="color: rgb(241, 242, 243);"> setuptools </span><span class="kwd" style="color: rgb(147, 199, 99);">import</span><span class="pln" style="color: rgb(241, 242, 243);"> setup</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">(</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> setup_requires</span><span class="pun" style="color: rgb(241, 242, 243);">=[</span><span class="str" style="color: rgb(236, 118, 0);">'pbr'</span><span class="pun" style="color: rgb(241, 242, 243);">],</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> pbr</span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="kwd" style="color: rgb(147, 199, 99);">True</span><span class="pun" style="color: rgb(241, 242, 243);">,</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">)</span></code></li></ol>
使用pbr时,setup.cfg中有一些配置。在[files]中,有三个key:
packages
:指定需要包含的包,行为类似于setuptools.find_packages
namespace_packages
:指定namespace packages
data_files
: 指定目的目录和源文件路径,一个示例:
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">[</span><span class="pln" style="color: rgb(241, 242, 243);">files</span><span class="pun" style="color: rgb(241, 242, 243);">]</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">data_files </span><span class="pun" style="color: rgb(241, 242, 243);">=</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);"> etc</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">pbr </span><span class="pun" style="color: rgb(241, 242, 243);">=</span><span class="pln" style="color: rgb(241, 242, 243);"> etc</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">pbr</span><span class="com" style="color: rgb(102, 116, 123);">/*</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="com" style="color: rgb(102, 116, 123);"> etc/neutron =</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="com" style="color: rgb(102, 116, 123);"> etc/api-paste.ini</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="com" style="color: rgb(102, 116, 123);"> etc/dhcp-agent.ini</span></code></li><li class="L6" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="com" style="color: rgb(102, 116, 123);"> etc/init.d = neutron.init</span></code></li></ol>
[entry_points]段跟setuptools的方式相同。
A collection of tools for internationalizing Python applications
Babel是 Python 的一个国际化工具包,提供了对distutils或setuptools的支持,包含一些命令。
1、compile_catalog
类似于msgfmt工具,takes a message catalog from a PO file and compiles it to a binary MO file.
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">$ </span><span class="pun" style="color: rgb(241, 242, 243);">./</span><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py compile_catalog </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">directory foobar</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">locale </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">locale pt_BR</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running compile_catalog</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">compiling catalog to foobar</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">locale</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">pt_BR</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">LC_MESSAGES</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">messages</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">mo</span></code></li></ol>
2、extract_messages
类似于xgettext,it can extract localizable messages from a variety of difference source files, and generate a PO (portable object) template file from the collected messages.
<ol class="linenums" style="margin: 0px 0px 0px 25px; padding: 0px; list-style-position: initial;"><li class="L0" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">$ </span><span class="pun" style="color: rgb(241, 242, 243);">./</span><span class="pln" style="color: rgb(241, 242, 243);">setup</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py extract_messages </span><span class="pun" style="color: rgb(241, 242, 243);">--</span><span class="pln" style="color: rgb(241, 242, 243);">output</span><span class="pun" style="color: rgb(241, 242, 243);">-</span><span class="pln" style="color: rgb(241, 242, 243);">file foobar</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">locale</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">messages</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">pot</span></code></li><li class="L1" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">running extract_messages</span></code></li><li class="L2" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">extracting messages </span><span class="kwd" style="color: rgb(147, 199, 99);">from</span><span class="pln" style="color: rgb(241, 242, 243);"> foobar</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">__init__</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py</span></code></li><li class="L3" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">extracting messages </span><span class="kwd" style="color: rgb(147, 199, 99);">from</span><span class="pln" style="color: rgb(241, 242, 243);"> foobar</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">core</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">py</span></code></li><li class="L4" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em;"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pun" style="color: rgb(241, 242, 243);">...</span></code></li><li class="L5" style="margin: 0px 0px 5px; padding: 0px; color: rgb(85, 85, 85); list-style: decimal; line-height: 1.1em; background-color: rgb(17, 17, 17);"><code style="margin: 0px; padding: 0px; border: none; font-family: Courier; line-height: 14px; word-wrap: normal; background-color: transparent;"><span class="pln" style="color: rgb(241, 242, 243);">writing PO </span><span class="kwd" style="color: rgb(147, 199, 99);">template</span><span class="pln" style="color: rgb(241, 242, 243);"> file to foobar</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">locale</span><span class="pun" style="color: rgb(241, 242, 243);">/</span><span class="pln" style="color: rgb(241, 242, 243);">messages</span><span class="pun" style="color: rgb(241, 242, 243);">.</span><span class="pln" style="color: rgb(241, 242, 243);">pot</span></code></li></ol>
3、update_catalog
类似于msgmerge,it updates an existing translations catalog based on a PO template file (POT).
OK,讲了这么多琐碎的东西,现在去看看Nova或Ceilometer的setup脚本,是不是一下清晰了很多?!但说实话,setup.py的使用,我还不能讲的特别清楚,需要在后续的实战中学习。