Skip to content

Commit

Permalink
Improved python 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
aldro61 committed Feb 11, 2019
1 parent 7100be3 commit 92efb85
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
8 changes: 3 additions & 5 deletions patric_tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
"""
try:
from urlparse import urlsplit, urljoin
from urllib import unquote, urlretrieve
except ImportError: # Python 3
from urllib.parse import urlsplit, unquote # TODO: include urljoin
from urllib.request import urlretrieve
from urlparse import urljoin
except ImportError: # Python 3
from urllib.parse import urljoin


PATRIC_FTP_BASE_URL = "ftp://ftp.patricbrc.org"
Expand Down
4 changes: 2 additions & 2 deletions patric_tools/genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import os
try:
from urlparse import urljoin
except ImportError: # Python 3
pass # TODO: include urljoin
except ImportError: # Python 3
from urllib.parse import urljoin

from time import sleep

Expand Down
10 changes: 6 additions & 4 deletions patric_tools/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
from unittest import TestCase

try:
from urllib2 import urlopen
from urlparse import urljoin
except ImportError: # Python 3
pass # TODO: include urljoin
except ImportError: # Python 3
from urllib.parse import urljoin
from urllib.request import urlopen

from ..config import PATRIC_FTP_BASE_URL, PATRIC_FTP_AMR_METADATA_URL, \
PATRIC_FTP_GENOMES_URL, PATRIC_FTP_GENOMES_METADATA_URL


class UtilityTests(TestCase):
def setUp(self):
"""
Expand All @@ -34,9 +37,8 @@ def setUp(self):
pass

def _test_url(self, url):
import urllib2
try:
urllib2.urlopen(url, timeout=10)
urlopen(url, timeout=10)
except:
self.fail("Could not reach {0!s}".format(url))

Expand Down
11 changes: 5 additions & 6 deletions patric_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import posixpath

try:
from urlparse import urlsplit, urljoin
from urllib import unquote, urlretrieve
except ImportError: # Python 3
from urllib.parse import urlsplit, unquote #TODO: include urljoin
from urllib.request import urlretrieve
from urlparse import urlsplit
from urllib import unquote
except ImportError: # Python 3
from urllib.parse import urlsplit, unquote


def download_file_from_url(url, outdir):
Expand Down Expand Up @@ -51,7 +50,7 @@ def download_file_from_url(url, outdir):
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))
return ""
except Exception as e:
print e
print(e)
return url + str(e)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

setup(
name='PATRIC Tools',
version='1.0.0',
version='1.1.0',

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

0 comments on commit 92efb85

Please sign in to comment.