Skip to content

Commit

Permalink
Merge pull request #409 from drdavella/remove-py2
Browse files Browse the repository at this point in the history
Remove all support for Python 2
  • Loading branch information
drdavella authored Dec 21, 2017
2 parents b786fe3 + d7c8fcd commit 5c69797
Show file tree
Hide file tree
Showing 74 changed files with 134 additions and 853 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

- ICRSCoord tag has moved to Astropy core package. [#401]

- Remove support for Python 2. [#409]

1.4.0 (unreleased)
------------------

Expand Down
1 change: 0 additions & 1 deletion asdf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

"""
asdf: Python library for reading and writing Advanced Scientific
Expand Down
1 change: 0 additions & 1 deletion asdf/_internal_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

__all__ = ['__version__', '__githash__', 'test']

Expand Down
1 change: 0 additions & 1 deletion asdf/asdf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import io
import re
Expand Down
22 changes: 9 additions & 13 deletions asdf/asdftypes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import bisect
import importlib
Expand All @@ -11,7 +10,7 @@
import six
from copy import copy

from .compat import lru_cache
from functools import lru_cache

from . import tagged
from . import util
Expand All @@ -21,9 +20,7 @@
__all__ = ['format_tag', 'AsdfTypeIndex', 'AsdfType']


_BASIC_PYTHON_TYPES = set(list(six.string_types) +
list(six.integer_types) +
[float, list, dict, tuple])
_BASIC_PYTHON_TYPES = [str, int, float, list, dict, tuple]

# regex used to parse module name from optional version string
MODULE_RE = re.compile(r'([a-zA-Z]+)(-(\d+\.\d+\.\d+))?')
Expand Down Expand Up @@ -104,7 +101,7 @@ def add_by_tag(name, version):
add_type(asdftype)

if self._version == 'latest':
for name, versions in six.iteritems(index._versions_by_type_name):
for name, versions in index._versions_by_type_name.items():
add_by_tag(name, versions[-1])
else:
try:
Expand All @@ -114,11 +111,11 @@ def add_by_tag(name, version):
"Don't know how to write out ASDF version {0}".format(
self._version))

for name, _version in six.iteritems(version_map['tags']):
for name, _version in version_map['tags'].items():
add_by_tag(name, AsdfVersion(_version))

# Now add any extension types that aren't known to the ASDF standard
for name, versions in six.iteritems(index._versions_by_type_name):
for name, versions in index._versions_by_type_name.items():
if name not in self._type_by_name:
add_by_tag(name, versions[-1])

Expand All @@ -143,8 +140,7 @@ def from_custom_type(self, custom_type):
# includes classes that are created dynamically post
# Python-import, e.g. astropy.modeling._CompoundModel
# subclasses.
for key, val in six.iteritems(
self._types_with_dynamic_subclasses):
for key, val in self._types_with_dynamic_subclasses.items():
if issubclass(custom_type, key):
self._type_by_cls[custom_type] = val
return val
Expand Down Expand Up @@ -178,7 +174,7 @@ def add_type(self, asdftype):

if isinstance(asdftype.name, list):
yaml_tags = [asdftype.make_yaml_tag(name) for name in asdftype.name]
elif isinstance(asdftype.name, six.string_types):
elif isinstance(asdftype.name, str):
yaml_tags = [asdftype.yaml_tag]
elif asdftype.name is None:
yaml_tags = []
Expand Down Expand Up @@ -413,7 +409,7 @@ def __new__(mcls, name, bases, attrs):
types = mcls._find_in_bases(attrs, bases, 'types', [])
new_types = []
for typ in types:
if isinstance(typ, six.string_types):
if isinstance(typ, str):
typ = util.resolve_name(typ)
new_types.append(typ)
attrs['types'] = new_types
Expand All @@ -425,7 +421,7 @@ def __new__(mcls, name, bases, attrs):
cls.version = AsdfVersion(cls.version)

if hasattr(cls, 'name'):
if isinstance(cls.name, six.string_types):
if isinstance(cls.name, str):
if 'yaml_tag' not in attrs:
cls.yaml_tag = cls.make_yaml_tag(cls.name)
elif isinstance(cls.name, list):
Expand Down
20 changes: 7 additions & 13 deletions asdf/block.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

from collections import namedtuple
import copy
import hashlib
import io
import os
import re
import struct
import weakref
from collections import namedtuple
from urllib import parse as urlparse

import numpy as np

import six
from six.moves.urllib import parse as urlparse

import yaml

from . import compression as mcompression
Expand Down Expand Up @@ -472,7 +468,7 @@ def read_block_index(self, fd, ctx):

last_offset = 0
for x in offsets:
if (not isinstance(x, six.integer_types) or
if (not isinstance(x, int) or
x > file_size or
x < 0 or
x <= last_offset + Block._header.size):
Expand Down Expand Up @@ -592,7 +588,7 @@ def get_block(self, source):
buffer : buffer
"""
# If an "int", it is the index of an internal block
if isinstance(source, six.integer_types):
if isinstance(source, int):
if source == -1:
if len(self._streamed_blocks):
return self._streamed_blocks[0]
Expand Down Expand Up @@ -639,7 +635,7 @@ def get_block(self, source):

raise ValueError("Block '{0}' not found.".format(source))

elif isinstance(source, six.string_types):
elif isinstance(source, str):
asdffile = self._asdffile().open_external(
source, do_not_fill_defaults=True)
block = asdffile.blocks._internal_blocks[0]
Expand Down Expand Up @@ -901,10 +897,8 @@ def update_size(self):
updating the file in-place, otherwise the work is redundant.
"""
if self._data is not None:
if six.PY2: # pragma: no cover
self._data_size = len(self._data.data)
else:
self._data_size = self._data.data.nbytes
self._data_size = self._data.data.nbytes

if not self.output_compression:
self._size = self._data_size
else:
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

from .exploded import *
from .to_yaml import *
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/defragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Defragment command.
"""

from __future__ import absolute_import, division, unicode_literals, print_function

import os

Expand Down
1 change: 0 additions & 1 deletion asdf/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Implementation of command for displaying differences between two ASDF files.
"""

from __future__ import absolute_import, division, unicode_literals, print_function

import os
import sys
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/exploded.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Contains commands for dealing with exploded and imploded forms.
"""

from __future__ import absolute_import, division, unicode_literals, print_function

import os

Expand Down
11 changes: 3 additions & 8 deletions asdf/commands/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from __future__ import (absolute_import, division, print_function,
unicode_literals)

import argparse
import logging
import sys

import six

from .. import util


Expand Down Expand Up @@ -61,7 +56,7 @@ def help(args):
commands[str(command)].setup_arguments(subparsers)
del commands[command]

for name, command in sorted(six.iteritems(commands)):
for name, command in sorted(commands.items()):
command.setup_arguments(subparsers)

return parser, subparsers
Expand All @@ -80,10 +75,10 @@ def main_from_args(args):
try:
result = args.func(args)
except RuntimeError as e:
logging.error(six.text_type(e))
logging.error(str(e))
return 1
except IOError as e:
logging.error(six.text_type(e))
logging.error(str(e))
return e.errno

if result is None:
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Implementation of command for displaying available tags in asdf
"""

from __future__ import absolute_import, division, unicode_literals, print_function

import sys

Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function
1 change: 0 additions & 1 deletion asdf/commands/tests/setup_package.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function


def get_package_data(): # pragma: no cover
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/test_defragment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import os
import sys
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/test_diff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import os
import io
Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/test_exploded.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import os

Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import pytest

Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import io

Expand Down
1 change: 0 additions & 1 deletion asdf/commands/tests/test_to_yaml.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import os

Expand Down
1 change: 0 additions & 1 deletion asdf/commands/to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Contains commands for dealing with exploded and imploded forms.
"""

from __future__ import absolute_import, division, unicode_literals, print_function

import os

Expand Down
21 changes: 0 additions & 21 deletions asdf/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals, print_function

import six

if six.PY2:
from UserDict import UserDict
from UserList import UserList
from UserString import UserString
elif six.PY3:
from .user_collections_py3.UserDict import UserDict
from .user_collections_py3.UserList import UserList
from .user_collections_py3.UserString import UserString

if six.PY2:
from .functools_backport import lru_cache
elif six.PY3:
try:
from functools import lru_cache
except ImportError:
from .functools_backport import lru_cache
Loading

0 comments on commit 5c69797

Please sign in to comment.