Skip to content

Commit 92efb85

Browse files
committed
Improved python 3 compatibility
1 parent 7100be3 commit 92efb85

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

patric_tools/config.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
1515
"""
1616
try:
17-
from urlparse import urlsplit, urljoin
18-
from urllib import unquote, urlretrieve
19-
except ImportError: # Python 3
20-
from urllib.parse import urlsplit, unquote # TODO: include urljoin
21-
from urllib.request import urlretrieve
17+
from urlparse import urljoin
18+
except ImportError: # Python 3
19+
from urllib.parse import urljoin
2220

2321

2422
PATRIC_FTP_BASE_URL = "ftp://ftp.patricbrc.org"

patric_tools/genomes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import os
1818
try:
1919
from urlparse import urljoin
20-
except ImportError: # Python 3
21-
pass # TODO: include urljoin
20+
except ImportError: # Python 3
21+
from urllib.parse import urljoin
2222

2323
from time import sleep
2424

patric_tools/tests/test_config.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
from unittest import TestCase
1919

2020
try:
21+
from urllib2 import urlopen
2122
from urlparse import urljoin
22-
except ImportError: # Python 3
23-
pass # TODO: include urljoin
23+
except ImportError: # Python 3
24+
from urllib.parse import urljoin
25+
from urllib.request import urlopen
2426

2527
from ..config import PATRIC_FTP_BASE_URL, PATRIC_FTP_AMR_METADATA_URL, \
2628
PATRIC_FTP_GENOMES_URL, PATRIC_FTP_GENOMES_METADATA_URL
2729

30+
2831
class UtilityTests(TestCase):
2932
def setUp(self):
3033
"""
@@ -34,9 +37,8 @@ def setUp(self):
3437
pass
3538

3639
def _test_url(self, url):
37-
import urllib2
3840
try:
39-
urllib2.urlopen(url, timeout=10)
41+
urlopen(url, timeout=10)
4042
except:
4143
self.fail("Could not reach {0!s}".format(url))
4244

patric_tools/utils.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
import posixpath
1818

1919
try:
20-
from urlparse import urlsplit, urljoin
21-
from urllib import unquote, urlretrieve
22-
except ImportError: # Python 3
23-
from urllib.parse import urlsplit, unquote #TODO: include urljoin
24-
from urllib.request import urlretrieve
20+
from urlparse import urlsplit
21+
from urllib import unquote
22+
except ImportError: # Python 3
23+
from urllib.parse import urlsplit, unquote
2524

2625

2726
def download_file_from_url(url, outdir):
@@ -51,7 +50,7 @@ def download_file_from_url(url, outdir):
5150
system("wget --quiet -o /dev/null -O {0!s} --continue --timeout 20 {1!s}".format(os.path.join(outdir, url_extract_file_name(url)), url))
5251
return ""
5352
except Exception as e:
54-
print e
53+
print(e)
5554
return url + str(e)
5655

5756

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
setup(
2727
name='PATRIC Tools',
28-
version='1.0.0',
28+
version='1.1.0',
2929

3030
description='A Python package to interact with the PATRIC database (https://www.patricbrc.org)',
3131
long_description=long_description,

0 commit comments

Comments
 (0)