質問

私が簡単なスクリプト後のモジュールやプログラムが設置されています。んちょっとしたトラブルに見直前の文書をどのよう関係ではないかと思います。うまからは継承しdistutils.コマンドです。インストールし、オーバーライド方法と追加このオブジェクトの設定を記述します。の具体的なビ霞がとうに多くの努力などシンプルなフック。なんだろうけど、日本人にやるのか?

役に立ちましたか?

解決

私は、カスタムコマンドの束を作るためにそれについて十分に学ぶために日のdistutilsのソースから掘りました。それはきれいではありませんが、それは作業を行います。

import distutils.core
from distutils.command.install import install
...
class my_install(install):
    def run(self):
        install.run(self)
        # Custom stuff here
        # distutils.command.install actually has some nice helper methods
        # and interfaces. I strongly suggest reading the docstrings.
...
distutils.core.setup(..., cmdclass=dict(install=my_install), ...)

他のヒント

OK、私はそれを考え出しました。アイデアはdistutilsのコマンドのいずれかを拡張し、runメソッドを上書きすることは基本的です。あなたはcmdclass変数を使用することができる新しいクラスを使用するのdistutilsを教えてます。

from distutils.core import setup
from distutils.command.install_data import install_data

class post_install(install_data):
    def run(self):
        # Call parent 
        install_data.run(self)
        # Execute commands
        print "Running"

setup(name="example",
      cmdclass={"install_data": post_install},
      ...
      )

これは他の誰かを助けることを願っています。

いず ジョー Wreschnigs答え作業を調整えに類似の拡大にともなうdistutils 文書.またこのコードを動作っ機です。

from distutils import core
from distutils.command.install import install
...
class my_install(install):
    def run(self):
        install.run(self)
        # Custom stuff here
        # distutils.command.install actually has some nice helper methods
        # and interfaces. I strongly suggest reading the docstrings.
...
distutils.core.setup(..., cmdclass={'install': my_install})

注意:僕の編集回答のジョーさんも多いので不確実なぜ彼の答えが悪かったです私の機です。

私は(私は確信して、この特定のケースではPython 2.6を使用していないだからかもしれません)、ここで受け入れ答えをしようとしたとき、

私はエラーを得ました。これは、 'setup.py installを' と 'インストールPIP' の両方のために発生します:

sudo python setup.py install
setup.cfgでエラー:

がエラーで失敗するコマンド 'my_install' はそのようなオプションを持っていない 'single_version_externally_managed'

sudo pip install . -U

は、より冗長に失敗しただけでなく、のエラーで:オプションは--single-バージョン - 外部管理

は認識されません

受け入れ答えのバリエーション

のdistutilsからの輸入を置き換えるのとのsetuptoolsのの私のための問題を解決します:

from setuptools import setup
from setuptools.command.install import install
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top