Skip to content

Commit 89b7fde

Browse files
authored
Merge pull request #404 from mpsonntag/py2bgone
Dropping Python 2 support
2 parents 4e23a93 + fe5b543 commit 89b7fde

20 files changed

+64
-183
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ matrix:
1010
dist: bionic
1111

1212
include:
13-
- os: linux
14-
python: "2.7"
1513
- os: linux
1614
python: "3.5"
1715
- os: linux
@@ -27,10 +25,6 @@ matrix:
2725
python: "3.9-dev"
2826
dist: bionic
2927

30-
- os: osx
31-
language: generic
32-
env:
33-
- OSXENV=2.7.14
3428
- os: osx
3529
language: generic
3630
env:

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
Used to document all changes from previous releases and collect changes
44
until the next release.
55

6+
# Latest
7+
8+
# Dropping Python 2 support
9+
10+
Python 2 has reached end of life. The codebase has been cleaned from Python 2 and Python 3 compatible code, all tests now run exclusively on Python 3 versions.
11+
12+
# Features
13+
- `odml.save` and `odmlparser.ODMLWriter` now support additional keywords. See issue #402 and PR #403 for details.
14+
15+
616
# Version 1.5.1
717

818
# RDF Subclassing feature

appveyor.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ image: Visual Studio 2017
44

55
environment:
66
matrix:
7-
- PYTHON: "C:\\Python27"
8-
PYVER: 2
9-
BITS: 32
107
- PYTHON: "C:\\Python36"
118
PYVER: 3
129
BITS: 32
@@ -16,9 +13,6 @@ environment:
1613
- PYTHON: "C:\\Python38"
1714
PYVER: 3
1815
BITS: 32
19-
- PYTHON: "C:\\Python27-x64"
20-
PYVER: 2
21-
BITS: 64
2216
- PYTHON: "C:\\Python36-x64"
2317
PYVER: 3
2418
BITS: 64

odml/dtypes.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
self = sys.modules[__name__].__dict__
1212

13-
try:
14-
unicode = unicode
15-
except NameError:
16-
unicode = str
17-
1813
FORMAT_DATE = "%Y-%m-%d"
1914
FORMAT_DATETIME = "%Y-%m-%d %H:%M:%S"
2015
FORMAT_TIME = "%H:%M:%S"
@@ -103,7 +98,7 @@ def valid_type(dtype):
10398
if dtype is None:
10499
return True
105100

106-
if not isinstance(dtype, str) and not isinstance(dtype, unicode):
101+
if not isinstance(dtype, str):
107102
return False
108103

109104
dtype = dtype.lower()
@@ -152,14 +147,13 @@ def set(value, dtype=None):
152147
"""
153148
if not dtype:
154149
return str_set(value)
150+
155151
if dtype.endswith("-tuple"):
156152
return tuple_set(value)
157-
if sys.version_info > (3, 0):
158-
if isinstance(value, str):
159-
return str_set(value)
160-
else:
161-
if isinstance(value, (str, unicode)):
162-
return str_set(value)
153+
154+
if isinstance(value, str):
155+
return str_set(value)
156+
163157
return self.get(dtype + "_set", str_set)(value)
164158

165159

@@ -206,9 +200,6 @@ def str_get(string):
206200
if string in [None, "", [], {}]:
207201
return default_values("string")
208202

209-
if sys.version_info < (3, 0):
210-
return unicode(string)
211-
212203
return str(string)
213204

214205

@@ -296,7 +287,7 @@ def boolean_get(string):
296287
if string in [None, "", [], {}]:
297288
return default_values("boolean")
298289

299-
if isinstance(string, (unicode, str)):
290+
if isinstance(string, str):
300291
string = string.lower()
301292

302293
truth = ["true", "1", True, "t"] # be kind, spec only accepts True / False

odml/format.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
XML and RDF attributes to their Python class equivalents.
44
"""
55

6-
import sys
7-
86
from rdflib import Namespace
97

108
import odml
@@ -76,12 +74,8 @@ def revmap(self, name):
7674
if self._rev_map is None:
7775
# create the reverse map only if requested
7876
self._rev_map = {}
79-
if sys.version_info < (3, 0):
80-
for k, val in self._map.iteritems():
81-
self._rev_map[val] = k
82-
else:
83-
for k, val in self._map.items():
84-
self._rev_map[val] = k
77+
for k, val in self._map.items():
78+
self._rev_map[val] = k
8579

8680
return self._rev_map.get(name)
8781

odml/property.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ def odml_tuple_import(t_count, new_value):
2929
:param new_value: string containing an odml style tuple list.
3030
:return: list of odml style tuples.
3131
"""
32-
try:
33-
unicode = unicode
34-
except NameError:
35-
unicode = str
36-
3732
if not isinstance(new_value, (list, tuple)) and \
3833
not isinstance(new_value[0], (list, tuple)):
3934
new_value = [new_value]
@@ -48,9 +43,6 @@ def odml_tuple_import(t_count, new_value):
4843
n_val_str += str(tuple_val) + "; "
4944
return_value += [n_val_str[:-2] + ")"]
5045
else:
51-
#non-unicode handling needed for python2
52-
if len(n_val) != 1 and not isinstance(n_val[0], unicode):
53-
n_val = n_val.encode('utf-8')
5446
cln = n_val.strip()
5547
br_check = cln.count("(") == cln.count(")")
5648
sep_check = t_count == 1 or cln.count("(") == (cln.count(";") / (t_count - 1))

odml/scripts/odml_convert.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737

3838
from odml.tools.converters import VersionConverter as VerConf
3939

40-
try:
41-
unicode = unicode
42-
except NameError:
43-
unicode = str
44-
4540

4641
def run_conversion(file_list, output_dir, report, source_format="XML"):
4742
"""
@@ -56,7 +51,7 @@ def run_conversion(file_list, output_dir, report, source_format="XML"):
5651
# Exceptions are kept as broad as possible to ignore any non-odML or
5752
# invalid odML files and ensuring everything that can be will be converted.
5853
for curr_file in file_list:
59-
file_path = unicode(curr_file.absolute())
54+
file_path = str(curr_file.absolute())
6055
report.write("[Info] Handling file '%s'\n" % file_path)
6156
# When loading the current file succeeds, it is
6257
# a recent odML format file and can be ignored.

odml/scripts/odml_to_rdf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
from odml.tools.odmlparser import ODMLReader, ODMLWriter
4040
from odml.tools.converters import VersionConverter as VerConf
4141

42-
try:
43-
unicode = unicode
44-
except NameError:
45-
unicode = str
46-
4742

4843
def run_rdf_export(odml_file, export_dir):
4944
"""
@@ -75,7 +70,7 @@ def run_conversion(file_list, output_dir, rdf_dir, report, source_format="XML"):
7570
# Exceptions are kept as broad as possible to ignore any non-odML or
7671
# invalid odML files and ensuring everything that can be will be converted.
7772
for curr_file in file_list:
78-
file_path = unicode(curr_file.absolute())
73+
file_path = str(curr_file.absolute())
7974
report.write("[Info] Handling file '%s'\n" % file_path)
8075
# When loading the current file succeeds, it is
8176
# a recent odML format file and can be exported

odml/templates.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import os
6-
import sys
76
import tempfile
87
import threading
98
try:
@@ -65,8 +64,7 @@ def cache_load(url):
6564
dati.fromtimestamp(os.path.getmtime(cache_file)) < (dati.now() - CACHE_AGE):
6665
try:
6766
data = urllib2.urlopen(url).read()
68-
if sys.version_info.major > 2:
69-
data = data.decode("utf-8")
67+
data = data.decode("utf-8")
7068
except (ValueError, URLError) as exc:
7169
msg = "Failed to load resource from '%s': %s" % (url, exc)
7270
exc.args = (msg,) # needs to be a tuple

odml/terminology.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import datetime
66
import os
7-
import sys
87
import tempfile
98
import threading
109
try:
@@ -47,8 +46,7 @@ def cache_load(url, replace_file=False):
4746
datetime.datetime.now() - CACHE_AGE:
4847
try:
4948
data = urllib2.urlopen(url).read()
50-
if sys.version_info.major > 2:
51-
data = data.decode("utf-8")
49+
data = data.decode("utf-8")
5250
except Exception as exc:
5351
print("failed loading '%s': %s" % (url, exc))
5452
return

0 commit comments

Comments
 (0)