BUG: `numpy.distutils.system_info.get_info("blas_opt")` has unsuppressable stdout side effects
See original GitHub issueDescribe the issue:
Aesara uses numpy.distutils.system_info.get_info("blas_opt")
to obtain some compiler settings upon import.
However, every this prints the GCC configuration to stdout
which is incredibly annoying.
We tried to capture/suppress the stdout/stderr
output (see below), but it doesn’t work.
Related issues/PRs:
- https://github.com/conda-forge/aesara-feedstock/issues/54
- https://github.com/aesara-devs/aesara/issues/1005
- https://github.com/aesara-devs/aesara/pull/980
Reproduce the code example:
from contextlib import redirect_stderr, redirect_stdout
import io
import sys
import numpy.distutils.system_info
class NumpyCompatibleStdoutStringIO(io.StringIO):
"""Used as a temporary replacement of sys.stdout to capture Numpy's output.
We want to simply use io.StringIO, but this doesn't work because
Numpy expects the .encoding attribute to be a string. For io.StringIO,
this attribute is set to None and cannot be modified, hence the need for
this subclass.
(See forward_bytes_to_stdout in numpy.distutils.exec_command.)
"""
encoding = sys.stdout.encoding
# Neither of the following two work:
# stdout_sio, stderr_sio = io.StringIO(), io.StringIO()
stdout_sio, stderr_sio = NumpyCompatibleStdoutStringIO(), NumpyCompatibleStdoutStringIO()
with redirect_stdout(stdout_sio), redirect_stderr(stderr_sio):
numpy.distutils.system_info.get_info("blas_opt")
Error message:
No error, but unwanted stdout:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/Users/osthege/AppData/Local/Continuum/miniconda3/envs/pm3v4/Library/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-5.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --with-gxx-include-dir=/mingw64/include/c++/5.3.0 --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 5.3.0 (Rev5, Built by MSYS2 project)
NumPy/Python version information:
1.19.2 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)]
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, Windows only and probably a regression of some sort.
Thanks for the code pointer. I’ll investigate and attempt to fix tomorrow!
@rgommers I opened a PR here: https://github.com/numpy/numpy/pull/21959