33

我希望能够在我的 setup.py 中添加一个钩子,它将在安装后运行(在 easy_install'ing 或 python setup.py 安装时)。

在我的项目PySmell中,我有一些 Vim 和 Emacs 的支持文件。当用户以通常的方式安装 PySmell 时,这些文件会被复制到实际的 egg 中,用户必须将它们取出并将它们放在他的 .vim 或 .emacs 目录中。我想要的是在安装后询问用户,他希望将这些文件复制到哪里,或者甚至只是一条消息,打印文件的位置以及他应该如何处理它们。

做这个的最好方式是什么?

谢谢

我的 setup.py 看起来像这样:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from setuptools import setup

version = __import__('pysmell.pysmell').pysmell.__version__

setup(
    name='pysmell',
    version = version,
    description = 'An autocompletion library for Python',
    author = 'Orestis Markou',
    author_email = 'orestis@orestis.gr',
    packages = ['pysmell'],
    entry_points = {
        'console_scripts': [ 'pysmell = pysmell.pysmell:main' ]
    },
    data_files = [
        ('vim', ['pysmell.vim']),
        ('emacs', ['pysmell.el']),
    ],
    include_package_data = True,
    keywords = 'vim autocomplete',
    url = 'http://code.google.com/p/pysmell',
    long_description =
"""\
PySmell is a python IDE completion helper. 

It tries to statically analyze Python source code, without executing it,
and generates information about a project's structure that IDE tools can
use.

The first target is Vim, because that's what I'm using and because its
completion mechanism is very straightforward, but it's not limited to it.
""",
    classifiers = [
        'Development Status :: 5 - Production/Stable',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Software Development',
        'Topic :: Utilities',
        'Topic :: Text Editors',
    ]


)

编辑:

这是一个演示的存根python setup.py install

from setuptools.command.install import install as _install

class install(_install):
    def run(self):
        _install.run(self)
        print post_install_message

setup(
    cmdclass={'install': install},
    ...

easy_install 路线还没有运气。

4

2 回答 2

8

这取决于用户如何安装您的软件包。如果用户实际运行“setup.py install”,这相当容易:只需在安装命令中添加另一个子命令(例如 install_vim),它的 run() 方法会将您想要的文件复制到您想要的位置。您可以将子命令添加到 install.sub_commands,然后将命令传递给 setup()。

如果您想要二进制文件中的安装后脚本,这取决于您正在创建的二进制文件的类型。例如,bdist_rpm、bdist_wininst 和 bdist_msi 支持安装后脚本,因为底层打包格式支持安装后脚本。

bdist_egg 在设计上不支持安装后机制:

http://bugs.python.org/setuptools/issue41

于 2008-10-31T10:33:46.097 回答
0

作为一种变通方法,您可以将 zip_ok 选项设置为 false,以便将您的项目安装为解压缩目录,然后您的用户将更容易找到编辑器配置文件。

在 distutils2 中,可以将东西安装到更多目录,包括自定义目录,并具有 pre/post-install/remove 挂钩。

于 2011-10-28T15:56:28.713 回答