Skip to content

Commit 83fd6ed

Browse files
authored
Merge pull request #15 from casework/use_rdflib_6.0.1_features
Use rdflib 6.0.1 features
2 parents d8be3d2 + eeae6ac commit 83fd6ed

File tree

9 files changed

+13
-35
lines changed

9 files changed

+13
-35
lines changed

case_utils/__init__.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,13 @@
1313

1414
__version__ = "0.2.1"
1515

16+
import warnings
17+
1618
import rdflib.util
1719

1820
from . import local_uuid
1921

2022
def guess_format(fpath, fmap=None):
21-
"""
22-
This function is a wrapper around rdflib.util.guess_format(), adding that the .json extension should be recognized as JSON-LD.
23-
24-
:param fpath: File path.
25-
:type fpath: string
26-
27-
:param fmap: Mapper dictionary; see rdflib.util.guess_format() for further description. Note that as in rdflib 5.0.0, supplying this argument overwrites, not augments, the suffix format map used by rdflib.
28-
:type fmap: dict
29-
30-
:returns: RDF file format, fit for rdflib.Graph.parse() or .serialize(); or, None if file extension not mapped.
31-
:rtype: string
32-
"""
33-
34-
assert fmap is None or isinstance(fmap, dict), "Type check failed"
35-
36-
if fmap is None:
37-
updated_fmap = {key:rdflib.util.SUFFIX_FORMAT_MAP[key] for key in rdflib.util.SUFFIX_FORMAT_MAP}
38-
if not "json" in updated_fmap:
39-
updated_fmap["json"] = "json-ld"
40-
if not "jsonld" in updated_fmap:
41-
updated_fmap["jsonld"] = "json-ld"
42-
else:
43-
updated_fmap = {k:fmap[k] for k in fmap}
23+
warnings.warn("The functionality in case_utils.guess_format is now upstream. Please revise your code to use rdflib.util.guess_format. The function arguments remain the same. case_utils.guess_format will be removed in case_utils 0.4.0.", DeprecationWarning)
4424

45-
return rdflib.util.guess_format(fpath, updated_fmap)
25+
return rdflib.util.guess_format(fpath, fmap)

case_utils/case_sparql_construct/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def main():
4141

4242
in_graph = rdflib.Graph()
4343
for in_graph_filename in args.in_graph:
44-
in_graph.parse(in_graph_filename, format=case_utils.guess_format(in_graph_filename))
44+
in_graph.parse(in_graph_filename)
4545
_logger.debug("len(in_graph) = %d.", len(in_graph))
4646

4747
out_graph = rdflib.Graph()

case_utils/case_sparql_select/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def main():
5555

5656
graph = rdflib.Graph()
5757
for in_graph_filename in args.in_graph:
58-
graph.parse(in_graph_filename, format=case_utils.guess_format(in_graph_filename))
58+
graph.parse(in_graph_filename)
5959

6060
# Inherit prefixes defined in input context dictionary.
6161
nsdict = {k:v for (k,v) in graph.namespace_manager.namespaces()}

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ classifiers =
2020
install_requires =
2121
pandas
2222
pyparsing < 3.0.0
23-
rdflib >= 6.0.0
23+
rdflib >= 6.0.1
2424
requests
2525
tabulate
2626
packages = find:

tests/case_file/test_case_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
def load_graph(filename):
4141
in_graph = rdflib.Graph()
42-
in_graph.parse(filename, format=rdflib.util.guess_format(filename))
42+
in_graph.parse(filename)
4343
return in_graph
4444

4545
@pytest.fixture

tests/case_sparql_construct/test_case_sparql_construct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _test_templates_with_blank_nodes_result(filename):
2323
ground_truth_negative = set()
2424

2525
graph = rdflib.Graph()
26-
graph.parse(filename, format=case_utils.guess_format(filename))
26+
graph.parse(filename)
2727

2828
computed = set()
2929
query_string = """\

tests/case_utils/test_guess_format.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ def test_rdflib_util_guess_format_ttl_default():
3838
def test_rdflib_util_guess_format_ttl_fmap():
3939
assert rdflib.util.guess_format(PATH_TO_TTL, FMAP_XHTML_GRDDL) == "turtle", "Failed to recognize .ttl RDF file extension when using fmap"
4040

41-
@pytest.mark.xfail(reason="rdflib 5.0.0 known to not recognize .json", strict=True)
4241
def test_rdflib_util_guess_format_json():
4342
assert rdflib.util.guess_format(PATH_TO_JSON) == "json-ld", "Failed to recognize .json RDF file extension"
4443

45-
@pytest.mark.xfail(reason="rdflib 5.0.0 known to not recognize .jsonld", strict=True)
4644
def test_rdflib_util_guess_format_jsonld():
4745
assert rdflib.util.guess_format(PATH_TO_JSONLD) == "json-ld", "Failed to recognize .jsonld RDF file extension"
4846

tests/src/glom_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
def main():
2525
g = rdflib.Graph()
2626
for in_graph in args.in_graph:
27-
g.parse(in_graph, format=case_utils.guess_format(in_graph))
28-
g.serialize(args.out_graph, format=case_utils.guess_format(args.out_graph))
27+
g.parse(in_graph)
28+
g.serialize(args.out_graph)
2929

3030
if __name__ == "__main__":
3131
import argparse

tests/src/isomorphic_diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def main():
5252
g1 = rdflib.Graph()
5353
g2 = rdflib.Graph()
5454

55-
g1.parse(args.in_graph_1, format=case_utils.guess_format(args.in_graph_1))
56-
g2.parse(args.in_graph_2, format=case_utils.guess_format(args.in_graph_2))
55+
g1.parse(args.in_graph_1)
56+
g2.parse(args.in_graph_2)
5757

5858
#_logger.debug("type(g1) = %r.", type(g1))
5959
#_logger.debug("type(g2) = %r.", type(g2))

0 commit comments

Comments
 (0)