Skip to content

Commit 58fdc01

Browse files
authored
Merge pull request astropy#6556 from bsipocz/python2_remove_six
Remove python2 support from code
2 parents 34b6f85 + 7e0ab3c commit 58fdc01

529 files changed

Lines changed: 1147 additions & 3304 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ astropy.wcs
265265
Other Changes and Additions
266266
---------------------------
267267

268-
- Pytest <3.1 versions are no longer supported. [#6419]
268+
- Versions of Python <3.5 are no longer supported. [#6556]
269+
270+
- Versions of Pytest <3.1 are no longer supported. [#6419]
269271

270272
- The bundled CFITSIO was updated to version 3.41 [#6477]
271273

astropy/__init__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
managing them.
77
"""
88

9-
from __future__ import absolute_import
109

1110
import sys
1211
import os
1312
from warnings import warn
1413

15-
if sys.version_info[:2] < (2, 7):
16-
warn("Astropy does not support Python 2.6 (in v1.2 and later)")
14+
if sys.version_info[:2] < (3, 5):
15+
warn("Astropy does not support Python <3.5 (in v3.0 and later)")
1716

1817

1918
def _is_astropy_source(path=None):
@@ -54,10 +53,7 @@ def _is_astropy_setup():
5453
_ASTROPY_SETUP_
5554
except NameError:
5655
from sys import version_info
57-
if version_info[0] >= 3:
58-
import builtins
59-
else:
60-
import __builtin__ as builtins
56+
import builtins
6157

6258
# This will set the _ASTROPY_SETUP_ to True by default if
6359
# we are running Astropy's setup.py
@@ -223,7 +219,6 @@ def _rebuild_extensions():
223219
import time
224220

225221
from .utils.console import Spinner
226-
from .extern.six import next
227222

228223
devnull = open(os.devnull, 'w')
229224
old_cwd = os.getcwd()
@@ -302,7 +297,7 @@ def online_help(query):
302297
query : str
303298
The search query.
304299
"""
305-
from .extern.six.moves.urllib.parse import urlencode
300+
from urllib.parse import urlencode
306301
import webbrowser
307302

308303
version = __version__

astropy/_erfa/core.py.templ

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ dramatically reduces compilation time without notably impacting
3232
performance. (See issue [#3063] on the github repository for more
3333
about this.)
3434
"""
35-
from __future__ import absolute_import, division, print_function
3635

3736
import warnings
3837

astropy/_erfa/erfa_generator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Note that this does *not* currently automate the process of creating structs
1010
or dtypes for those structs. They should be added manually in the template file.
1111
"""
12-
from __future__ import absolute_import, division, print_function
1312
# note that we do *not* use unicode_literals here, because that makes the
1413
# generated code's strings have u'' in them on py 2.x
1514

astropy/_erfa/setup_package.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2-
from __future__ import absolute_import
32

43
import os
54
import glob

astropy/config/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
Astropy project. This includes all functionality related to the
66
affiliated package index.
77
"""
8-
from __future__ import (absolute_import, division, print_function,
9-
unicode_literals)
108

119
from .paths import *
1210
from .configuration import *

astropy/config/affiliated.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
affiliated packages and installing them.
44
"""
55

6-
from __future__ import (absolute_import, division, print_function,
7-
unicode_literals)
86

97
__all__ = []

astropy/config/configuration.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
`ConfigParser`. More information and documentation for configobj can be
99
found at http://www.voidspace.org.uk/python/configobj.html.
1010
"""
11-
from __future__ import (absolute_import, division, print_function,
12-
unicode_literals)
13-
from ..extern import six
1411

1512
from contextlib import contextmanager
1613
import hashlib
@@ -72,13 +69,12 @@ def __init__(cls, name, bases, dict):
7269
if cls.__bases__[0] is object:
7370
return
7471

75-
for key, val in six.iteritems(dict):
72+
for key, val in dict.items():
7673
if isinstance(val, ConfigItem):
7774
val.name = key
7875

7976

80-
@six.add_metaclass(_ConfigNamespaceMeta)
81-
class ConfigNamespace(object):
77+
class ConfigNamespace(metaclass=_ConfigNamespaceMeta):
8278
"""
8379
A namespace of configuration items. Each subpackage with
8480
configuration items should define a subclass of this class,
@@ -135,7 +131,7 @@ def reload(self, attr=None):
135131
return self.__class__.__dict__[attr].reload()
136132
raise AttributeError("No configuration parameter '{0}'".format(attr))
137133

138-
for item in six.itervalues(self.__class__.__dict__):
134+
for item in self.__class__.__dict__.values():
139135
if isinstance(item, ConfigItem):
140136
item.reload()
141137

@@ -156,13 +152,12 @@ def reset(self, attr=None):
156152
return
157153
raise AttributeError("No configuration parameter '{0}'".format(attr))
158154

159-
for item in six.itervalues(self.__class__.__dict__):
155+
for item in self.__class__.__dict__.values():
160156
if isinstance(item, ConfigItem):
161157
item.set(item.defaultvalue)
162158

163159

164-
@six.add_metaclass(InheritDocstrings)
165-
class ConfigItem(object):
160+
class ConfigItem(metaclass=InheritDocstrings):
166161
"""
167162
A setting and associated value stored in a configuration file.
168163
@@ -242,9 +237,9 @@ def __init__(self, defaultvalue='', description=None, cfgtype=None,
242237
# now determine cfgtype if it is not given
243238
if cfgtype is None:
244239
if (isiterable(defaultvalue) and not
245-
isinstance(defaultvalue, six.string_types)):
240+
isinstance(defaultvalue, str)):
246241
# it is an options list
247-
dvstr = [six.text_type(v) for v in defaultvalue]
242+
dvstr = [str(v) for v in defaultvalue]
248243
cfgtype = 'option(' + ', '.join(dvstr) + ')'
249244
defaultvalue = dvstr[0]
250245
elif isinstance(defaultvalue, bool):
@@ -253,9 +248,9 @@ def __init__(self, defaultvalue='', description=None, cfgtype=None,
253248
cfgtype = 'integer'
254249
elif isinstance(defaultvalue, float):
255250
cfgtype = 'float'
256-
elif isinstance(defaultvalue, six.string_types):
251+
elif isinstance(defaultvalue, str):
257252
cfgtype = 'string'
258-
defaultvalue = six.text_type(defaultvalue)
253+
defaultvalue = str(defaultvalue)
259254

260255
self.cfgtype = cfgtype
261256

@@ -264,7 +259,7 @@ def __init__(self, defaultvalue='', description=None, cfgtype=None,
264259

265260
if aliases is None:
266261
self.aliases = []
267-
elif isinstance(aliases, six.string_types):
262+
elif isinstance(aliases, str):
268263
self.aliases = [aliases]
269264
else:
270265
self.aliases = aliases
@@ -604,7 +599,7 @@ def is_unedited_config_file(content, template_content=None):
604599
buffer = io.BytesIO(content)
605600
buffer.seek(0)
606601
raw_cfg = configobj.ConfigObj(buffer, interpolation=True)
607-
for v in six.itervalues(raw_cfg):
602+
for v in raw_cfg.values():
608603
if len(v):
609604
break
610605
else:

astropy/config/paths.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
""" This module contains functions to determine where configuration and
33
data/cache files used by Astropy should be placed.
44
"""
5-
from __future__ import (absolute_import, division, print_function,
6-
unicode_literals)
75

8-
from ..extern import six
96
from ..utils.decorators import wraps
107

118
import os
@@ -29,58 +26,49 @@ def _find_home():
2926
directories.
3027
"""
3128

32-
# this is used below to make fix up encoding issues that sometimes crop up
33-
# in py2.x but not in py3.x
34-
if six.PY2:
35-
decodepath = lambda pth: pth.decode(sys.getfilesystemencoding())
36-
else:
37-
decodepath = lambda pth: pth
38-
3929
# First find the home directory - this is inspired by the scheme ipython
4030
# uses to identify "home"
4131
if os.name == 'posix':
4232
# Linux, Unix, AIX, OS X
4333
if 'HOME' in os.environ:
44-
homedir = decodepath(os.environ['HOME'])
34+
homedir = os.environ['HOME']
4535
else:
4636
raise OSError('Could not find unix home directory to search for '
4737
'astropy config dir')
4838
elif os.name == 'nt': # This is for all modern Windows (NT or after)
4939
if 'MSYSTEM' in os.environ and os.environ.get('HOME'):
5040
# Likely using an msys shell; use whatever it is using for its
5141
# $HOME directory
52-
homedir = decodepath(os.environ['HOME'])
42+
homedir = os.environ['HOME']
5343
# Next try for a network home
5444
elif 'HOMESHARE' in os.environ:
55-
homedir = decodepath(os.environ['HOMESHARE'])
45+
homedir = os.environ['HOMESHARE']
5646
# See if there's a local home
5747
elif 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ:
5848
homedir = os.path.join(os.environ['HOMEDRIVE'],
5949
os.environ['HOMEPATH'])
60-
homedir = decodepath(homedir)
6150
# Maybe a user profile?
6251
elif 'USERPROFILE' in os.environ:
63-
homedir = decodepath(os.path.join(os.environ['USERPROFILE']))
52+
homedir = os.path.join(os.environ['USERPROFILE'])
6453
else:
6554
try:
66-
from ..extern.six.moves import winreg as wreg
55+
import winreg as wreg
6756
shell_folders = r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
6857
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, shell_folders)
6958

7059
homedir = wreg.QueryValueEx(key, 'Personal')[0]
71-
homedir = decodepath(homedir)
7260
key.Close()
7361
except Exception:
7462
# As a final possible resort, see if HOME is present
7563
if 'HOME' in os.environ:
76-
homedir = decodepath(os.environ['HOME'])
64+
homedir = os.environ['HOME']
7765
else:
7866
raise OSError('Could not find windows home directory to '
7967
'search for astropy config dir')
8068
else:
8169
# for other platforms, try HOME, although it probably isn't there
8270
if 'HOME' in os.environ:
83-
homedir = decodepath(os.environ['HOME'])
71+
homedir = os.environ['HOME']
8472
else:
8573
raise OSError('Could not find a home directory to search for '
8674
'astropy config dir - are you on an unspported '

astropy/config/tests/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
from __future__ import (absolute_import, division, print_function,
2-
unicode_literals)

0 commit comments

Comments
 (0)