python 您为python推荐哪种构建工具?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/870516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
which build tool(s) do you recommend for python?
提问by Davide
I'm starting a small/medium-sized python project, likely in Test Driven Development. My backgrounds are more in C and java than python (I used ant and makefile)
我正在开始一个中小型 python 项目,可能是在测试驱动开发中。我的背景更多是在 C 和 java 而不是 python(我使用了 ant 和 makefile)
I know that in python you might not need a build tool, but I will, because I'll use cython and PyInstaller (the thing should work on a couple of different UNIXes, without depending directly on python) and I'd like the convenience of selecting the tests form CLI, building the docs, maybe check dependencies, etc.
我知道在 python 中你可能不需要构建工具,但我会,因为我将使用 cython 和 PyInstaller(这个东西应该在几个不同的 UNIX 上工作,而不直接依赖于 python),我想要方便从 CLI 中选择测试、构建文档、检查依赖关系等。
Somebodyis complaining that python lacks a make-like tool. I know that few tools exist, like sconand paver, but I'd like to hear from real users and not just their website. Does anybody use paver?
有人抱怨 python 缺少类似 make 的工具。我知道很少有工具存在,比如scon和paver,但我想听听真实用户的意见,而不仅仅是他们的网站。有人用摊铺机吗?
What's about the usual setup.py that comes with many packages? I looked into a few to see if there is a common usage, but I didn't find anything interesting (maybe I used the wrong examples)
许多包附带的通常 setup.py 是什么?查了几个,看看有没有共同的用法,但是没发现什么有趣的东西(可能是我用错了例子)
Do you recommend sticking with things I already know (ant and Makefile) at least to start? If so, is there any ant extension you recommend for python (+cython+pyinstaller+pyUnit)?
您是否建议至少在开始时坚持使用我已经知道的东西(ant 和 Makefile)?如果是这样,您是否有推荐用于 python 的 ant 扩展(+cython+pyinstaller+pyUnit)?
EDIT: to avoid further answers like jwp's one, note that, for this project, I absolutely need my program being a standalone executable because it is absolutely impossibleto have a python VM on the target platform where the executable will run. I have exactly the same hw available for compiling, so luckly I don't need to cross-compile (but I'd do the development on a more friendly Linux).
编辑:为了避免像 jwp 这样的其他答案,请注意,对于这个项目,我绝对需要我的程序是一个独立的可执行文件,因为在可执行文件将运行的目标平台上绝对不可能有一个 python VM。我有完全相同的硬件可用于编译,所以幸运的是我不需要交叉编译(但我会在更友好的 Linux 上进行开发)。
I'd also like to test if my code compile in Cython from the beginning, not to premature optimize, but just to be sure that I'm not going too far with the use of incompatible features, which would require a painful refactoring if Cython would be seriously needed.
我还想测试我的代码是否从一开始就在 Cython 中编译,而不是过早优化,但只是为了确保我不会使用不兼容的功能走得太远,如果 Cython,这将需要痛苦的重构将是非常需要的。
So please focus on my actual question
所以请关注我的实际问题
采纳答案by Piotr Byzia
Your requirements suggest rather Sconswhich, according to their website, has more control over variety of building tasks than Paver. In the latter you would end up using a lot of sh()
which runs a regular command line programs.
您的要求建议使用Scons,根据他们的网站,它比Paver对各种建筑任务有更多的控制权。在后者中,您最终会使用很多sh()
运行常规命令行程序的程序。
Recently, I started using Paverwhich is really great to run tests, build documentations with Sphinx, but I use only pure Python. If you want to see what's possible with Paver I highly recommend those 2 articles: converting-from-make-to-paverand writing-technical-documentationby Doug Hellmann and you definitely want to check his pavement.py configuration file.
最近,我开始使用Paver,它非常适合运行测试、使用Sphinx构建文档,但我只使用纯 Python。如果您想了解 Paver 的功能,我强烈推荐这两篇文章: Doug Hellmann 的 convert -from-make-to-paver和writing-technical-documentation,您肯定想查看他的 pavement.py配置文件。
回答by jwp
If it is at all possible, I'd suggest avoiding extension modules(C/cython) in the beginning. Get your all code written in Python, use a simple distutils
based configuration, run your tests using -m
(python -m mypkg.test.testall
, or whatever; import unittest
).
如果可能的话,我建议在开始时避免使用扩展模块(C/cython)。使用 Python 编写所有代码,使用基于简单distutils
的配置,使用-m
(python -m mypkg.test.testall
或其他方式; import unittest
)运行您的测试。
Once you get your project to a comfy state, then start tackling some optimizations with cython and the extra project management that comes with that. distutils can build extension modules, so I'm not sure you'll need make/scons..
一旦你的项目进入一个舒适的状态,然后开始用 cython 和随之而来的额外项目管理来解决一些优化问题。distutils 可以构建扩展模块,所以我不确定你是否需要 make/scons..
project-dir/
setup.py
mypkg/
__init__.py
mymod.py
test/
__init__.py
testall.py
testsomething_specific.py
回答by Ale
One tool I love is virtualenv: http://pypi.python.org/pypi/virtualenv
我喜欢的一种工具是 virtualenv:http: //pypi.python.org/pypi/virtualenv
from the site: What It Does virtualenv is a tool to create isolated Python environments. The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.4/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.
来自网站: 它的作用 virtualenv 是一个创建隔离 Python 环境的工具。正在解决的基本问题是依赖项和版本之一,以及间接权限。假设您有一个需要 LibFoo 版本 1 的应用程序,但另一个应用程序需要版本 2。如何同时使用这两个应用程序?如果您将所有内容都安装到 /usr/lib/python2.4/site-packages(或您平台的任何标准位置)中,很容易导致您无意中升级了不应升级的应用程序。
You can also try: http://pypi.python.org/pypi/zc.buildout
你也可以试试:http: //pypi.python.org/pypi/zc.buildout
from the site: The Buildout project provides support for creating applications, especially Python applications. It provides tools for assembling applications from multiple parts, Python or otherwise. An application may actually contain multiple programs, processes, and configuration settings.
来自站点: Buildout 项目为创建应用程序提供支持,尤其是 Python 应用程序。它提供了用于从多个部分(Python 或其他)组装应用程序的工具。一个应用程序实际上可能包含多个程序、进程和配置设置。
Tried it a couple of times, excellent for deploying development envrionments, maybe it's too much for your needs.
尝试了几次,非常适合部署开发环境,也许它对您的需求来说太多了。
I've also been told and read in a couple of places that nose is a very cool testing tool http://somethingaboutorange.com/mrl/projects/nose/0.11.1/, I'm looking for some free time to try it.
我也被告知并在几个地方读到鼻子是一个非常酷的测试工具 http://somethingaboutorange.com/mrl/projects/nose/0.11.1/,我正在寻找一些空闲时间来尝试它。
Hope It helps Cheers, Ale
希望它有助于干杯,啤酒
回答by Alexander Torstling
I've been using setuptoolsfor this, sometimes in combination with Ant for more complex stuff, or for integrating with other builds. In general it has worked well for me, but I've heard some people at #python (freenode) complain about a generally low source quality for this package, and recommending the standard distutils.
我一直在为此使用setuptools,有时与 Ant 结合用于更复杂的东西,或者与其他构建集成。总的来说,它对我来说效果很好,但我听说 #python (freenode) 的一些人抱怨这个包的源质量普遍较低,并推荐标准的distutils。
One thing to really watch out with if you are used to Java (like me), is that python does not support split packages. That is, you cannot put site.db in src/site/db, site.view in src2/site/view, put src and src2 on PYTHONPATH and the expect everything to work. This caused major headaches for me with the build tools, it worked a bit sporadically :)
如果您习惯了 Java(像我一样),真正要注意的一件事是 python 不支持拆分包。也就是说,你不能把 site.db 放在 src/site/db 中,site.view 放在 src2/site/view 中,把 src 和 src2 放在 PYTHONPATH 上,并期望一切正常。这给我的构建工具带来了很大的麻烦,它偶尔会起作用:)
回答by Jason Baker
to avoid further answers like jwp's one, note that, for this project, I absolutely need my program being a standalone executable because it is absolutely impossible to have a python VM on the target platform where the executable will run. I have exactly the same hw available for compiling, so luckly I don't need to cross-compile (but I'd do the development on a more friendly Linux).
I'd also like to test if my code compile in Cython from the beginning, not to premature optimize, but just to be sure that I'm not going too far with the use of incompatible features, which would require a painful refactoring if Cython would be seriously needed.
为了避免像 jwp 那样的进一步答案,请注意,对于这个项目,我绝对需要我的程序是一个独立的可执行文件,因为在可执行文件将运行的目标平台上绝对不可能有一个 python VM。我有完全相同的硬件可用于编译,所以幸运的是我不需要交叉编译(但我会在更友好的 Linux 上进行开发)。
我还想测试我的代码是否从一开始就在 Cython 中编译,而不是过早优化,但只是为了确保我不会使用不兼容的功能走得太远,如果 Cython,这将需要痛苦的重构将是非常需要的。
If all you're looking for is to have a stand-alone executable, you don't need to run Cython. There are a few good libraries for doing this:
如果您只需要一个独立的可执行文件,则不需要运行 Cython。有一些很好的库可以做到这一点:
However, to run Python code, you're simply going to have toinstall an interpreter or virtual machine on the target machine in some form or fashion. The solutions I presented involve merely embedding the interpreter to make it easier to install. In fact, I'm pretty sure (but could be wrong) that Cython won't allow you to build a stand-alone executables. It's mainly meant for creating extensions to the Python interpreter.
然而,运行Python代码,你只是将不得不安装在目标机器上的解释或虚拟机以某种形式或方式。我提出的解决方案仅涉及嵌入解释器以使其更易于安装。事实上,我很确定(但可能是错误的)Cython 不允许您构建独立的可执行文件。它主要用于创建 Python 解释器的扩展。
However, there are a couple of other alternatives. If you have a Java interpreter on the target machine, you can run Jython. There's also a IronPythonfor .net. However, you will still have to distribute the runtimes for these languages with your project.
但是,还有其他几种选择。如果目标机器上有 Java 解释器,则可以运行Jython。还有一个用于 .net的IronPython。但是,您仍然需要为您的项目分发这些语言的运行时。
In short, if you want a stand-alone executable with no dependencies, your only option is pretty much to go with straight C or C++.
简而言之,如果您想要一个没有依赖项的独立可执行文件,您唯一的选择几乎是直接使用 C 或 C++。