如何使用简单的安装后脚本扩展distutils? [英] How to extend distutils with a simple post install script?

查看:83
本文介绍了如何使用简单的安装后脚本扩展distutils?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装模块和程序之后,我需要运行一个简单的脚本。
我在查找有关如何执行此操作的直接文档方面遇到了一些麻烦。看来我需要从distutils.command.install继承,重写某些方法,然后将此对象添加到安装脚本中。虽然细节有些模糊,但是对于这样一个简单的钩子似乎需要付出很多努力。有人知道这样做的简单方法吗?

I need to run a simple script after the modules and programs have been installed. I'm having a little trouble finding straight-forward documentation on how to do this. It looks like I need to inherit from distutils.command.install, override some methods and add this object to the setup script. The specifics are a bit hazy though and it seems like a lot of effort for such a simple hook. Does anyone know an easy way to do this?

推荐答案

我花了一天时间浏览distutils源,以了解足够的信息来制作一堆自定义命令。

I dug through distutils source for a day to learn enough about it to make a bunch of custom commands. It's not pretty, but it does work.

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

这篇关于如何使用简单的安装后脚本扩展distutils?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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