インストール後スクリプトをeasy_install / setuptools / distutilsに追加するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/250038

  •  05-07-2019
  •  | 
  •  

質問

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

私のプロジェクト 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ルートはまだ運がありません。

役に立ちましたか?

解決

ユーザーがパッケージをインストールする方法によって異なります。ユーザーが実際に" setup.py 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では、カスタムディレクトリを含む他のディレクトリにインストールしたり、pre / post-install / removeフックを設定したりできます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top