summaryrefslogtreecommitdiff
path: root/numpy/distutils
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-15 17:03:58 -0800
committerSeth Troisi <sethtroisi@google.com>2020-01-20 15:22:57 -0800
commit9a21ec857b22ff0140a7f71a12f2cc943f163404 (patch)
tree1f8b26a1bb346fab26d2210de286d29011bf2bf1 /numpy/distutils
parentb753aa7a3a2c958e70826fb8af3b56db5c758819 (diff)
downloadnumpy-9a21ec857b22ff0140a7f71a12f2cc943f163404.tar.gz
[MAINT] Cleanup python2 sys.version checks
Diffstat (limited to 'numpy/distutils')
-rw-r--r--numpy/distutils/ccompiler.py8
-rw-r--r--numpy/distutils/cpuinfo.py10
-rw-r--r--numpy/distutils/exec_command.py14
-rw-r--r--numpy/distutils/fcompiler/gnu.py3
-rw-r--r--numpy/distutils/log.py8
-rw-r--r--numpy/distutils/mingw32ccompiler.py6
-rw-r--r--numpy/distutils/misc_util.py5
-rw-r--r--numpy/distutils/npy_pkg_config.py5
-rw-r--r--numpy/distutils/system_info.py59
-rw-r--r--numpy/distutils/unixccompiler.py6
10 files changed, 37 insertions, 87 deletions
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py
index 35cf9df81..ea7912feb 100644
--- a/numpy/distutils/ccompiler.py
+++ b/numpy/distutils/ccompiler.py
@@ -271,12 +271,8 @@ def CCompiler_compile(self, sources, output_dir=None, macros=None,
if not sources:
return []
- # FIXME:RELATIVE_IMPORT
- if sys.version_info[0] < 3:
- from .fcompiler import FCompiler, is_f_file, has_f90_header
- else:
- from numpy.distutils.fcompiler import (FCompiler, is_f_file,
- has_f90_header)
+ from numpy.distutils.fcompiler import (FCompiler, is_f_file,
+ has_f90_header)
if isinstance(self, FCompiler):
display = []
for fc in ['f77', 'f90', 'fix']:
diff --git a/numpy/distutils/cpuinfo.py b/numpy/distutils/cpuinfo.py
index efea90113..e066f9888 100644
--- a/numpy/distutils/cpuinfo.py
+++ b/numpy/distutils/cpuinfo.py
@@ -17,10 +17,7 @@ __all__ = ['cpu']
import sys, re, types
import os
-if sys.version_info[0] >= 3:
- from subprocess import getstatusoutput
-else:
- from commands import getstatusoutput
+from subprocess import getstatusoutput
import warnings
import platform
@@ -484,10 +481,7 @@ class Win32CPUInfo(CPUInfoBase):
info = []
try:
#XXX: Bad style to use so long `try:...except:...`. Fix it!
- if sys.version_info[0] >= 3:
- import winreg
- else:
- import _winreg as winreg
+ import winreg
prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py
index d35b4f898..fb10d2470 100644
--- a/numpy/distutils/exec_command.py
+++ b/numpy/distutils/exec_command.py
@@ -74,10 +74,6 @@ def filepath_from_subprocess_output(output):
# Another historical oddity
if output[-1:] == '\n':
output = output[:-1]
- # stdio uses bytes in python 2, so to avoid issues, we simply
- # remove all non-ascii characters
- if sys.version_info < (3, 0):
- output = output.encode('ascii', errors='replace')
return output
@@ -89,10 +85,7 @@ def forward_bytes_to_stdout(val):
The assumption is that the subprocess call already returned bytes in
a suitable encoding.
"""
- if sys.version_info.major < 3:
- # python 2 has binary output anyway
- sys.stdout.write(val)
- elif hasattr(sys.stdout, 'buffer'):
+ if hasattr(sys.stdout, 'buffer'):
# use the underlying binary output if there is one
sys.stdout.buffer.write(val)
elif hasattr(sys.stdout, 'encoding'):
@@ -305,11 +298,6 @@ def _exec_command(command, use_shell=None, use_tee = None, **env):
if text[-1:] == '\n':
text = text[:-1]
- # stdio uses bytes in python 2, so to avoid issues, we simply
- # remove all non-ascii characters
- if sys.version_info < (3, 0):
- text = text.encode('ascii', errors='replace')
-
if use_tee and text:
print(text)
return proc.returncode, text
diff --git a/numpy/distutils/fcompiler/gnu.py b/numpy/distutils/fcompiler/gnu.py
index 4fc9f33ff..128e54db3 100644
--- a/numpy/distutils/fcompiler/gnu.py
+++ b/numpy/distutils/fcompiler/gnu.py
@@ -412,8 +412,7 @@ class Gnu95FCompiler(GnuFCompiler):
break
h.update(block)
text = base64.b32encode(h.digest())
- if sys.version_info[0] >= 3:
- text = text.decode('ascii')
+ text = text.decode('ascii')
return text.rstrip('=')
def _link_wrapper_lib(self, objects, output_dir, extra_dll_dir,
diff --git a/numpy/distutils/log.py b/numpy/distutils/log.py
index ec1100b1b..79eec00a6 100644
--- a/numpy/distutils/log.py
+++ b/numpy/distutils/log.py
@@ -4,12 +4,8 @@ from distutils.log import *
from distutils.log import Log as old_Log
from distutils.log import _global_log
-if sys.version_info[0] < 3:
- from .misc_util import (red_text, default_text, cyan_text, green_text,
- is_sequence, is_string)
-else:
- from numpy.distutils.misc_util import (red_text, default_text, cyan_text,
- green_text, is_sequence, is_string)
+from numpy.distutils.misc_util import (red_text, default_text, cyan_text,
+ green_text, is_sequence, is_string)
def _fix_args(args,flag=1):
diff --git a/numpy/distutils/mingw32ccompiler.py b/numpy/distutils/mingw32ccompiler.py
index e2cd1c19b..475f73718 100644
--- a/numpy/distutils/mingw32ccompiler.py
+++ b/numpy/distutils/mingw32ccompiler.py
@@ -15,11 +15,7 @@ import textwrap
# Overwrite certain distutils.ccompiler functions:
import numpy.distutils.ccompiler
-
-if sys.version_info[0] < 3:
- from . import log
-else:
- from numpy.distutils import log
+from numpy.distutils import log
# NT stuff
# 1. Make sure libpython<version>.a exists for gcc. If not, build it.
# 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py
index eec8d56a3..f9d2be716 100644
--- a/numpy/distutils/misc_util.py
+++ b/numpy/distutils/misc_util.py
@@ -2242,10 +2242,7 @@ def get_info(pkgname, dirs=None):
return info
def is_bootstrapping():
- if sys.version_info[0] >= 3:
- import builtins
- else:
- import __builtin__ as builtins
+ import builtins
try:
builtins.__NUMPY_SETUP__
diff --git a/numpy/distutils/npy_pkg_config.py b/numpy/distutils/npy_pkg_config.py
index 47965b4ae..26a0437fb 100644
--- a/numpy/distutils/npy_pkg_config.py
+++ b/numpy/distutils/npy_pkg_config.py
@@ -2,10 +2,7 @@ import sys
import re
import os
-if sys.version_info[0] < 3:
- from ConfigParser import RawConfigParser
-else:
- from configparser import RawConfigParser
+from configparser import RawConfigParser
__all__ = ['FormatError', 'PkgNotFound', 'LibraryInfo', 'VariableSet',
'read_config', 'parse_flags']
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py
index 6a69fed59..f0641a688 100644
--- a/numpy/distutils/system_info.py
+++ b/numpy/distutils/system_info.py
@@ -138,12 +138,8 @@ import textwrap
from glob import glob
from functools import reduce
-if sys.version_info[0] < 3:
- from ConfigParser import NoOptionError
- from ConfigParser import RawConfigParser as ConfigParser
-else:
- from configparser import NoOptionError
- from configparser import RawConfigParser as ConfigParser
+from configparser import NoOptionError
+from configparser import RawConfigParser as ConfigParser
# It seems that some people are importing ConfigParser from here so is
# good to keep its class name. Use of RawConfigParser is needed in
# order to be able to load path names with percent in them, like
@@ -264,32 +260,29 @@ if sys.platform == 'win32':
default_include_dirs.extend(
os.path.join(library_root, d) for d in _include_dirs)
- if sys.version_info >= (3, 3):
- # VCpkg is the de-facto package manager on windows for C/C++
- # libraries. If it is on the PATH, then we append its paths here.
- # We also don't re-implement shutil.which for Python 2.7 because
- # vcpkg doesn't support MSVC 2008.
- vcpkg = shutil.which('vcpkg')
- if vcpkg:
- vcpkg_dir = os.path.dirname(vcpkg)
- if platform.architecture() == '32bit':
- specifier = 'x86'
- else:
- specifier = 'x64'
-
- vcpkg_installed = os.path.join(vcpkg_dir, 'installed')
- for vcpkg_root in [
- os.path.join(vcpkg_installed, specifier + '-windows'),
- os.path.join(vcpkg_installed, specifier + '-windows-static'),
- ]:
- add_system_root(vcpkg_root)
-
- # Conda is another popular package manager that provides libraries
- conda = shutil.which('conda')
- if conda:
- conda_dir = os.path.dirname(conda)
- add_system_root(os.path.join(conda_dir, '..', 'Library'))
- add_system_root(os.path.join(conda_dir, 'Library'))
+ # VCpkg is the de-facto package manager on windows for C/C++
+ # libraries. If it is on the PATH, then we append its paths here.
+ vcpkg = shutil.which('vcpkg')
+ if vcpkg:
+ vcpkg_dir = os.path.dirname(vcpkg)
+ if platform.architecture() == '32bit':
+ specifier = 'x86'
+ else:
+ specifier = 'x64'
+
+ vcpkg_installed = os.path.join(vcpkg_dir, 'installed')
+ for vcpkg_root in [
+ os.path.join(vcpkg_installed, specifier + '-windows'),
+ os.path.join(vcpkg_installed, specifier + '-windows-static'),
+ ]:
+ add_system_root(vcpkg_root)
+
+ # Conda is another popular package manager that provides libraries
+ conda = shutil.which('conda')
+ if conda:
+ conda_dir = os.path.dirname(conda)
+ add_system_root(os.path.join(conda_dir, '..', 'Library'))
+ add_system_root(os.path.join(conda_dir, 'Library'))
else:
default_lib_dirs = libpaths(['/usr/local/lib', '/opt/lib', '/usr/lib',
@@ -2145,8 +2138,6 @@ class openblas_info(blas_info):
extra_args = info['extra_link_args']
except Exception:
extra_args = []
- if sys.version_info < (3, 5) and sys.version_info > (3, 0) and c.compiler_type == "msvc":
- extra_args.append("/MANIFEST")
try:
with open(src, 'wt') as f:
f.write(s)
diff --git a/numpy/distutils/unixccompiler.py b/numpy/distutils/unixccompiler.py
index 9a4d3ba52..cf62cb019 100644
--- a/numpy/distutils/unixccompiler.py
+++ b/numpy/distutils/unixccompiler.py
@@ -8,11 +8,7 @@ from distutils.errors import DistutilsExecError, CompileError
from distutils.unixccompiler import *
from numpy.distutils.ccompiler import replace_method
from numpy.distutils.misc_util import _commandline_dep_string
-
-if sys.version_info[0] < 3:
- from . import log
-else:
- from numpy.distutils import log
+from numpy.distutils import log
# Note that UnixCCompiler._compile appeared in Python 2.3
def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):