pyodide / micropip

A lightweight Python package installer for Pyodide
https://micropip.pyodide.org
Mozilla Public License 2.0
68 stars 16 forks source link

How to suppress console messages from `micropip.install()`? #100

Open seanpk opened 3 months ago

seanpk commented 3 months ago

When I do micropip.install(module) I get messages about the dependencies that are being pulled with it.

E.g.,:

micropip.install('ezdxf')

will print this to console:

Loading typing-extensions, fonttools, numpy, pyparsing
Loaded fonttools, numpy, pyparsing, typing-extensions

I have tried surrounding the call to install with a no-op stdout function, i.e.:

pyodide.setStdout({ batched: () => {} })
micropip.install('ezdxf')
pyodide.setStdout()

but this doesn't change anything.

How can I suppress these messages?

ryanking13 commented 3 months ago

Thanks for the report! The message occurs in pyodide.loadPackage (which is used internally by micropip). When calling pyodide.loadPackage directly, you can pass the messageCallback parameter, but there is currently no way to do so in micropip.install.

I think the correct behavior is that setting pyodide.setStdout should also change the stream that pyodide.loadPackage outputs, so this is a bug.

For now, you can suppress the message by re-defining console.log

originalConsoleLog = console.log
console.log = () => {}
micropip.install('ezdxf')
console.log = originalConsoleLog
hoodmane commented 3 months ago

setting pyodide.setStdout should also change the stream that pyodide.loadPackage outputs

Could someone open a Pyodide issue for this? While we're at it, maybe we should add a JS API to write to pyodide stdout/stderr.