Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/lxml-5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholascar authored Jul 23, 2024
2 parents a322c77 + ea0c42c commit 9d3d7a5
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ ci:
# https://pre-commit.com/#adding-pre-commit-plugins-to-your-project
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.4.9
hooks:
- id: ruff
args: ["--fix"]
- repo: https://github.com/psf/black-pre-commit-mirror
# WARNING: version should be the same as in `pyproject.toml`
rev: "24.4.0"
rev: "24.4.2"
hooks:
- id: black
pass_filenames: false
Expand Down
2 changes: 1 addition & 1 deletion docker/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/library/python:3.12.2-slim@sha256:5c73034c2bc151596ee0f1335610735162ee2b148816710706afec4757ad5b1e
FROM docker.io/library/python:3.12.4-slim@sha256:f11725aba18c19664a408902103365eaf8013823ffc56270f921d1dc78a198cb

COPY docker/latest/requirements.txt /var/tmp/build/

Expand Down
2 changes: 1 addition & 1 deletion docs/intro_to_parsing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Working with multi-graphs
-------------------------

To read and query multi-graphs, that is RDF data that is context-aware, you need to use rdflib's
:class:`rdflib.ConjunctiveGraph` or :class:`rdflib.Dataset` class. These are extensions to :class:`rdflib.Graph` that
:class:`rdflib.Dataset` class. This an extension to :class:`rdflib.Graph` that
know all about quads (triples + graph IDs).

If you had this multi-graph data file (in the ``trig`` format, using new-style ``PREFIX`` statement (not the older
Expand Down
2 changes: 1 addition & 1 deletion docs/merging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In RDFLib, blank nodes are given unique IDs when parsing, so graph merging can b
``graph`` now contains the merged graph of ``input1`` and ``input2``.


.. note:: However, the set-theoretic graph operations in RDFLib are assumed to be performed in sub-graphs of some larger data-base (for instance, in the context of a :class:`~rdflib.graph.ConjunctiveGraph`) and assume shared blank node IDs, and therefore do NOT do *correct* merging, i.e.::
.. note:: However, the set-theoretic graph operations in RDFLib are assumed to be performed in sub-graphs of some larger data-base (for instance, in the context of a :class:`~rdflib.graph.Dataset`) and assume shared blank node IDs, and therefore do NOT do *correct* merging, i.e.::

from rdflib import Graph

Expand Down
5 changes: 2 additions & 3 deletions docs/plugin_parsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ xml :class:`~rdflib.plugins.parsers.rdfxml.RDFXMLParser`

Multi-graph IDs
---------------
Note that for correct parsing of multi-graph data, e.g. Trig, HexT, etc., into a ``ConjunctiveGraph`` or a ``Dataset``,
as opposed to a context-unaware ``Graph``, you will need to set the ``publicID`` of the ``ConjunctiveGraph`` a
``Dataset`` to the identifier of the ``default_context`` (default graph), for example::
Note that for correct parsing of multi-graph data, e.g. Trig, HexT, etc., into a ``Dataset``,
as opposed to a context-unaware ``Graph``, you will need to set the ``publicID`` of the ``Dataset`` to the identifier of the ``default_context`` (default graph), for example::

d = Dataset()
d.parse(
Expand Down
173 changes: 87 additions & 86 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pytest = "^7.1.3"
pytest-cov = ">=4,<6"
coverage = {version = "^7.0.1", extras = ["toml"]}
types-setuptools = ">=68.0.0.3,<70.0.0.0"
setuptools = ">=68,<70"
setuptools = ">=68,<72"
wheel = ">=0.42,<0.44"

[tool.poetry.group.docs.dependencies]
Expand All @@ -67,7 +67,7 @@ sphinx-autodoc-typehints = "^1.17.1"
typing-extensions = "^4.5.0"

[tool.poetry.group.lint.dependencies]
ruff = ">=0.0.286,<0.4.2"
ruff = ">=0.0.286,<0.5.5"

[tool.poetry.extras]
berkeleydb = ["berkeleydb"]
Expand Down
15 changes: 15 additions & 0 deletions rdflib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
Conjunctive Graph
-----------------
.. warning::
ConjunctiveGraph is deprecated, use :class:`~rdflib.graph.Dataset` instead.
A Conjunctive Graph is the most relevant collection of graphs that are
considered to be the boundary for closed world assumptions. This
boundary is equivalent to that of the store instance (which is itself
Expand Down Expand Up @@ -249,6 +252,7 @@
import logging
import pathlib
import random
import warnings
from io import BytesIO
from typing import (
IO,
Expand Down Expand Up @@ -1893,6 +1897,9 @@ class ConjunctiveGraph(Graph):
"""A ConjunctiveGraph is an (unnamed) aggregation of all the named
graphs in a store.
.. warning::
ConjunctiveGraph is deprecated, use :class:`~rdflib.graph.Dataset` instead.
It has a ``default`` graph, whose name is associated with the
graph throughout its life. :meth:`__init__` can take an identifier
to use as the name of this default graph or it will assign a
Expand All @@ -1910,6 +1917,14 @@ def __init__(
default_graph_base: Optional[str] = None,
):
super(ConjunctiveGraph, self).__init__(store, identifier=identifier)

if type(self) is ConjunctiveGraph:
warnings.warn(
"ConjunctiveGraph is deprecated, use Dataset instead.",
DeprecationWarning,
stacklevel=2,
)

assert self.store.context_aware, (
"ConjunctiveGraph must be backed by" " a context aware store."
)
Expand Down
7 changes: 7 additions & 0 deletions test/test_conjunctivegraph/test_conjunctive_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def test_context_namespaces():
assert ("ex", ns) in g.namespace_manager.namespaces()


def test_deprecated():
with pytest.warns(
DeprecationWarning, match="ConjunctiveGraph is deprecated, use Dataset instead."
):
ConjunctiveGraph()


def get_graph_ids_tests():
def check(kws):
cg = ConjunctiveGraph()
Expand Down
12 changes: 12 additions & 0 deletions test/test_dataset/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
import tempfile
import warnings
from test.data import CONTEXT1, LIKES, PIZZA, TAREK
from test.utils.namespace import EGSCHEME

Expand Down Expand Up @@ -261,3 +262,14 @@ def test_subgraph_without_identifier() -> None:
) == ("genid", genid_prefix)

assert f"{subgraph.identifier}".startswith(genid_prefix)


def test_not_deprecated():
"""
Ensure Dataset does not trigger the deprecation warning
from the ConjunctiveGraph superclass.
"""

with warnings.catch_warnings():
warnings.simplefilter("error")
Dataset()
21 changes: 14 additions & 7 deletions test/test_misc/test_parse_file_guess_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_n3(self) -> None:
g.parse(os.path.join(TEST_DATA_DIR, "example-lots_of_graphs.n3")), Graph
)

def test_warning(self) -> None:
def test_warning(self, caplog: pytest.LogCaptureFixture) -> None:
g = Graph()
graph_logger = logging.getLogger("rdflib") # noqa: F841

Expand All @@ -78,9 +78,16 @@ def test_warning(self) -> None:
),
str(newpath),
)
with pytest.raises(ParserError, match=r"Could not guess RDF format"):
with pytest.warns(
UserWarning,
match="does not look like a valid URI, trying to serialize this will break.",
) as logwarning: # noqa: F841
g.parse(str(newpath))
with pytest.raises(
ParserError, match=r"Could not guess RDF format"
), caplog.at_level("WARNING"):
g.parse(str(newpath))

assert any(
rec.levelno == logging.WARNING
and (
"does not look like a valid URI, trying to serialize this will break."
in rec.message
)
for rec in caplog.records
)

0 comments on commit 9d3d7a5

Please sign in to comment.