33

インストール後に実行される setup.py にフックを追加できるようにしたいと思います (easy_install'ing または python setup.py install を実行するとき)。

私のプロジェクトPySmellには、Vim と Emacs のサポート ファイルがいくつかあります。ユーザーが通常の方法で PySmell をインストールすると、これらのファイルが実際の卵にコピーされるため、ユーザーはそれらを取り出して自分の .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 に答える