From 5d4acac9946f66d025d67bf37086e2f612659b6a Mon Sep 17 00:00:00 2001 From: bwoodsend Date: Sun, 16 Jan 2022 16:13:31 +0000 Subject: [PATCH] BUG: Avoid importing numpy.distutils on import numpy.testing (#20769) Move the offending imports into the functions that use them so that numpy.distutils is only loaded if those functions are required. --- numpy/testing/_private/extbuild.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpy/testing/_private/extbuild.py b/numpy/testing/_private/extbuild.py index 20bf3dceac02..fc39163953d9 100644 --- a/numpy/testing/_private/extbuild.py +++ b/numpy/testing/_private/extbuild.py @@ -8,8 +8,6 @@ import pathlib import sys import sysconfig -from numpy.distutils.ccompiler import new_compiler -from distutils.errors import CompileError __all__ = ['build_and_import_extension', 'compile_extension_module'] @@ -53,6 +51,7 @@ def build_and_import_extension( >>> assert not mod.test_bytes(u'abc') >>> assert mod.test_bytes(b'abc') """ + from distutils.errors import CompileError body = prologue + _make_methods(functions, modname) init = """PyObject *mod = PyModule_Create(&moduledef); @@ -221,6 +220,7 @@ def _c_compile(cfile, outputfilename, include_dirs=[], libraries=[], def build(cfile, outputfilename, compile_extra, link_extra, include_dirs, libraries, library_dirs): "cd into the directory where the cfile is, use distutils to build" + from numpy.distutils.ccompiler import new_compiler compiler = new_compiler(force=1, verbose=2) compiler.customize('')