Skip to content

Commit

Permalink
Bump rdflib dependency to 6.0.1, deprecating local guess_format
Browse files Browse the repository at this point in the history
rdflib 6.0.1 upgraded `guess_format()` to report JSON-LD (via PRs 1403
and 1408).  With the functionality upstream, this patch moves towards
completing tech. transfer by deprecating the local implementation.

References:
* RDFLib/rdflib#1403
* RDFLib/rdflib#1408

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
  • Loading branch information
ajnelson-nist committed Sep 28, 2021
1 parent d8be3d2 commit ce43114
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
28 changes: 4 additions & 24 deletions case_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,13 @@

__version__ = "0.2.1"

import warnings

import rdflib.util

from . import local_uuid

def guess_format(fpath, fmap=None):
"""
This function is a wrapper around rdflib.util.guess_format(), adding that the .json extension should be recognized as JSON-LD.
:param fpath: File path.
:type fpath: string
: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.
:type fmap: dict
:returns: RDF file format, fit for rdflib.Graph.parse() or .serialize(); or, None if file extension not mapped.
:rtype: string
"""

assert fmap is None or isinstance(fmap, dict), "Type check failed"

if fmap is None:
updated_fmap = {key:rdflib.util.SUFFIX_FORMAT_MAP[key] for key in rdflib.util.SUFFIX_FORMAT_MAP}
if not "json" in updated_fmap:
updated_fmap["json"] = "json-ld"
if not "jsonld" in updated_fmap:
updated_fmap["jsonld"] = "json-ld"
else:
updated_fmap = {k:fmap[k] for k in fmap}
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)

return rdflib.util.guess_format(fpath, updated_fmap)
return rdflib.util.guess_format(fpath, fmap)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers =
install_requires =
pandas
pyparsing < 3.0.0
rdflib >= 6.0.0
rdflib >= 6.0.1
requests
tabulate
packages = find:
Expand Down
2 changes: 0 additions & 2 deletions tests/case_utils/test_guess_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def test_rdflib_util_guess_format_ttl_default():
def test_rdflib_util_guess_format_ttl_fmap():
assert rdflib.util.guess_format(PATH_TO_TTL, FMAP_XHTML_GRDDL) == "turtle", "Failed to recognize .ttl RDF file extension when using fmap"

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

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

Expand Down

0 comments on commit ce43114

Please sign in to comment.