在每个openstack项目中,都有setup.py和setup.cfg这两个文件。那setup.py和setup.cfg是什么?如何使用?以keystone项目为例,进行实践和解析。
简单的说,setup.py和setup.cfg是控制python项目打包、安装的工具类。
Setup.py
我们从一个简单的例子开始。假设要分发一个叫foo的模块,文件名foo.py,那么setup.py的内容如下:
fromdistutils.core import setup setup(name='foo',version='1.0',py_modules=['foo'],) |
然后,运行pythonsetup.py sdist为模块创建一个源码包。
stack@liujunpeng-Inspur-Computer:~/python_setup$python setup.py sdist runningsdist runningcheck warning:check: missing required meta-data: url
warning:check: missing meta-data: either (author and author_email) or(maintainer and maintainer_email) must be supplied
warning:sdist: manifest template 'MANIFEST.in' does not exist (usingdefault file list)
warning:sdist: standard file not found: should have one of README,README.txt
writingmanifest file 'MANIFEST' creatingfoo-1.0 makinghard links in foo-1.0... hardlinking foo.py -> foo-1.0 hardlinking setup.py -> foo-1.0 Creatingtar archive removing'foo-1.0' (and everything under it) |
在当前目录下,会创建dist目录,里面有个文件名为foo-1.0.tar.gz,这个就是可以分发的包。使用者,把该包解压,然后执行