如果你能保证
- 始终从源代码分发包安装软件包,而不是二进制轮,并且
- 用户将
-v 选项用于pip install,
您可以在 setup.py 脚本中输出文本。
setup.py 几乎是一个普通的 Python 脚本。
只需在 setup.py 文件末尾使用 print() 函数即可。
在本例中,文件结构为somedir/setup.py、somedir/test/ 和test/__init__.py。
简单的解决方案
from setuptools import setup
print("Started!")
setup(name='testing',
version='0.1',
description='The simplest setup in the world',
classifiers=[
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.0',
],
keywords='setup',
author='someone',
author_email='someone@example.com',
license='MIT',
packages=['test'],
entry_points={
},
zip_safe=False)
print("Finished!")
开始了!
运行安装
运行 bdist_egg
运行 egg_info
编写 testing.egg-info/PKG-INFO
...
...
...
测试的处理依赖==0.1
完成处理
测试依赖项==0.1
完成!
使用setuptools.command.install解决方案
此外,您可以将setuptools.command.install 命令子类化。在全新设置中更改install.run(self) 和os.system("cat testing.egg-info/PKG-INFO") 的顺序时检查差异。
from setuptools import setup
from setuptools.command.install import install
import os
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
install.run(self)
os.system("cat testing.egg-info/PKG-INFO")
setup(name='testing',
version='0.1',
description='The simplest setup in the world',
classifiers=[
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.0',
],
keywords='setup',
author='someone',
author_email='someone@example.com',
license='MIT',
packages=['test'],
entry_points={
},
cmdclass={
'install': PostInstallCommand,
},
zip_safe=False)