setup.py、setup() 以及其他一些东西
setup.py
除了调用函数 setup()
之外,还可以包含任何类型的 Python 代码,我使用以下代码片段对其进行了测试:
from setuptools import setup
setup(name='MyPackage',
packages=['mypackage'])
print "After setup()"
print
> 语句正常执行。我对此进行了测试,因为命令(python setup.py install
)让我产生了疑问。我是否应该无畏地将 setup.py
视为处理我所有安装需求的任意脚本?
背景是这样的:我正在编写一个Python包,它作为一个独立的程序运行,它不打算被导入。在 distutils 中,我找到了处理安装细节所需的几乎所有内容,例如将脚本复制到系统路径、复制额外的数据文件、创建目录等。但是仍然有一些过程超出了 >distutils
'范围,例如系统调用。
我应该将我需要的额外代码放入 setup.py
中吗?
setup.py
can contain any sort of Python code besides the call to the function setup()
, I tested it with the following snippet:
from setuptools import setup
setup(name='MyPackage',
packages=['mypackage'])
print "After setup()"
The print
statement was executed normally. I tested this because the command (python setup.py install
) made me doubt. Should I fearlessly treat setup.py
as an arbitrary script that handles all my installation needs?
The background goes something like this: I'm writing a Python package that works as a stand-alone program, it's not intended to be imported. In distutils
I found almost everything I need to handle the installation details like copying a script to the system path, copying extra data files, creating directories, etc. But there's still some procedures that go out of distutils
' scope, e.g. system calls.
Should I just put this extra code I need into setup.py
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最近的这篇博客文章应该可以回答您的大部分问题:
http://tarekziade.wordpress.com/2011/08/19/5-tips-for-packaging-your-python-projects/
很多工作正在进行中,但尚未提供,关于 Python 世界中的打包。
This recent blog post should answer most of your questions:
http://tarekziade.wordpress.com/2011/08/19/5-tips-for-packaging-your-python-projects/
A lot of work-in-progress, but not yet available, regarding packaging in Python world.
您可能想看看 http://paver.github.com/paver/,其中使得通过一些特定于项目的任务扩展 distutils 变得轻而易举。
You might want to take a look at http://paver.github.com/paver/, which makes extending distutils with some project-specific tasks a breeze.
如果在执行 setup() 期间发生错误,程序将停止并且不会执行进一步的代码。但您可能仍然需要执行一些额外的代码。
在这种情况下,使用:
If an error occures during the execution of setup(), the program will stop and no further code will be executed. But you might still want some additional code to be executed.
In this case, use: