[英]python setup.py - how to show message after install
我正在开发 PyQt5 应用程序并通过pip install
使其可用,因为 python3 中的 pip 可以安装 pyqt5 作为依赖项。 我创建了一个入口点来启动我的包,并告诉 setup.py 它是一个 gui_scripts。
我现在想做的是,在用户输入pip install package
并且安装完成后,向用户显示一条消息,告诉您现在可以在终端中输入package
来加载应用程序。 这样做的正确方法是什么? 或者我不应该这样做?
如果你能确保
-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)
另一种选择是日志记录模块。
例如rasterio使用这样的方法,您可以根据自己的需要进行调整:
import logging
import sys
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
log = logging.getLogger()
...
log.info("Your message")
sys.stderr
将由 pip 打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.