问题描述
我正在开发一个需要在远程服务器上安装distutils软件包的扩展脚本。
I'm working on a buildout script that needs to install a distutils package on remote server.
在PyPi上有2种方法来完成此
。
On PyPi there are 2 recipes for doing thiscollective.recipe.distutils 0.1 and zerokspot.recipe.distutils 0.1.1.
后面的模块是前者的派生工具,比第一个模块方便一些,但是两者都具有相同的缺点问题,我现在将对其进行描述。
The later module a derivative of the former, and is a little more convenient then the first, but the both suffer from the same problem, which I will describe now.
执行bootstrap.py时,它将下载zc.buildout软件包并将其放入buildout的eggs目录中。这使./bin/buildout可以访问zc.buildout代码,但是/ usr / local / python此时不了解zc.buildout。
When bootstrap.py is executed, it downloads zc.buildout package and puts it into buildout's eggs directory. This gives ./bin/buildout access to zc.buildout code, but /usr/local/python does not know anything about zc.buildout at this point.
Buildout提示通过在子进程内运行 python setup.py install来安装软件包。这会产生ImportError,因为未为/ usr / local / python安装zc.buildout。
Buildout attepts to install the package by running 'python setup.py install' inside of a subprocess. This produces an ImportError because zc.buildout is not installed for /usr/local/python.
因此,我有几种解决方案。
So, I have several solutions.
-
使用easy_install在远程服务器上安装zc.buildout。我一点都不喜欢这个选项,它为一个非常微不足道的模块提供了特殊情况。
Install zc.buildout using easy_install on the remote server. I don't like this option at all, it makes a special case for a module that is very insignificant.
修改zerokspot.recipe.distutils进行尝试以这种方式阻止 import zc.buildout,即使未安装zc.buildout也会安装。不错的解决方案,但有点黑。
Modify zerokspot.recipe.distutils to put try block around 'import zc.buildout' this way, it will install even if zc.buildout is not installed. It's an ok solution, but somewhat hackish.
用代码替换子进程,该代码将使用distutils api或setuptools api安装软件包。我认为这将是最好的解决方案。
Replace subprocess with code that will install the package using distutils api or setuptools api. This would be the best solution in my opinion.
问题是我该怎么做#3?
The question is how would i do #3?
谢谢,
Taras
Thank you,Taras
PS:我通过创建另一个没有依赖性的软件包解决了这个问题在zc.buildout上。我的程序包名为,可在pypi上使用。 / p>
PS: I solved the problem by creating another package that does not have dependancy on zc.buildout. My package is called taras.recipe.distutils and it's available on pypi.
推荐答案
zerokspot.recipe.distutils从根本上被破坏了,因为它在setup.py中添加了对zc.buildout的依赖,如下所示:
zerokspot.recipe.distutils is fundamentally broken in that it adds a dependency on zc.buildout in it's setup.py, as follows:
-
setup.py
导入get_version
来自zerokspot.recipe.distutils
- 所有
zerokspot.recipe.distutils
在它的__ init __。py
中定义,包括get_version
-
__ init __。py
在zerokspot.recipe.distutils
进口zc.buildout
setup.py
importsget_version
fromzerokspot.recipe.distutils
- All of
zerokspot.recipe.distutils
is defined in it's__init__.py
, includingget_version
__init__.py
inzerokspot.recipe.distutils
importszc.buildout
为什么作者定义 get_version
对我来说是个谜;最佳做法是在 setup.py
本身中保留一个简单的版本字符串,并让setuptools处理开发版本(通过 setup.cfg
)以及用于版本元数据提取的distutils。
Why the author defines get_version
is a mystery to me; best practice keeps a simple version string in setup.py
itself and lets setuptools deal with dev versions (through setup.cfg
), and distutils for version metadata extraction.
通常,将整个包导入 setup.py $ c中不是一个好主意。 $ c>,因为这将要求所有软件包依赖项都在安装时出现。显然,该软件包的作者已将zc.buildout安装为站点范围的软件包,并且没有注意到他的疏忽。
Generally it is not a good idea to import the whole package in setup.py
as that would require all the package dependencies to be present at install time. Obviously the author of the package has zc.buildout installed as a site-wide package and didn't notice his oversight.
您最好的选择是将该软件包分叉到github上,删除get_version依赖项,然后在使用fork时向原始作者提出更改。
Your best bet is to fork the package on github, remove the get_version dependency, and propose the change to the original author while you use your fork instead.
这篇关于如何使用distutils api或setuptools api安装distutils软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!