我正在使用 setuptools 来打包代码,以便可以使用以下命令轻松安装它
cd project_name && pip install .
在设置过程中,我想警告用户有关预先存在的配置文件的信息,并在系统上打印一些安装后说明。例如
/etc/project_name/project.conf exists. Not copying default config file.
我尝试过使用print
and logging.warning()
但使用 pip 安装时仍然不会出现警告。我有一种感觉,我错过了一些明显的东西。
我们正在尝试在 Redhat 系列 >= el6 和 Ubuntu >= 14.04LTS 上支持 3.0 > python >= 2.6
如果您查看 pip 源代码,在负责运行设置脚本的函数中,call_subprocess
(来源在这里 https://github.com/pypa/pip/blob/main/src/pip/_internal/utils/subprocess.py#L71), 它说:
def call_subprocess(cmd, show_stdout=False, cwd=None, ...
"""
Args:
show_stdout: if true, use INFO to log the subprocess's stderr and
stdout streams. Otherwise, use DEBUG. Defaults to False.
...
"""
...
# Most places in pip use show_stdout=False. What this means is--
#
# - We connect the child's output (combined stderr and stdout) to a
# single pipe, which we read.
# - We log this output to stderr at DEBUG level as it is received.
# - If DEBUG logging isn't enabled (e.g. if --verbose logging wasn't
# requested), then we show a spinner so the user can still see the
# subprocess is in progress.
# - If the subprocess exits with an error, we log the output to stderr
# at ERROR level if it hasn't already been displayed to the console
# (e.g. if --verbose logging wasn't enabled). This way we don't log
# the output to the console twice.
#
# If show_stdout=True, then the above is still done, but with DEBUG
# replaced by INFO.
简而言之,只有在以下情况下您才能看到输出:
- 您的设置因错误而退出,或者
- 用户调用 pip
-v
,详细标志
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)