当前位置:  开发笔记 > 编程语言 > 正文

如何将安装后脚本添加到easy_install/setuptools/distutils?

如何解决《如何将安装后脚本添加到easy_install/setuptools/distutils?》经验,为你挑选了1个好方法。

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



1> Martin v. Lö..:

这取决于用户如何安装您的包.如果用户实际运行"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


"只需在install命令中添加另一个子命令(比如,install_vim)"那怎么做呢?
对于答案,**查看上面_question_的下半部分**.(@ limp-chimp,@ maverick-wolverine)
推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有