通过 Pip 打印来自 setup.py 的消息
Print a message from setup.py through Pip
有什么方法可以让 setup.py 的用户在使用 pip
时看到消息 and/or 警告?
我的包使用自定义安装命令。 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\wheelsfe55517a1e0973939e9578945ff104b6e0193cfaed649e206
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
-v 是详细信息,它显示详细信息。默认关闭。用户不想看到它。如果您将其显示为错误,他们可能会感到困惑,但如果它不是错误而您将其显示为错误,则可能会使他们感到困惑。
Link 如需进一步帮助:How to print warnings and errors when using setuptools (pip)
有什么方法可以让 setup.py 的用户在使用 pip
时看到消息 and/or 警告?
我的包使用自定义安装命令。 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\wheelsfe55517a1e0973939e9578945ff104b6e0193cfaed649e206
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
-v 是详细信息,它显示详细信息。默认关闭。用户不想看到它。如果您将其显示为错误,他们可能会感到困惑,但如果它不是错误而您将其显示为错误,则可能会使他们感到困惑。
Link 如需进一步帮助:How to print warnings and errors when using setuptools (pip)