Skip to content

Commit 054e8a3

Browse files
authored
Merge pull request #419 from mpsonntag/updateRDFlib
rdflib dependency update, preparation release v1.5.3
2 parents a5e6f12 + ffc3362 commit 054e8a3

19 files changed

+129
-72
lines changed

.github/workflows/run-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest]
16-
python-version: ["3.8", "3.9", "3.10"]
16+
python-version: ["3.8", "3.9", "3.10", "3.11"]
1717
steps:
1818
- uses: actions/checkout@v2
1919
- name: Setup Python ${{ matrix.python-version }}
@@ -35,7 +35,7 @@ jobs:
3535
strategy:
3636
matrix:
3737
os: [ubuntu-20.04]
38-
python-version: ["3.6", "3.7"]
38+
python-version: ["3.7"]
3939
steps:
4040
- uses: actions/checkout@v2
4141
- name: Setup Python ${{ matrix.python-version }}
@@ -61,7 +61,7 @@ jobs:
6161
# and fails on install. MacOS Python version 3.9 build will stay
6262
# disabled until this is resolved.
6363
#python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
64-
python-version: ["3.6", "3.7", "3.8", "3.10"]
64+
python-version: ["3.7", "3.8", "3.10"]
6565
steps:
6666
- uses: actions/checkout@v2
6767
- name: Setup Python ${{ matrix.python-version }}

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ Used to document all changes from previous releases and collect changes
44
until the next release.
55

66

7+
# Version 1.5.3
8+
9+
## Support rdflib version 6+
10+
11+
The rdflib upgrade from version 5.0.0 to 6+ introduced breaking changes
12+
in the rdflib library. This update fixes these breaks without changing
13+
functionality, unpins the rdflib version and defaults to the latest
14+
version on install.
15+
16+
## Dropping official support for Python 3.5 and 3.6
17+
18+
The introduction of the rdflib 6+ library restricts the
19+
Python support for 3.7+.
20+
21+
It is still possible to install odml with a Python version <=3.6,
22+
but these versions are no longer tested and officially supported.
23+
24+
725
# Version 1.5.2
826

927
## Pinning rdflib version to 5.0.0 until further notice

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ release notes](https://github.com/G-Node/python-odml/releases).
7777

7878
# Dependencies
7979

80-
* Python 3.6+
80+
* Python 3.7+
8181
* Python packages:
8282

8383
* lxml (version 3.7.2)
@@ -101,7 +101,9 @@ release notes](https://github.com/G-Node/python-odml/releases).
101101

102102
## Previous Python versions
103103

104-
Python 2 has reached end of life. We will not keep any future versions of odml Python 2 compatible and will completely drop support for Python 2 with August 2020. We also recommend using a Python version >= 3.6. If a Python version < 3.6 is a requirement, the following dependency needs to be installed as well:
104+
Python 2 has reached end of life. Current and future versions of odml are not Python 2 compatible. We removed support
105+
for Python 2 in August 2020 with version 1.5.2. We also recommend using a Python version >= 3.7. If a
106+
Python version < 3.7 is a requirement, the following dependency needs to be installed as well:
105107

106108
* pip install
107109
* enum34 (version 0.4.4)

appveyor.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ image: Visual Studio 2017
44

55
environment:
66
matrix:
7-
- PYTHON: "C:\\Python36"
8-
PYVER: 3
9-
BITS: 32
107
- PYTHON: "C:\\Python37"
118
PYVER: 3
129
BITS: 32
@@ -21,9 +18,10 @@ environment:
2118
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
2219
PYVER: 3
2320
BITS: 32
24-
- PYTHON: "C:\\Python36-x64"
21+
- PYTHON: "C:\\Python311"
22+
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
2523
PYVER: 3
26-
BITS: 64
24+
BITS: 32
2725
- PYTHON: "C:\\Python37-x64"
2826
PYVER: 3
2927
BITS: 64
@@ -38,6 +36,10 @@ environment:
3836
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
3937
PYVER: 3
4038
BITS: 64
39+
- PYTHON: "C:\\Python311-x64"
40+
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
41+
PYVER: 3
42+
BITS: 64
4143

4244
init:
4345
- "ECHO %PYTHON% %vcvars% (%bits%)"

doc/support-classes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ These classes are
77

88

99
Validation
10-
-------
10+
----------
1111
.. autoclass:: odml.validation.Validation
1212
:members:
1313
:inherited-members:

doc/tutorial.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
=============
32
odML Tutorial
43
=============
54

65
:Author:
7-
Lyuba Zehl;
6+
Lyuba Zehl, Michael Sonntag;
87
based on work by Hagen Fritsch
98
:Release:
10-
1.4
9+
1.5
1110
:License:
1211
Creative Commons Attribution-ShareAlike 4.0 International
1312
`License <http://creativecommons.org/licenses/by-sa/4.0/>`_
@@ -89,7 +88,7 @@ the project name `python-odml <https://github.com/G-Node/python-odml>`_.
8988
Dependencies
9089
------------
9190

92-
The Python-odML library (version 1.4+) runs under Python 3.6+.
91+
The Python-odML library (version 1.5+) is tested and fully supported using Python 3.7+.
9392

9493
Additionally, the Python-odML library depends on the lxml, pyyaml and rdflib python packages.
9594

@@ -102,7 +101,9 @@ On Ubuntu, the dependency packages are available as ``python-lxml``, ``python-ya
102101
Note that on Ubuntu 14.04, the latter package additionally requires the
103102
installation of ``libxml2-dev``, ``libxslt1-dev``, and ``lib32z1-dev``.
104103

105-
Python 2 has reached end of life. We will not keep any future versions of odml Python 2 compatible and also recommend using a Python version >= 3.6. If a Python version < 3.6 is a requirement, the following dependency needs to be installed as well:
104+
Python 2 has reached end of life. Current and future versions of odml are not Python 2 compatible. We removed support
105+
for Python 2 in August 2020 with version 1.5.2. We also recommend using a Python version >= 3.7. If a
106+
Python version < 3.7 is a requirement, the following dependency needs to be installed as well:
106107

107108
The ``enum34`` package with a ``pip`` installation or ``python-enum`` using the OS package manager.
108109

odml/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _format_warning(warn_msg, *args, **kwargs):
3333
msg = "Python 2 has reached end of live."
3434
msg += "\n\todML support for Python 2 has been dropped."
3535
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
36-
elif _python_version.major == 3 and _python_version.minor < 6:
36+
elif _python_version.major == 3 and _python_version.minor < 7:
3737
msg = "The '%s' package is not tested with your Python version. " % __name__
3838
msg += "\n\tPlease consider upgrading to the latest Python distribution."
3939
warnings.warn(msg)

odml/info.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"VERSION": "1.5.2",
2+
"VERSION": "1.5.3",
33
"FORMAT_VERSION": "1.1",
44
"AUTHOR": "Hagen Fritsch, Jan Grewe, Christian Kellner, Achilleas Koutsou, Michael Sonntag, Lyuba Zehl",
55
"COPYRIGHT": "(c) 2011-2023, German Neuroinformatics Node",
@@ -8,10 +8,10 @@
88
"CLASSIFIERS": [
99
"Development Status :: 5 - Production/Stable",
1010
"Programming Language :: Python",
11-
"Programming Language :: Python :: 3.6",
1211
"Programming Language :: Python :: 3.7",
1312
"Programming Language :: Python :: 3.8",
1413
"Programming Language :: Python :: 3.9",
14+
"Programming Language :: Python :: 3.10",
1515
"Topic :: Scientific/Engineering",
1616
"Intended Audience :: Science/Research",
1717
"License :: OSI Approved :: BSD License"

odml/tools/rdf_converter.py

+55-19
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
import warnings
1010

1111
from io import StringIO
12+
13+
from rdflib import __version__ as rdflib_version
1214
from rdflib import Graph, Literal, URIRef
1315
from rdflib.graph import Seq
16+
try:
17+
from rdflib.container import Seq as CollSeq
18+
except ImportError as exc:
19+
# annoy people to upgrade their rdflib version but still support the usage
20+
print("deprecated rdflib version. Please upgrade to the latest version.")
1421
from rdflib.namespace import XSD, RDF, RDFS
1522

1623
import yaml
@@ -25,6 +32,14 @@
2532
ODML_NS = Format.namespace()
2633

2734

35+
def rdflib_version_major():
36+
version_split = rdflib_version.split(".")
37+
if len(version_split) < 3 or not version_split[0].isdigit():
38+
print("Could not parse rdflib version %s" % rdflib_version)
39+
return 0
40+
return int(version_split[0])
41+
42+
2843
def load_rdf_subclasses():
2944
"""
3045
load_rdf_subclasses loads odml section types to RDF Section subclass types
@@ -133,16 +148,23 @@ def save_odml_values(self, parent_node, rdf_predicate, values):
133148
# Once rdflib upgrades this should be reversed to RDF:li again!
134149
# see https://github.com/RDFLib/rdflib/issues/280
135150
# -- keep until supported
136-
# bag = URIRef(ODML_NS + str(uuid.uuid4()))
137-
# self.graph.add((bag, RDF.type, RDF.Bag))
138-
# self.graph.add((curr_node, fmt.rdf_map(k), bag))
139-
# for curr_val in values:
140-
# self.graph.add((bag, RDF.li, Literal(curr_val)))
141-
counter = 1
142-
for curr_val in values:
143-
custom_predicate = "%s_%s" % (str(RDF), counter)
144-
self.graph.add((seq, URIRef(custom_predicate), Literal(curr_val)))
145-
counter = counter + 1
151+
#bag = URIRef(ODML_NS + str(uuid.uuid4()))
152+
#self.graph.add((bag, RDF.type, RDF.Bag))
153+
#self.graph.add((parent_node, rdf_predicate, bag))
154+
#for curr_val in values:
155+
# self.graph.add((bag, RDF.li, Literal(curr_val)))
156+
if rdflib_version_major() >= 6:
157+
seq_list = []
158+
for curr_val in values:
159+
seq_list.append(Literal(curr_val))
160+
_ = CollSeq(self.graph, seq, seq_list)
161+
else:
162+
# manually create and use the value blank nodes order
163+
counter = 1
164+
for curr_val in values:
165+
custom_predicate = "%s_%s" % (str(RDF), counter)
166+
self.graph.add((seq, URIRef(custom_predicate), Literal(curr_val)))
167+
counter = counter + 1
146168

147169
def save_odml_list(self, parent_node, rdf_predicate, odml_list):
148170
"""
@@ -349,9 +371,13 @@ def _parse_custom_subclasses(self, custom_subclasses):
349371
self.section_subclasses[k] = val
350372

351373
def __str__(self):
374+
if rdflib_version_major() >= 6:
375+
return self.convert_to_rdf().serialize(format='turtle')
352376
return self.convert_to_rdf().serialize(format='turtle').decode("utf-8")
353377

354378
def __unicode__(self):
379+
if rdflib_version_major() >= 6:
380+
return self.convert_to_rdf().serialize(format='turtle')
355381
return self.convert_to_rdf().serialize(format='turtle').decode("utf-8")
356382

357383
def get_rdf_str(self, rdf_format="turtle"):
@@ -370,6 +396,8 @@ def get_rdf_str(self, rdf_format="turtle"):
370396
msg = "%s Please choose from the list: %s" % (msg, list(RDF_CONVERSION_FORMATS))
371397
raise ValueError(msg)
372398

399+
if rdflib_version_major() >= 6:
400+
return self.convert_to_rdf().serialize(format=rdf_format)
373401
return self.convert_to_rdf().serialize(format=rdf_format).decode("utf-8")
374402

375403
def write_file(self, filename, rdf_format="turtle"):
@@ -516,18 +544,26 @@ def parse_property(self, prop_uri):
516544
if attr[0] == "value" and elems:
517545
prop_attrs[attr[0]] = []
518546

519-
# rdflib does not respect order with RDF.li items yet, see comment above
520-
# support both RDF.li and rdf:_nnn for now.
521-
# Remove rdf:_nnn once rdflib respects RDF.li order in an RDF.Seq obj.
522-
values = list(self.graph.objects(subject=elems[0], predicate=RDF.li))
523-
if values:
524-
for curr_val in values:
525-
prop_attrs[attr[0]].append(curr_val.toPython())
526-
else:
527-
# rdf:__nnn part
547+
if rdflib_version_major() >= 6:
548+
# rdflib version 6.x.x+ should support rdf:_nnn only, RDF.li
549+
# are not supported; reverse import the blank node values;
550+
# hopefully in the correct order.
528551
val_seq = Seq(graph=self.graph, subject=elems[0])
529552
for seq_item in val_seq:
530553
prop_attrs[attr[0]].append(seq_item.toPython())
554+
else:
555+
# rdflib does not respect order with RDF.li items yet, see comment above
556+
# support both RDF.li and rdf:_nnn for now.
557+
# Remove rdf:_nnn once rdflib respects RDF.li order in an RDF.Seq obj.
558+
values = list(self.graph.objects(subject=elems[0], predicate=RDF.li))
559+
if values:
560+
for curr_val in values:
561+
prop_attrs[attr[0]].append(curr_val.toPython())
562+
else:
563+
# rdf:__nnn part
564+
val_seq = Seq(graph=self.graph, subject=elems[0])
565+
for seq_item in val_seq:
566+
prop_attrs[attr[0]].append(seq_item.toPython())
531567

532568
elif attr[0] == "id":
533569
prop_attrs[attr[0]] = prop_uri.split("#", 1)[1]

requirements-test.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1+
owlrl
12
pytest
2-
owlrl==5.2.3
33
requests

scripts/release_tests/run_pypi_odml.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo
44
echo "-- MAKE SURE TO RUN THIS SCRIPT IN INTERACTIVE MODE '-i' --"
55

6-
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|")
6+
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|3.11|")
77

88
if [[ $# != 1 ]]; then
99
echo

scripts/release_tests/run_test_local_odml.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo
44
echo "-- MAKE SURE TO RUN THIS SCRIPT IN INTERACTIVE MODE '-i' --"
55

6-
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|")
6+
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|3.11|")
77

88
if [[ $# != 1 ]]; then
99
echo

scripts/release_tests/run_test_matrix.sh

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ function run_script () {
9999
fi
100100
}
101101

102+
PYVER=3.11
103+
run_script
104+
102105
PYVER=3.10
103106
run_script
104107

scripts/release_tests/run_test_pypi_nixodmlconverter.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo
44
echo "-- MAKE SURE TO RUN THIS SCRIPT IN INTERACTIVE MODE '-i' --"
55

6-
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|")
6+
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|3.11|")
77

88
if [[ $# != 1 ]]; then
99
echo

scripts/release_tests/run_test_pypi_odml.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo
44
echo "-- MAKE SURE TO RUN THIS SCRIPT IN INTERACTIVE MODE '-i' --"
55

6-
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|")
6+
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|3.11|")
77

88
if [[ $# != 1 ]]; then
99
echo

scripts/release_tests/run_test_pypi_odmltools.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
echo
44
echo "-- MAKE SURE TO RUN THIS SCRIPT IN INTERACTIVE MODE '-i' --"
55

6-
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|")
6+
PY_VER_ARRAY=("|3.5|3.6|3.7|3.8|3.9|3.10|3.11|")
77

88
if [[ $# != 1 ]]; then
99
echo

setup.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@
3131
with open('README.md') as f:
3232
description_text = f.read()
3333

34-
# pyparsing needs to be pinned to 2.4.7 for the time being. setup install fetches a pre-release
35-
# package that currently results in issues with the rdflib library.
36-
install_req = ["lxml", "pyyaml>=5.1", "rdflib==5.0.0", "docopt", "pathlib", "pyparsing==2.4.7"]
34+
install_req = ["docopt", "lxml", "pathlib", "pyyaml>=5.1", "rdflib>=6.0.0"]
35+
# owlrl depends on rdflib; update any changes in requirements-test.txt as well.
36+
tests_req = ["owlrl", "pytest", "requests"]
3737

38-
# owlrl depends on rdflib - the pinned version should be removed once the version pin has also been
39-
# removed from rdflib. Also needs to be updated in requirements-test.txt
40-
tests_req = ["pytest", "owlrl==5.2.3", "requests"]
38+
# Keep support for for Python versions below 3.7; relevant for the
39+
# rdflib usage; rdflib >= 6 does not support Python versions below 3.7.
40+
if _python_version.minor <= 6:
41+
# pyparsing needs to be pinned to 2.4.7 due to issues with the rdflib 5.0.0 library.
42+
install_req = ["docopt", "lxml", "pathlib", "pyyaml>=5.1", "rdflib==5.0.0", "pyparsing==2.4.7"]
43+
44+
# owlrl depends on rdflib and needs to be pinned to a corresponding version.
45+
tests_req = ["owlrl==5.2.3", "pytest", "requests"]
4146

4247
setup(
4348
name='odML',
@@ -66,7 +71,7 @@
6671
msg = "Python 2 has reached end of live."
6772
msg += "\n\todML support for Python 2 has been dropped."
6873
print(msg)
69-
elif _python_version.major == 3 and _python_version.minor < 6:
74+
elif _python_version.major == 3 and _python_version.minor < 7:
7075
msg = "\n\nThis package is not tested with your Python version. "
7176
msg += "\n\tPlease consider upgrading to the latest Python distribution."
7277
print(msg)

0 commit comments

Comments
 (0)