Skip to content

Commit 42b8d46

Browse files
authored
Remove six dependency (#2017)
* remove six from python code * remove six from setup.py * remove six from tests * remove six from references * remove six from packaging * revert str to torch._six._string_classes * revert str to torch._six._string_classes
1 parent e1bd43c commit 42b8d46

File tree

8 files changed

+8
-15
lines changed

8 files changed

+8
-15
lines changed

packaging/torchvision/meta.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ requirements:
2020
- python
2121
- pillow >=4.1.1
2222
- numpy >=1.11
23-
- six
2423
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
2524
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
2625

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def write_version_file():
6969

7070
requirements = [
7171
'numpy',
72-
'six',
7372
pytorch_dep,
7473
]
7574

test/common_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import __main__
1212

1313
from numbers import Number
14-
from torch._six import string_classes, inf
14+
from torch._six import string_classes
1515
from collections import OrderedDict
1616

1717

@@ -255,6 +255,7 @@ def assertTensorsEqual(a, b):
255255
elif isinstance(x, bool) and isinstance(y, bool):
256256
super(TestCase, self).assertEqual(x, y, message)
257257
elif isinstance(x, Number) and isinstance(y, Number):
258+
inf = float("inf")
258259
if abs(x) == inf or abs(y) == inf:
259260
if allow_inf:
260261
super(TestCase, self).assertEqual(x, y, message)

test/test_datasets_utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import tarfile
88
import gzip
99
import warnings
10-
from torch._six import PY2
1110
from torch._utils_internal import get_file_path_2
1211

1312
from common_utils import get_tmp_dir
@@ -41,7 +40,6 @@ def test_check_integrity(self):
4140
self.assertTrue(utils.check_integrity(existing_fpath))
4241
self.assertFalse(utils.check_integrity(nonexisting_fpath))
4342

44-
@unittest.skipIf(PY2, "https://github.com/pytorch/vision/issues/1268")
4543
def test_download_url(self):
4644
with get_tmp_dir() as temp_dir:
4745
url = "http://github.com/pytorch/vision/archive/master.zip"
@@ -53,7 +51,6 @@ def test_download_url(self):
5351
warnings.warn(msg, RuntimeWarning)
5452
raise unittest.SkipTest(msg)
5553

56-
@unittest.skipIf(PY2, "https://github.com/pytorch/vision/issues/1268")
5754
def test_download_url_retry_http(self):
5855
with get_tmp_dir() as temp_dir:
5956
url = "https://github.com/pytorch/vision/archive/master.zip"

torchvision/datasets/flickr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from collections import defaultdict
22
from PIL import Image
3-
from six.moves import html_parser
3+
from html.parser import HTMLParser
44

55
import glob
66
import os
77
from .vision import VisionDataset
88

99

10-
class Flickr8kParser(html_parser.HTMLParser):
10+
class Flickr8kParser(HTMLParser):
1111
"""Parser for extracting captions from the Flickr8k dataset web page."""
1212

1313
def __init__(self, root):

torchvision/datasets/lsun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from PIL import Image
33
import os
44
import os.path
5-
import six
5+
import io
66
import string
77
import sys
88

@@ -43,7 +43,7 @@ def __getitem__(self, index):
4343
with env.begin(write=False) as txn:
4444
imgbuf = txn.get(self.keys[index])
4545

46-
buf = six.BytesIO()
46+
buf = io.BytesIO()
4747
buf.write(imgbuf)
4848
buf.seek(0)
4949
img = Image.open(buf).convert('RGB')

torchvision/datasets/sbu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from PIL import Image
2-
from six.moves import zip
32
from .utils import download_url, check_integrity
43

54
import os

torchvision/datasets/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import torch
1010
from torch.utils.model_zoo import tqdm
11-
from torch._six import PY3
1211

1312

1413
def gen_bar_updater():
@@ -52,7 +51,7 @@ def download_url(url, root, filename=None, md5=None):
5251
filename (str, optional): Name to save the file under. If None, use the basename of the URL
5352
md5 (str, optional): MD5 checksum of the download. If None, do not check
5453
"""
55-
from six.moves import urllib
54+
import urllib
5655

5756
root = os.path.expanduser(root)
5857
if not filename:
@@ -222,8 +221,7 @@ def extract_archive(from_path, to_path=None, remove_finished=False):
222221
elif _is_targz(from_path) or _is_tgz(from_path):
223222
with tarfile.open(from_path, 'r:gz') as tar:
224223
tar.extractall(path=to_path)
225-
elif _is_tarxz(from_path) and PY3:
226-
# .tar.xz archive only supported in Python 3.x
224+
elif _is_tarxz(from_path):
227225
with tarfile.open(from_path, 'r:xz') as tar:
228226
tar.extractall(path=to_path)
229227
elif _is_gzip(from_path):

0 commit comments

Comments
 (0)