自定义distutils命令 [英] Custom distutils commands

查看:134
本文介绍了自定义distutils命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为example的库,我正在安装到我的全球site-packages目录中。但是,我想要安装两个版本,一个用于生产,一个用于测试(我有一个Web应用程序和其他这些版本的东西)。



有没有办法指定,python setup.py stage不仅会将不同的蛋安装到site-packages中,还可以将模块从example更改为example_stage或类似的东西?



如果distutils不能这样做,还有其他工具可以吗?

解决方案

当然,你可以用新的命令扩展distutils。在您的distutil配置文件中,添加:

  [global] 
command-packages = foo.bar

这可以在 distutils.cfg $ c> distutils 包装本身,您的主目录中的 .. pydistutils.cfg (Windows上没有前导点)或 setup.cfg



然后,您需要在Python的site-packages目录中的foo.bar包。 >

然后在该包中添加实现新的所需命令的类,例如 stage ,将 distutils.cmd - 文档很弱,但有很多例子,因为所有的现有的distutils命令也是这样构建的。


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).

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?

If distutils cannot do this, is there any other tool that can?

解决方案

Sure, you can extend distutils with new commands. In your distutil configuration file, add:

 [global]
 command-packages=foo.bar

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.

Then you need a foo.bar package in your Python's site-packages directory.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆