Skip to content

Commit

Permalink
MAINT: Remove sys.version checks (gh-numpy#15373)
Browse files Browse the repository at this point in the history
More sys.version cleanup.
  • Loading branch information
sethtroisi authored and seberg committed Jan 28, 2020
1 parent d67de1b commit 96727cf
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 139 deletions.
16 changes: 3 additions & 13 deletions numpy/core/_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
String handling is much easier to do correctly in python.
"""
import sys

import numpy as np


Expand All @@ -17,18 +15,10 @@
'V': 'void',
'O': 'object',
'M': 'datetime',
'm': 'timedelta'
'm': 'timedelta',
'S': 'bytes',
'U': 'str',
}
if sys.version_info[0] >= 3:
_kind_to_stem.update({
'S': 'bytes',
'U': 'str'
})
else:
_kind_to_stem.update({
'S': 'string',
'U': 'unicode'
})


def _kind_name(dtype):
Expand Down
19 changes: 5 additions & 14 deletions numpy/core/_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,16 @@ def _set_up_aliases():
('bool_', 'bool'),
('bytes_', 'string'),
('string_', 'string'),
('str_', 'unicode'),
('unicode_', 'unicode'),
('object_', 'object')]
if sys.version_info[0] >= 3:
type_pairs.extend([('str_', 'unicode')])
else:
type_pairs.extend([('str_', 'string')])
for alias, t in type_pairs:
allTypes[alias] = allTypes[t]
sctypeDict[alias] = sctypeDict[t]
# Remove aliases overriding python types and modules
to_remove = ['ulong', 'object', 'int', 'float',
'complex', 'bool', 'string', 'datetime', 'timedelta']
if sys.version_info[0] >= 3:
to_remove.extend(['bytes', 'str'])
else:
to_remove.extend(['unicode', 'long'])
'complex', 'bool', 'string', 'datetime', 'timedelta',
'bytes', 'str']

for t in to_remove:
try:
Expand Down Expand Up @@ -267,11 +261,8 @@ def _set_array_types():


# Add additional strings to the sctypeDict
_toadd = ['int', 'float', 'complex', 'bool', 'object']
if sys.version_info[0] >= 3:
_toadd.extend(['str', 'bytes', ('a', 'bytes_')])
else:
_toadd.extend(['string', ('str', 'string_'), 'unicode', ('a', 'string_')])
_toadd = ['int', 'float', 'complex', 'bool', 'object',
'str', 'bytes', ('a', 'bytes_')]

for name in _toadd:
if isinstance(name, tuple):
Expand Down
108 changes: 48 additions & 60 deletions numpy/distutils/fcompiler/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,72 +62,60 @@ def runtime_library_dir_option(self, dir):
return '-R%s' % dir


if sys.version_info >= (3, 5):
import functools
import functools

class PGroupFlangCompiler(FCompiler):
compiler_type = 'flang'
description = 'Portland Group Fortran LLVM Compiler'
version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*'

ar_exe = 'lib.exe'
possible_executables = ['flang']

executables = {
'version_cmd': ["<F77>", "--version"],
'compiler_f77': ["flang"],
'compiler_fix': ["flang"],
'compiler_f90': ["flang"],
'linker_so': [None],
'archiver': [ar_exe, "/verbose", "/OUT:"],
'ranlib': None
}

library_switch = '/OUT:' # No space after /OUT:!
module_dir_switch = '-module ' # Don't remove ending space!

def get_libraries(self):
opt = FCompiler.get_libraries(self)
opt.extend(['flang', 'flangrti', 'ompstub'])
return opt

@functools.lru_cache(maxsize=128)
def get_library_dirs(self):
"""List of compiler library directories."""
opt = FCompiler.get_library_dirs(self)
flang_dir = dirname(self.executables['compiler_f77'][0])
opt.append(normpath(join(flang_dir, '..', 'lib')))

return opt

class PGroupFlangCompiler(FCompiler):
compiler_type = 'flang'
description = 'Portland Group Fortran LLVM Compiler'
version_pattern = r'\s*(flang|clang) version (?P<version>[\d.-]+).*'

ar_exe = 'lib.exe'
possible_executables = ['flang']

executables = {
'version_cmd': ["<F77>", "--version"],
'compiler_f77': ["flang"],
'compiler_fix': ["flang"],
'compiler_f90': ["flang"],
'linker_so': [None],
'archiver': [ar_exe, "/verbose", "/OUT:"],
'ranlib': None
}

library_switch = '/OUT:' # No space after /OUT:!
module_dir_switch = '-module ' # Don't remove ending space!

def get_libraries(self):
opt = FCompiler.get_libraries(self)
opt.extend(['flang', 'flangrti', 'ompstub'])
return opt

@functools.lru_cache(maxsize=128)
def get_library_dirs(self):
"""List of compiler library directories."""
opt = FCompiler.get_library_dirs(self)
flang_dir = dirname(self.executables['compiler_f77'][0])
opt.append(normpath(join(flang_dir, '..', 'lib')))

return opt

def get_flags(self):
return []

def get_flags_free(self):
return []

def get_flags_debug(self):
return ['-g']

def get_flags_opt(self):
return ['-O3']
def get_flags(self):
return []

def get_flags_arch(self):
return []
def get_flags_free(self):
return []

def runtime_library_dir_option(self, dir):
raise NotImplementedError
def get_flags_debug(self):
return ['-g']

else:
from numpy.distutils.fcompiler import CompilerNotFound
def get_flags_opt(self):
return ['-O3']

# No point in supporting on older Pythons because not ABI compatible
class PGroupFlangCompiler(FCompiler):
compiler_type = 'flang'
description = 'Portland Group Fortran LLVM Compiler'
def get_flags_arch(self):
return []

def get_version(self):
raise CompilerNotFound('Flang unsupported on Python < 3.5')
def runtime_library_dir_option(self, dir):
raise NotImplementedError


if __name__ == '__main__':
Expand Down
6 changes: 1 addition & 5 deletions numpy/f2py/capi_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@
'complex_float': 'N',
'complex_double': 'N',
'complex_long_double': 'N',
'string': 'z'}

if sys.version_info[0] >= 3:
# Bytes, not Unicode strings
c2buildvalue_map['string'] = 'y'
'string': 'y'}

if using_newcore:
# c2buildvalue_map=???
Expand Down
35 changes: 0 additions & 35 deletions numpy/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,41 +605,6 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'):
)
print(" %s -- %s" % (meth, methstr), file=output)

elif (sys.version_info[0] < 3
and isinstance(object, types.InstanceType)):
# check for __call__ method
# types.InstanceType is the type of the instances of oldstyle classes
print("Instance of class: ", object.__class__.__name__, file=output)
print(file=output)
if hasattr(object, '__call__'):
arguments = formatargspec(
*getargspec(object.__call__.__func__)
)
arglist = arguments.split(', ')
if len(arglist) > 1:
arglist[1] = "("+arglist[1]
arguments = ", ".join(arglist[1:])
else:
arguments = "()"

if hasattr(object, 'name'):
name = "%s" % object.name
else:
name = "<name>"
if len(name+arguments) > maxwidth:
argstr = _split_line(name, arguments, maxwidth)
else:
argstr = name + arguments

print(" " + argstr + "\n", file=output)
doc = inspect.getdoc(object.__call__)
if doc is not None:
print(inspect.getdoc(object.__call__), file=output)
print(inspect.getdoc(object), file=output)

else:
print(inspect.getdoc(object), file=output)

elif inspect.ismethod(object):
name = object.__name__
arguments = formatargspec(
Expand Down
7 changes: 1 addition & 6 deletions numpy/linalg/lapack_lite/make_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
import fortran
import clapack_scrub

PY2 = sys.version_info < (3, 0)

if PY2:
from distutils.spawn import find_executable as which
else:
from shutil import which
from shutil import which

# Arguments to pass to f2c. You'll always want -A for ANSI C prototypes
# Others of interest: -a to not make variables static by default
Expand Down
5 changes: 0 additions & 5 deletions numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"""
# pylint: disable-msg=E1002
import builtins
import sys
import operator
import warnings
import textwrap
Expand Down Expand Up @@ -3885,10 +3884,6 @@ def _insert_masked_print(self):
def __str__(self):
return str(self._insert_masked_print())

if sys.version_info.major < 3:
def __unicode__(self):
return unicode(self._insert_masked_print())

def __repr__(self):
"""
Literal string representation.
Expand Down
2 changes: 1 addition & 1 deletion tools/pypy-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pypy3/bin/pypy3 -m pip install --upgrade pip setuptools
pypy3/bin/pypy3 -m pip install --user -r test_requirements.txt --no-warn-script-location

echo
echo pypy3 version
echo pypy3 version
pypy3/bin/pypy3 -c "import sys; print(sys.version)"
echo

Expand Down

0 comments on commit 96727cf

Please sign in to comment.