8000 MAINT: use sysconfig not distutils.sysconfig where possible by mattip · Pull Request #17223 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: use sysconfig not distutils.sysconfig where possible #17223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from numpy.distutils import log
from distutils.dep_util import newer
from distutils.sysconfig import get_config_var
from sysconfig import get_config_var
from numpy.compat import npy_load_module
from setup_common import * # noqa: F403

Expand Down
2 changes: 1 addition & 1 deletion numpy/distutils/fcompiler/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_flags_opt(self):

def _c_arch_flags(self):
""" Return detected arch flags from CFLAGS """
from distutils import sysconfig
import sysconfig
try:
cflags = sysconfig.get_config_vars()['CFLAGS']
except KeyError:
Expand Down
4 changes: 2 additions & 2 deletions numpy/distutils/misc_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import multiprocessing
import textwrap

import distutils
import sysconfig
from distutils.errors import DistutilsError
try:
from threading import local as tlocal
Expand Down Expand Up @@ -661,7 +661,7 @@ def get_shared_lib_extension(is_python_ext=False):
Linux, but not on OS X.

"""
confvars = distutils.sysconfig.get_config_vars()
confvars = sysconfig.get_config_vars()
# SO is deprecated in 3.3.1, use EXT_SUFFIX instead
so_ext = confvars.get('EXT_SUFFIX', None)
if so_ext is None:
Expand Down
15 changes: 8 additions & 7 deletions numpy/distutils/system_info.py
< 8000 td class="blob-num blob-num-deletion empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@

from distutils.errors import DistutilsError
from distutils.dist import Distribution
import distutils.sysconfig
import sysconfig
from numpy.distutils import log
from distutils.util import get_platform

Expand All @@ -187,6 +187,7 @@
import tempfile
import shutil

__all__ = ['system_info']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was missing an __all__, so it was re-exporting imported modules.


# Determine number of bits
import platform
Expand Down Expand Up @@ -255,7 +256,7 @@ def libpaths(paths, bits):

if sys.platform == 'win32':
default_lib_dirs = ['C:\\',
os.path.join(distutils.sysconfig.EXEC_PREFIX,
os.path.join(sysconfig.EXEC_PREFIX,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeError: module 'sysconfig' has no attribute 'EXEC_PREFIX'

'libs')]
default_runtime_dirs = []
default_include_dirs = []
Expand Down Expand Up @@ -2498,13 +2499,13 @@ def __init__(self):
except AttributeError:
pass

include_dirs.append(distutils.sysconfig.get_python_inc(
include_dirs.append(distutils.get_python_inc(
prefix=os.sep.join(prefix)))
except ImportError:
pass
py_incl_dir = distutils.sysconfig.get_python_inc()
py_incl_dir = sysconfig.get_python_inc()
include_dirs.append(py_incl_dir)
py_pincl_dir = distutils.sysconfig.get_python_inc(plat_specific=True)
py_pincl_dir = sysconfig.get_python_inc(plat_specific=True)
if py_pincl_dir not in include_dirs:
include_dirs.append(py_pincl_dir)
for d in default_include_dirs:
Expand Down Expand Up @@ -2631,8 +2632,8 @@ def calc_info(self):
break
if not src_dir:
return
py_incl_dirs = [distutils.sysconfig.get_python_inc()]
py_pincl_dir = distutils.sysconfig.get_python_inc(plat_specific=True)
py_incl_dirs = [sysconfig.get_python_inc()]
py_pincl_dir = sysconfig.get_python_inc(plat_specific=True)
if py_pincl_dir not in py_incl_dirs:
py_incl_dirs.append(py_pincl_dir)
srcs_dir = os.path.join(src_dir, 'libs', 'python', 'src')
Expand Down
3 changes: 2 additions & 1 deletion numpy/distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts
self.compiler_so = ccomp
# ensure OPT environment variable is read
if 'OPT' in os.environ:
from distutils.sysconfig import get_config_vars
# XXX who uses this?
from sysconfig import get_config_vars
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is OPT ever used?

opt = " ".join(os.environ['OPT'].split())
gcv_opt = " ".join(get_config_vars('OPT')[0].split())
ccomp_s = " ".join(self.compiler_so)
Expand Down
12 changes: 0 additions & 12 deletions numpy/tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,6 @@ def test_all_modules_are_expected():
SKIP_LIST_2 = [
'numpy.math',
'numpy.distutils.log.sys',
'numpy.distutils.system_info.copy',
'numpy.distutils.system_info.distutils',
'numpy.distutils.system_info.log',
'numpy.distutils.system_info.os',
'numpy.distutils.system_info.platform',
'numpy.distutils.system_info.re',
'numpy.distutils.system_info.shutil',
'numpy.distutils.system_info.subprocess',
'numpy.distutils.system_info.sys',
'numpy.distutils.system_info.tempfile',
'numpy.distutils.system_info.textwrap',
'numpy.distutils.system_info.warnings',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that system_info has an __all__, these can be removed.

'numpy.doc.constants.re',
'numpy.doc.constants.textwrap',
'numpy.lib.emath',
Expand Down
6 changes: 3 additions & 3 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def build_project(args):

"""

import distutils.sysconfig
import sysconfig

root_ok = [os.path.exists(os.path.join(ROOT_DIR, fn))
for fn in PROJECT_ROOT_FILES]
Expand All @@ -388,7 +388,7 @@ def build_project(args):

# Always use ccache, if installed
env['PATH'] = os.pathsep.join(EXTRA_PATH + env.get('PATH', '').split(os.pathsep))
cvars = distutils.sysconfig.get_config_vars()
cvars = sysconfig.get_config_vars()
compiler = env.get('CC') or cvars.get('CC', '')
if 'gcc' in compiler:
# Check that this isn't clang masquerading as gcc.
Expand Down Expand Up @@ -445,7 +445,7 @@ def build_project(args):
os.makedirs(site_dir)
if not os.path.exists(site_dir_noarch):
os.makedirs(site_dir_noarch)
env['PYTHONPATH'] = site_dir + ':' + site_dir_noarch
env['PYTHONPATH'] = site_dir + os.pathsep + site_dir_noarch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mistake makes me suspicious - do we really need to set PYTHONPATH here? It is done correctly before running tests.


log_filename = os.path.join(ROOT_DIR, 'build.log')

Expand Down
0