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

2024/9/20 8:04:30

I am using setuptools to package code such that it can be easily installed using

cd project_name && pip install .

During the setup process, I want to warn the user about pre-existing config files and print some post install instructions on the system. For example

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

I have tried to use print and logging.warning() but still the warnings don't appear when installing using pip. I have a feeling I am missing something obvious.

We are trying to support 3.0 > python >= 2.6 on Redhat family >= el6 and Ubuntu >= 14.04LTS

Answer

If you take a look at the pip source, in the function responsible for running the setup script, call_subprocess (source here), it says:

def call_subprocess(cmd, show_stdout=False, cwd=None, ..."""Args:show_stdout: if true, use INFO to log the subprocess's stderr andstdout 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.

In short, you can see the output only if:

  • your setup exits with an error, or
  • user calls pip with -v, the verbose flag
https://en.xdnf.cn/q/72376.html

Related Q&A

TypeError: not supported between instances of State and State PYTHON 3

I am trying to utilize a PriorityQueue from the queue class. However, im having issues putting custom objects into my PQ. I have implemented the __cmp__ function below:def __cmp__(self, other):return (…

Threading and information passing -- how to

To reframe from confusion i have edited the question:one.pyimport threading count = 5 dev = threading.Thread(name=dev, target=dev,args=(workQueue,count,)) dev.setDaemon(True) dev.start() workQueue = Qu…

How to rename a node with Python LXML?

How do I rename a node using LXML? Specifically, how to rename a parent node i.e. a <body> tag while preserving all the underlying structure? I am parsing using the lxml.html module but suppos…

In python, selenium, how do I set the error messages for a wait?

I have the following code:WebDriverWait(self.driver, 20).until(expected_conditions.element_to_be_clickable(click))Now this sometimes fails and I know why it fails. But the error gives me TimeoutExcept…

Python: the mechanism behind list comprehension

When using list comprehension or the in keyword in a for loop context, i.e:for o in X:do_something_with(o)orl=[o for o in X]How does the mechanism behind in works? Which functions\methods within X do…

PRAW: Comment Submitters Username

Im developing a reddit bot that needs to know which user submitted a comment. According to the PRAW API wrapper docs, theres no specific way to get the username of a Comment objects author. Ideally I c…

Paramiko, exec_command get the output stream continuously [duplicate]

This question already has answers here:Get output from a Paramiko SSH exec_command continuously(6 answers)Closed 2 years ago.I dry on a Python script. I create a python script for a given IP will conne…

pdfminer3k has no method named create_pages in PDFPage

Since I want to move from python 2 to 3, I tried to work with pdfmine.3kr in python 3.4. It seems like they have edited everything. Their change logs do not reflect the changes they have done but I had…

curve fitting zipf distribution matplotlib python

I tried to fit the following plot(red dot) with the Zipf distribution PDF in Python, F~x^(-a). I simply chose a=0.56 and plotted y = x^(-0.56), and I got the curve shown below. The curve is obviously …

Running python/ruby script on iPhone?

From the recent news from the Apple, I learned that one has to use C/C++/Objective-C for iPhone App. Accordingly, its not possible to use MacPython or similar to make iPhone App. But as the python/ruby…