【发布时间】:2020-01-29 11:09:29
【问题描述】:
当用户使用pip 时,有什么方法可以让 setup.py 中的消息和/或警告对用户可见?
我的包使用自定义安装命令。 setup.py的结构是这样的:
from setuptools import setup
from setuptools.command.install import install
import warnings
import sys
class CustomInstallCommand(install):
def run(self):
install.run(self)
sys.stdout.write('My message.\n')
sys.stdout.flush()
warnings.warn('My warning.', UserWarning)
setup(name='blub',
version='0.1',
description='blah',
packages=['blub'],
cmdclass={'install': CustomInstallCommand})
当我运行 python setup.py install 时,我会在输出中看到自定义打印消息和警告。
但是,如果我运行 pip install .,我只会得到这个:
C:\Users\ae\Software\SomeModule>pip install .
Processing c:\users\ae\software\somemodule
Building wheels for collected packages: blub
Building wheel for blub (setup.py) ... done
Created wheel for blub: filename=blub-0.1-cp37-none-any.whl size=1115 sha256=51c91c5b449673e3be5dd7382cd12f59cb38021167ba3a0b3634214419c61bcb
Stored in directory: C:\Users\ae\AppData\Local\Temp\pip-ephem-wheel-cache-575zecpf\wheels\81\5f\73\46e55517a1e0973939e9578945ff104b6e0193cfaed649e206
Successfully built blub
Installing collected packages: blub
Found existing installation: blub 0.1
Uninstalling blub-0.1:
Successfully uninstalled blub-0.1
Successfully installed blub-0.1
【问题讨论】:
-
试试:
pip install . -v -
@Alper 谢谢!这确实允许该消息。所以我想,没有
-v标志是不可能的吗?问题是,我无法控制用户是否使用-v... -
如果您发布轮子(这是目前首选的分发格式)
pip在构建时运行setup.py,但在安装时不运行setup.py。所以无论如何你都不走运,-v与否。 -
@AmosEgel 我在下面的答案中回答您的问题。如果我的解决方案对您有用,那么您应该将我的解决方案签署为已解决。
-
@AmosEgel 似乎没有任何可能的方式来做你真正想做的事情。
标签: python pip warnings setuptools