如何子类化构建命令? [英] How do I subclass the build command?
问题描述
主题是不言自明的:我需要对 setup.py build
命令进行子类化以执行额外的构建步骤.但是我没有找到任何要继承的 build
命令类.我一直在努力:
The subject is self-descriptive: I need to subclass the setup.py build
command in order to perform additional build steps. However I've failed to find any build
command class to inherit from. I've been trying:
class BuildCommandProxy(setuptools.command.build):
pass
和
class BuildCommandProxy(distutils.command.build):
pass
甚至:
class BuildCommandProxy(setuptools.distutils.command.build):
pass
没有任何成功.
更新:寻找如何使用setuptools<实现this之类的东西/代码>.
UPDATE: looking for how to implement something like this with setuptools
.
UPDATE2:我有一些自定义命令实现:
UPDATE2: I have some custom command implementation:
class CustomCommand(setuptools.Command):
# ...
我想要实现的是将这个命令传递给 cmdclass
像这样:
What I would like to implement is to pass this command to cmdclass
like this:
cmdclass={
"build": CustomCommand,
}
然后在执行一些自定义步骤后调用 CustomCommand.run
中的原始 build
.
and then invoke the original build
in CustomCommand.run
after doing some custom steps.
推荐答案
Setuptools 不会覆盖 distutils
build
命令本身;只有 build_py
和 build_ext
子命令.
Setuptools does not override the distutils
build
command itself; only the build_py
and build_ext
subcommands.
因此,要创建自己的子类,您需要从 distutils.command.build
module 导入,其中包含一个 build
类(Command
) 的子类:
So, to create your own subclass you need to import from the distutils.command.build
module, which contains a build
class (subclass of Command
):
import distutils.command.build
class BuildCommandProxy(distutils.command.build.build):
pass
这篇关于如何子类化构建命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!