Skip to content

Commit 93deba0

Browse files
author
Joseph Hamman
committed
remove py2 compat (code changes)
1 parent cb3138c commit 93deba0

31 files changed

+74
-269
lines changed

setup.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, print_function, division
32
from setuptools import setup
43
import sys
54

@@ -17,11 +16,6 @@
1716
'numcodecs>=0.6.2',
1817
]
1918

20-
if sys.version_info < (3, 5):
21-
dependencies.append('scandir')
22-
if sys.version_info < (3, 3) and sys.platform == "win32":
23-
dependencies.append('pyosreplace')
24-
2519
setup(
2620
name='zarr',
2721
description=DESCRIPTION,

zarr/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
22
# flake8: noqa
3-
from __future__ import absolute_import, print_function, division
4-
5-
63
from zarr.core import Array
74
from zarr.creation import (empty, zeros, ones, full, array, empty_like, zeros_like,
85
ones_like, full_like, open_array, open_like, create)

zarr/attrs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, print_function, division
3-
4-
52
from zarr.compat import MutableMapping
63
from zarr.errors import PermissionError
74
from zarr.meta import parse_metadata

zarr/codecs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# -*- coding: utf-8 -*-
22
# flake8: noqa
3-
from __future__ import absolute_import, print_function, division
4-
5-
63
from numcodecs import *
74
from numcodecs.registry import codec_registry

zarr/compat.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
11
# -*- coding: utf-8 -*-
22
# flake8: noqa
3-
from __future__ import absolute_import, print_function, division
4-
import sys
53

4+
# TODO: we can probably eliminate all of this module
5+
text_type = str
6+
binary_type = bytes
7+
from functools import reduce
8+
from itertools import zip_longest
69

7-
PY2 = sys.version_info[0] == 2
10+
def OrderedDict_move_to_end(od, key):
11+
od.move_to_end(key)
812

9-
10-
if PY2: # pragma: py3 no cover
11-
12-
text_type = unicode
13-
binary_type = str
14-
reduce = reduce
15-
from itertools import izip_longest as zip_longest
16-
17-
class PermissionError(Exception):
18-
pass
19-
20-
def OrderedDict_move_to_end(od, key):
21-
od[key] = od.pop(key)
22-
23-
from collections import Mapping, MutableMapping
24-
from scandir import scandir
25-
26-
27-
else: # pragma: py2 no cover
28-
29-
text_type = str
30-
binary_type = bytes
31-
from functools import reduce
32-
from itertools import zip_longest
33-
PermissionError = PermissionError
34-
35-
def OrderedDict_move_to_end(od, key):
36-
od.move_to_end(key)
37-
38-
from collections.abc import Mapping, MutableMapping
39-
from os import scandir
13+
from collections.abc import Mapping, MutableMapping
14+
from os import scandir

zarr/convenience.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
"""Convenience functions for storing and loading data."""
3-
from __future__ import absolute_import, print_function, division
43
import io
54
import re
65
import itertools
@@ -13,7 +12,7 @@
1312
from zarr.storage import contains_array, contains_group
1413
from zarr.errors import err_path_not_found, CopyError
1514
from zarr.util import normalize_storage_path, TreeViewer, buffer_size
16-
from zarr.compat import Mapping, PY2, text_type
15+
from zarr.compat import Mapping, text_type
1716
from zarr.meta import json_dumps, json_loads
1817

1918

@@ -451,9 +450,6 @@ def __exit__(self, *args):
451450
def __call__(self, *args, **kwargs):
452451
if self.log_file is not None:
453452
kwargs['file'] = self.log_file
454-
if PY2: # pragma: py3 no cover
455-
# expect file opened in text mode, need to adapt message
456-
args = [text_type(a) for a in args]
457453
print(*args, **kwargs)
458454
if hasattr(self.log_file, 'flush'):
459455
# get immediate feedback

zarr/core.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, print_function, division
32
import binascii
43
import operator
54
import itertools
65
import hashlib
76
import re
87

9-
108
import numpy as np
119
from numcodecs.compat import ensure_bytes, ensure_ndarray
1210

@@ -17,7 +15,7 @@
1715
from zarr.storage import array_meta_key, attrs_key, listdir, getsize
1816
from zarr.meta import decode_array_metadata, encode_array_metadata
1917
from zarr.attrs import Attributes
20-
from zarr.errors import PermissionError, err_read_only, err_array_not_found
18+
from zarr.errors import err_read_only, err_array_not_found
2119
from zarr.compat import reduce
2220
from zarr.codecs import AsType, get_codec
2321
from zarr.indexing import (OIndex, OrthogonalIndexer, BasicIndexer, VIndex,
@@ -1786,7 +1784,7 @@ def _encode_chunk(self, chunk):
17861784

17871785
def __repr__(self):
17881786
t = type(self)
1789-
r = '<%s.%s' % (t.__module__, t.__name__)
1787+
r = '<{}.{}'.format(t.__module__, t.__name__)
17901788
if self.name:
17911789
r += ' %r' % self.name
17921790
r += ' %s' % str(self.shape)
@@ -1827,11 +1825,11 @@ def info_items(self):
18271825
def _info_items_nosync(self):
18281826

18291827
def typestr(o):
1830-
return '%s.%s' % (type(o).__module__, type(o).__name__)
1828+
return '{}.{}'.format(type(o).__module__, type(o).__name__)
18311829

18321830
def bytestr(n):
18331831
if n > 2**10:
1834-
return '%s (%s)' % (n, human_readable_size(n))
1832+
return '{} ({})'.format(n, human_readable_size(n))
18351833
else:
18361834
return str(n)
18371835

@@ -1872,7 +1870,7 @@ def bytestr(n):
18721870
('Storage ratio', '%.1f' % (self.nbytes / self.nbytes_stored)),
18731871
]
18741872
items += [
1875-
('Chunks initialized', '%s/%s' % (self.nchunks_initialized, self.nchunks))
1873+
('Chunks initialized', '{}/{}'.format(self.nchunks_initialized, self.nchunks))
18761874
]
18771875

18781876
return items
@@ -1930,7 +1928,7 @@ def hexdigest(self, hashname="sha1"):
19301928
checksum = binascii.hexlify(self.digest(hashname=hashname))
19311929

19321930
# This is a bytes object on Python 3 and we want a str.
1933-
if type(checksum) is not str: # pragma: py2 no cover
1931+
if type(checksum) is not str:
19341932
checksum = checksum.decode('utf8')
19351933

19361934
return checksum

zarr/creation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, print_function, division
32
from warnings import warn
43

5-
64
import numpy as np
75

8-
96
from zarr.core import Array
107
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
118
default_compressor, normalize_storage_path, ZipStore)

zarr/errors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, print_function, division
3-
4-
5-
from zarr.compat import PermissionError
6-
72

83
class MetadataError(Exception):
94
pass

zarr/hierarchy.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, print_function, division
32
from itertools import islice
43

54
import numpy as np
65

76

8-
from zarr.compat import PY2, MutableMapping
7+
from zarr.compat import MutableMapping
98
from zarr.attrs import Attributes
109
from zarr.core import Array
1110
from zarr.storage import (contains_array, contains_group, init_group,
@@ -218,7 +217,7 @@ def __len__(self):
218217

219218
def __repr__(self):
220219
t = type(self)
221-
r = '<%s.%s' % (t.__module__, t.__name__)
220+
r = '<{}.{}'.format(t.__module__, t.__name__)
222221
if self.name:
223222
r += ' %r' % self.name
224223
if self._read_only:
@@ -229,7 +228,7 @@ def __repr__(self):
229228
def info_items(self):
230229

231230
def typestr(o):
232-
return '%s.%s' % (type(o).__module__, type(o).__name__)
231+
return '{}.{}'.format(type(o).__module__, type(o).__name__)
233232

234233
items = []
235234

@@ -353,11 +352,8 @@ def __getattr__(self, item):
353352
raise AttributeError
354353

355354
def __dir__(self):
356-
if PY2: # pragma: py3 no cover
357-
base = instance_dir(self)
358-
else: # pragma: py2 no cover
359-
# noinspection PyUnresolvedReferences
360-
base = super().__dir__()
355+
# noinspection PyUnresolvedReferences
356+
base = super().__dir__()
361357
keys = sorted(set(base + list(self)))
362358
keys = [k for k in keys if is_valid_python_name(k)]
363359
return keys

0 commit comments

Comments
 (0)