我希望能夠在我的setup.py中添加一個鉤子,這個鉤子將在安裝後運行(無論是在easy_install或安裝python setup.py時)。如何將安裝後腳本添加到easy_install/setuptools/distutils?
在我的項目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 = '[email protected]',
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路線呢。
我剛剛發現,調用`setuptools.install.install:run()`明確不能解決`install_requires`設置參數,它看起來像它在不同的方式工作,當你這樣做 – astronaut 2013-09-22 13:11:04
@astronaut使用`do_egg_install`,在這裏討論:http://stackoverflow.com/questions/21915469/python-setuptools-install-requires-is-ignored-when-overriding-cmdclass – 2015-03-27 12:57:14