__init__.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """SPARQL implementation for RDFLib
  2. !!! example "New in version 4.0"
  3. """
  4. from importlib.metadata import entry_points
  5. from typing import TYPE_CHECKING
  6. SPARQL_LOAD_GRAPHS = True
  7. """
  8. If True, using FROM <uri> and FROM NAMED <uri>
  9. will load/parse more data
  10. """
  11. SPARQL_DEFAULT_GRAPH_UNION = True
  12. """
  13. If True - the default graph in the RDF Dataset is the union of all
  14. named graphs (like RDFLib's ConjunctiveGraph)
  15. """
  16. CUSTOM_EVALS = {}
  17. """
  18. Custom evaluation functions
  19. These must be functions taking (ctx, part) and raise
  20. NotImplementedError if they cannot handle a certain part
  21. """
  22. PLUGIN_ENTRY_POINT = "rdf.plugins.sparqleval"
  23. from . import operators, parser, parserutils
  24. from .processor import prepareQuery, prepareUpdate, processUpdate
  25. assert parser
  26. assert operators
  27. assert parserutils
  28. all_entry_points = entry_points()
  29. if hasattr(all_entry_points, "select"):
  30. for ep in all_entry_points.select(group=PLUGIN_ENTRY_POINT):
  31. CUSTOM_EVALS[ep.name] = ep.load()
  32. else:
  33. # Prior to Python 3.10, this returns a dict instead of the selection interface
  34. if TYPE_CHECKING:
  35. assert isinstance(all_entry_points, dict)
  36. for ep in all_entry_points.get(PLUGIN_ENTRY_POINT, []):
  37. CUSTOM_EVALS[ep.name] = ep.load()
  38. __all__ = [
  39. "prepareQuery",
  40. "prepareUpdate",
  41. "processUpdate",
  42. "operators",
  43. "parser",
  44. "parserutils",
  45. "CUSTOM_EVALS",
  46. ]