簡體   English   中英

使用setuptools(pip)時如何打印警告和錯誤

[英]How to print warnings and errors when using setuptools (pip)

我正在使用setuptools打包代碼,以便可以使用以下命令輕松安裝

cd project_name && pip install .

在設置過程中,我想警告用戶有關預先存在的配置文件,並在系統上打印一些安裝后的說明。 例如

/etc/project_name/project.conf exists. Not copying default config file.

我嘗試使用printlogging.warning()但使用pip安裝時仍然沒有出現警告。 我感覺自己缺少明顯的東西。

我們正在嘗試在Redhat系列> = el6和Ubuntu> = 14.04LTS上支持3.0> python> = 2.6

如果您看一下pip源代碼,那么在負責運行安裝腳本的函數call_subprocess此處的源代碼 )中,它說:

def call_subprocess(cmd, show_stdout=True, cwd=None, ...
    ...
    # The obvious thing that affects output is the show_stdout=
    # kwarg. show_stdout=True means, let the subprocess write directly to our
    # stdout. Even though it is nominally the default, it is almost never used
    # inside pip (and should not be used in new code without a very good
    # reason); as of 2016-02-22 it is only used in a few places inside the VCS
    # wrapper code. Ideally we should get rid of it entirely, because it
    # creates a lot of complexity here for a rarely used feature.
    #
    # Most places in pip set show_stdout=False. What this means is:
    # - We connect the child stdout to a pipe, which we read.
    # - By default, we hide the output but show a spinner -- unless the
    #   subprocess exits with an error, in which case we show the output.
    # - If the --verbose option was passed (= loglevel is DEBUG), then we show
    #   the output unconditionally. (But in this case we don't want to show
    #   the output a second time if it turns out that there was an error.)

簡而言之,只有在以下情況下,您才能看到輸出:

  • 您的設置退出並出現錯誤,或者
  • 用戶使用-v (詳細標志)調用pip

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM