我希望能够在我的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路线。

有帮助吗?

解决方案

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

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

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

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

其他提示

作为解决方法,您可以将zip_ok选项设置为false,以便将项目安装为解压缩目录,这样您的用户就可以更轻松地找到编辑器配置文件。

在distutils2中,可以将东西安装到更多目录,包括自定义目录,以及安装前/后安装/删除钩子。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top