Skip to content

Commit 2f9cccf

Browse files
author
Nicholas Car
authored
Merge branch 'master' into default_prefixes
2 parents 4c4a0ea + d711a35 commit 2f9cccf

File tree

122 files changed

+2585
-2078
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2585
-2078
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trim_trailing_whitespace = false
2020
[*.{js,py,pyi,toml,yml,yaml}]
2121
charset = utf-8
2222

23-
[*.{yaml,yml,json}]
23+
[*.{yaml,yml,json,jsonld}]
2424
indent_style = space
2525
indent_size = 2
2626

.github/workflows/validate.yaml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,3 @@ jobs:
104104
export TOXENV
105105
export TOX_EXTRA_COMMAND="${{ matrix.TOX_EXTRA_COMMAND }}"
106106
"${test_harness[@]}" python -m tox
107-
docs:
108-
runs-on: ubuntu-latest
109-
strategy:
110-
fail-fast: false
111-
matrix:
112-
tox-env: ["docs"]
113-
steps:
114-
- uses: actions/checkout@v2
115-
- name: Set up Python ${{env.DEFAULT_PYTHON}}
116-
uses: actions/setup-python@v2
117-
with:
118-
python-version: ${{env.DEFAULT_PYTHON}}
119-
- name: Get pip cache dir
120-
id: pip-cache
121-
shell: bash
122-
run: |
123-
python -m ensurepip --upgrade
124-
echo "::set-output name=dir::$(pip cache dir)"
125-
- name: Cache pip
126-
uses: actions/cache@v2
127-
with:
128-
path: ${{ steps.pip-cache.outputs.dir }}
129-
key: tox-${{ matrix.tox-env }}-pip-v1-${{
130-
hashFiles('**/setup.py', '**/requirements*.txt') }}
131-
restore-keys: |
132-
tox-${{ matrix.tox-env }}-pip-v1-
133-
- name: Install dependencies
134-
shell: bash
135-
run: |
136-
python -m pip install tox tox-gh-actions
137-
- name: Run ${{ matrix.tox-env }}
138-
shell: bash
139-
run: |
140-
python -m tox -e ${{ matrix.tox-env }}

.readthedocs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ python:
1414
path: .
1515
extra_requirements:
1616
- docs
17+
18+
sphinx:
19+
fail_on_warning: true

docs/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,9 @@ def find_version(filename):
243243
html_experimental_html5_writer = True
244244

245245
needs_sphinx = "4.1.2"
246+
247+
suppress_warnings = [
248+
# This is here to prevent:
249+
# "WARNING: more than one target found for cross-reference"
250+
"ref.python",
251+
]

docs/developers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ met:
3838

3939
There should either be existing tests that cover the changed code and
4040
behaviour, or the PR should include tests. For more information about what is
41-
considered adequate testing see the `Tests directory for examples <https://github.com/RDFLib/rdflib/tree/master/test>`_.
41+
considered adequate testing see the :ref:`Tests section <tests>`.
4242

4343
* Documentation that covers something that changed has been updated.
4444

@@ -65,7 +65,7 @@ the users of this project.
6565
Please note that while we would like all PRs to follow the guidelines given
6666
here, we will not reject a PR just because it does not.
6767

68-
.. Tests:
68+
.. _tests:
6969

7070
Tests
7171
-----

docs/rdf_terms.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ All terms in RDFLib are sub-classes of the :class:`rdflib.term.Identifier` class
8181
@enduml
8282

8383
Nodes are a subset of the Terms that underlying stores actually persist.
84+
8485
The set of such Terms depends on whether or not the store is formula-aware.
8586
Stores that aren't formula-aware only persist those terms core to the
8687
RDF Model but those that are formula-aware also persist the N3

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exclude = '''
1919
| htmlcov
2020
| benchmarks
2121
| examples # No need to Black examples
22-
| test # Tests are a mess, don't black them
2322
| test_reports
2423
| rdflib.egg-info
2524
| buck-out

rdflib/exceptions.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
__all__ = [
66
"Error",
7-
"TypeCheckError",
8-
"SubjectTypeError",
9-
"PredicateTypeError",
10-
"ObjectTypeError",
11-
"ContextTypeError",
127
"ParserError",
138
]
149

@@ -21,61 +16,6 @@ def __init__(self, msg=None):
2116
self.msg = msg
2217

2318

24-
class TypeCheckError(Error):
25-
"""Parts of assertions are subject to type checks."""
26-
27-
def __init__(self, node):
28-
Error.__init__(self, node)
29-
self.type = type(node)
30-
self.node = node
31-
32-
33-
class SubjectTypeError(TypeCheckError):
34-
"""Subject of an assertion must be an instance of URIRef."""
35-
36-
def __init__(self, node):
37-
TypeCheckError.__init__(self, node)
38-
self.msg = "Subject must be instance of URIRef or BNode: %s(%s)" % (
39-
self.node,
40-
self.type,
41-
)
42-
43-
44-
class PredicateTypeError(TypeCheckError):
45-
"""Predicate of an assertion must be an instance of URIRef."""
46-
47-
def __init__(self, node):
48-
TypeCheckError.__init__(self, node)
49-
self.msg = "Predicate must be a URIRef instance: %s(%s)" % (
50-
self.node,
51-
self.type,
52-
)
53-
54-
55-
class ObjectTypeError(TypeCheckError):
56-
"""Object of an assertion must be an instance of URIRef, Literal,
57-
or BNode."""
58-
59-
def __init__(self, node):
60-
TypeCheckError.__init__(self, node)
61-
self.msg = (
62-
"\
63-
Object must be instance of URIRef, Literal, or BNode: %s(%s)"
64-
% (self.node, self.type)
65-
)
66-
67-
68-
class ContextTypeError(TypeCheckError):
69-
"""Context of an assertion must be an instance of URIRef."""
70-
71-
def __init__(self, node):
72-
TypeCheckError.__init__(self, node)
73-
self.msg = "Context must be instance of URIRef or BNode: %s(%s)" % (
74-
self.node,
75-
self.type,
76-
)
77-
78-
7919
class ParserError(Error):
8020
"""RDF Parser error."""
8121

rdflib/namespace/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import json
12
import logging
23
import warnings
4+
from pathlib import Path
35
from functools import lru_cache
46
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, Iterable
57
from unicodedata import category
6-
7-
from pathlib import Path
88
from urllib.parse import urldefrag
99
from urllib.parse import urljoin
1010

@@ -246,6 +246,15 @@ def __dir__(cls) -> Iterable[str]:
246246
values = {cls[str(x)] for x in cls.__annotations__}
247247
return values
248248

249+
def as_jsonld_context(self, pfx: str) -> dict:
250+
"""Returns this DefinedNamespace as a a JSON-LD 'context' object"""
251+
terms = {pfx: str(self._NS)}
252+
for key, term in self.__annotations__.items():
253+
if issubclass(term, URIRef):
254+
terms[key] = f'{pfx}:{key}'
255+
256+
return {'@context': terms}
257+
249258

250259
class DefinedNamespace(metaclass=DefinedNamespaceMeta):
251260
"""

rdflib/plugins/sparql/results/tsvresults.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,24 @@ def parse(self, source, content_type=None):
6868
# if reading from source returns bytes do utf-8 decoding
6969
source = codecs.getreader("utf-8")(source)
7070

71-
try:
72-
r = Result("SELECT")
73-
74-
header = source.readline()
75-
76-
r.vars = list(HEADER.parseString(header.strip(), parseAll=True))
77-
r.bindings = []
78-
while True:
79-
line = source.readline()
80-
if not line:
81-
break
82-
line = line.strip("\n")
83-
if line == "":
84-
continue
85-
86-
row = ROW.parseString(line, parseAll=True)
87-
r.bindings.append(dict(zip(r.vars, (self.convertTerm(x) for x in row))))
88-
89-
return r
90-
91-
except ParseException as err:
92-
print(err.line)
93-
print(" " * (err.column - 1) + "^")
94-
print(err)
71+
r = Result("SELECT")
72+
73+
header = source.readline()
74+
75+
r.vars = list(HEADER.parseString(header.strip(), parseAll=True))
76+
r.bindings = []
77+
while True:
78+
line = source.readline()
79+
if not line:
80+
break
81+
line = line.strip("\n")
82+
if line == "":
83+
continue
84+
85+
row = ROW.parseString(line, parseAll=True)
86+
r.bindings.append(dict(zip(r.vars, (self.convertTerm(x) for x in row))))
87+
88+
return r
9589

9690
def convertTerm(self, t):
9791
if t is NONE_VALUE:

0 commit comments

Comments
 (0)