Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop use_2to3 and restore rdflib interoperability #105

Merged
merged 7 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion rdflib_jsonld/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
>>> register('json-ld', Serializer, 'rdflib_jsonld.serializer', 'JsonLDSerializer')

>>> from rdflib import Graph
>>> from rdflib import __version__ as rdflib_version

>>> testrdf = '''
... @prefix dcterms: <http://purl.org/dc/terms/> .
Expand All @@ -19,7 +20,12 @@

>>> g = Graph().parse(data=testrdf, format='n3')

>>> print(g.serialize(format='json-ld', indent=4).decode())
>>> g_display = g.serialize(format='json-ld', indent=4)
>>> if rdflib_version < "6.0.0":
... # rdflib < 6.0.0 returns bytes when no
... # destination is provided.
... g_display = g_display.decode()
>>> print(g_display)
[
{
"@id": "http://example.org/about",
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def md2pypi(filename):
url="https://github.com/RDFLib/rdflib-jsonld",
license="BSD",
packages=["rdflib_jsonld"],
use_2to3=True,
zip_safe=False,
platforms=["any"],
classifiers=[
Expand All @@ -93,7 +92,7 @@ def md2pypi(filename):
"Natural Language :: English",
],
test_suite="nose.collector",
install_requires=["rdflib>=5.0.0"],
install_requires=["rdflib"],
tests_require=["nose"],
command_options={
"build_sphinx": {
Expand Down
28 changes: 20 additions & 8 deletions test/runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import with_statement
import json
import rdflib
from rdflib import ConjunctiveGraph
from rdflib.compare import isomorphic
from rdflib_jsonld._compat import IS_PY3
Expand All @@ -9,14 +10,25 @@


# monkey-patch NTriplesParser to keep source bnode id:s ..
from rdflib.plugins.parsers.ntriples import NTriplesParser, r_nodeid, bNode


def _preserving_nodeid(self):
if not self.peek("_"):
return False
return bNode(self.eat(r_nodeid).group(1))

from rdflib.plugins.parsers.ntriples import r_nodeid, bNode
# NTriplesParser was renamed between 5.0.0 and 6.0.0.
if rdflib.__version__ < "6":
from rdflib.plugins.parsers.ntriples import NTriplesParser
else:
from rdflib.plugins.parsers.ntriples import W3CNTriplesParser as NTriplesParser


# NTriplesParser.nodeid changed its function signature between 5.0.0 and 6.0.0.
if rdflib.__version__ < "6":
def _preserving_nodeid(self):
if not self.peek("_"):
return False
return bNode(self.eat(r_nodeid).group(1))
else:
def _preserving_nodeid(self, bnode_context=None):
if not self.peek("_"):
return False
return bNode(self.eat(r_nodeid).group(1))

NTriplesParser.nodeid = _preserving_nodeid
# .. and accept bnodes everywhere
Expand Down
4 changes: 3 additions & 1 deletion test/test_compaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ def case(*args):

def run(data, expected):
g = Graph().parse(data=data, format="turtle")
result = g.serialize(format="json-ld", context=expected["@context"]).decode("utf-8")
result = g.serialize(format="json-ld", context=expected["@context"])
if isinstance(result, bytes):
result = result.decode("utf-8")
result = json.loads(result)

sort_graph(result)
Expand Down