自定义 distutils 命令 [英] Custom distutils commands
问题描述
我有一个名为example"的库,我将它安装到我的全局站点包目录中.但是,我希望能够安装两个版本,一个用于生产,一个用于测试(我有一个网络应用程序和其他以这种方式进行版本控制的东西).
I have a library called "example" that I'm installing into my global site-packages directory. However, I'd like to be able to install two versions, one for production and one for testing (I have a web application and other things that are versioned this way).
有没有办法指定,比如python setup.py stage",它不仅可以将不同的 egg 安装到站点包中,还可以将模块从example"重命名为example_stage"或类似的东西?
Is there a way to specify, say "python setup.py stage" that will not only install a different egg into site-packages, but also rename the module from "example" to "example_stage" or something similar?
如果 distutils 不能做到这一点,有没有其他工具可以做到这一点?
If distutils cannot do this, is there any other tool that can?
推荐答案
当然,您可以使用新命令扩展 distutils.在您的 distutil 配置文件中,添加:
Sure, you can extend distutils with new commands. In your distutil configuration file, add:
[global]
command-packages=foo.bar
这可以在 distutils
包本身的 distutils.cfg
中,..pydistutils.cfg
在你的主目录中(没有前导点在 Windows 上),或当前目录中的 setup.cfg
.
this can be in distutils.cfg
in the distutils
package itself, ..pydistutils.cfg
in your home directory (no leading dot on Windows), or setup.cfg
in the current directory.
那么你需要在你的 Python 的 site-packages 目录中有一个 foo.bar 包.
Then you need a foo.bar package in your Python's site-packages directory.
然后在该包中添加实现新所需命令的类,例如 stage
,子类化 distutils.cmd -- 文档很弱,但有很多例子,因为所有现有的 distutils 命令也是这样构建的.
Then in that package you add the classes implementing your new desired commands, such as stage
, subclassing distutils.cmd -- the docs are weak, but there are plenty of examples since all the existing distutils commands are also built that way.
这篇关于自定义 distutils 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!