安装模块和程序后,我需要运行一个简单的脚本。
我在寻找有关如何执行此操作的直接文档时遇到了一些麻烦。看来我需要继承 distutils.command.install,重写一些方法并将此对象添加到安装脚本中。但具体细节有点模糊,对于这样一个简单的钩子来说似乎需要付出很大的努力。有谁知道一个简单的方法来做到这一点?
我花了一天的时间研究了 distutils 源代码,了解了足够的知识来制作一堆自定义命令。它不漂亮,但确实有效。
import distutils.core
from distutils.command.install import install
...
class my_install(install):
def run(self):
install.run(self)
# Custom stuff here
# distutils.command.install actually has some nice helper methods
# and interfaces. I strongly suggest reading the docstrings.
...
distutils.core.setup(..., cmdclass=dict(install=my_install), ...)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)