From 36471ece4e2861f03edc7a0515dc6081530cbf9d Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Sun, 21 Nov 2021 21:53:54 +1000 Subject: [PATCH 1/6] dd Py 3.10 to testing environments --- .drone.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.drone.yml b/.drone.yml index 4abdb59c0..cb40060ae 100644 --- a/.drone.yml +++ b/.drone.yml @@ -72,3 +72,24 @@ steps: - black --config black.toml --check ./rdflib | true - flake8 --exit-zero rdflib - PYTHONWARNINGS=default nosetests --with-timer --timer-top-n 42 + + +--- +kind: pipeline +name: python-3-10 +type: docker +platform: + os: linux + arch: amd64 + +steps: +- name: test + image: python:3.10 + commands: + - bash .travis.fuseki_install_optional.sh + - pip install --default-timeout 60 -r requirements.txt + - pip install --default-timeout 60 -r requirements.dev.txt + - python setup.py install + - black --config black.toml --check ./rdflib | true + - flake8 --exit-zero rdflib + - PYTHONWARNINGS=default nosetests --with-timer --timer-top-n 42 From 07f696f1b855ae5b974330618c886fe58372ada4 Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Tue, 7 Dec 2021 19:38:29 +1000 Subject: [PATCH 2/6] Update .drone.yml --- .drone.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index baa12139f..4ed89b606 100644 --- a/.drone.yml +++ b/.drone.yml @@ -84,7 +84,6 @@ steps: - name: test image: python:3.10 commands: - - bash .travis.fuseki_install_optional.sh - pip install --default-timeout 60 -r requirements.txt - pip install --default-timeout 60 -r requirements.dev.txt - python setup.py install From 74302bcf993777c7f7ae494aaf4953c05724d4f3 Mon Sep 17 00:00:00 2001 From: nicholascar Date: Sat, 11 Dec 2021 13:02:02 +1000 Subject: [PATCH 3/6] more Flak8 improvements --- rdflib/plugins/parsers/notation3.py | 11 +---------- rdflib/plugins/shared/jsonld/context.py | 6 +++++- rdflib/plugins/shared/jsonld/errors.py | 1 + 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py index 31b20036a..b277a283f 100755 --- a/rdflib/plugins/parsers/notation3.py +++ b/rdflib/plugins/parsers/notation3.py @@ -27,13 +27,10 @@ Copyright 2010, Gunnar A. Grimnes """ - -# Python standard libraries import sys import os import re import codecs -import warnings from decimal import Decimal @@ -1902,7 +1899,7 @@ def parse(self, source, graph, encoding="utf-8", turtle=True): if encoding not in [None, "utf-8"]: raise ParserError( - ("N3/Turtle files are always utf-8 encoded, I was passed: %s") + "N3/Turtle files are always utf-8 encoded, I was passed: %s" % encoding ) @@ -1957,10 +1954,6 @@ def _test(): # pragma: no cover doctest.testmod() -# if __name__ == '__main__': -# _test() - - def main(): # pragma: no cover g = ConjunctiveGraph() @@ -1984,5 +1977,3 @@ def main(): # pragma: no cover if __name__ == "__main__": main() - -# ends diff --git a/rdflib/plugins/shared/jsonld/context.py b/rdflib/plugins/shared/jsonld/context.py index 30bb02eab..c91107b48 100644 --- a/rdflib/plugins/shared/jsonld/context.py +++ b/rdflib/plugins/shared/jsonld/context.py @@ -34,7 +34,11 @@ VERSION, VOCAB, ) -from .errors import INVALID_REMOTE_CONTEXT, RECURSIVE_CONTEXT_INCLUSION +from .errors import ( + INVALID_REMOTE_CONTEXT, + RECURSIVE_CONTEXT_INCLUSION, + INVALID_CONTEXT_ENTRY +) from .util import source_to_json, urljoin, urlsplit, split_iri, norm_url diff --git a/rdflib/plugins/shared/jsonld/errors.py b/rdflib/plugins/shared/jsonld/errors.py index 977d2d6fc..f1973f14a 100644 --- a/rdflib/plugins/shared/jsonld/errors.py +++ b/rdflib/plugins/shared/jsonld/errors.py @@ -7,3 +7,4 @@ class JSONLDException(ValueError): # http://www.w3.org/TR/json-ld-api/#idl-def-JsonLdErrorCode.{code-message} RECURSIVE_CONTEXT_INCLUSION = JSONLDException("recursive context inclusion") INVALID_REMOTE_CONTEXT = JSONLDException("invalid remote context") +INVALID_CONTEXT_ENTRY = JSONLDException("invalid context entry") From 28288b07074125d87be849d23a53c19605d78b5b Mon Sep 17 00:00:00 2001 From: nicholascar Date: Thu, 16 Dec 2021 09:19:46 +1000 Subject: [PATCH 4/6] style fixes only --- rdflib/namespace/_SDO.py | 6 ++--- rdflib/namespace/__init__.py | 2 +- rdflib/plugins/parsers/notation3.py | 3 +-- rdflib/plugins/serializers/xmlwriter.py | 4 +-- rdflib/plugins/shared/jsonld/context.py | 2 +- rdflib/plugins/shared/jsonld/util.py | 1 + rdflib/tools/defined_namespace_creator.py | 30 +++++++++++------------ rdflib/tools/rdfs2dot.py | 22 ++++++++--------- 8 files changed, 34 insertions(+), 36 deletions(-) diff --git a/rdflib/namespace/_SDO.py b/rdflib/namespace/_SDO.py index a572cad96..9745c5180 100644 --- a/rdflib/namespace/_SDO.py +++ b/rdflib/namespace/_SDO.py @@ -625,7 +625,7 @@ class SDO(DefinedNamespace): MayTreatHealthAspect: URIRef # Related topics may be treated by a Topic. MeasurementTypeEnumeration: URIRef # Enumeration of common measurement types (or dimensions), for example "chest" for a person, "inseam" for pants, "gauge" for screws, or "wheel" for bicycles. MediaGallery: URIRef # Web page type: Media gallery page. A mixed-media page that can contains media such as images, videos, and other multimedia. - MediaManipulationRatingEnumeration: URIRef # Codes for use with the [[mediaAuthenticityCategory]] property, indicating the authenticity of a media object (in the context of how it was published or shared). In general these codes are not mutually exclusive, although some combinations (such as 'original' versus 'transformed', 'edited' and 'staged') would be contradictory if applied in the same [[MediaReview]]. Note that the application of these codes is with regard to a piece of media shared or published in a particular context. + MediaManipulationRatingEnumeration: URIRef # Codes for use with the [[mediaAuthenticityCategory]] property, indicating the authenticity of a media object (in the context of how it was published or shared). In general these codes are not mutually exclusive, although some combinations (such as 'original' versus 'transformed', 'edited' and 'staged') would be contradictory if applied in the same [[MediaReview]]. Note that the application of these codes is with regard to a piece of media shared or published in a particular context. MediaObject: URIRef # A media object, such as an image, video, or audio object embedded in a web page or a downloadable dataset i.e. DataDownload. Note that a creative work may have many media objects associated with it on the same web page. For example, a page about a single song (MusicRecording) may have a music video (VideoObject), and a high and low bandwidth audio stream (2 AudioObject's). MediaReview: URIRef # A [[MediaReview]] is a more specialized form of Review dedicated to the evaluation of media content online, typically in the context of fact-checking and misinformation. For more general reviews of media in the broader sense, use [[UserReview]], [[CriticReview]] or other [[Review]] types. This definition is a work in progress. While the [[MediaManipulationRatingEnumeration]] list reflects significant community review amongst fact-checkers and others working to combat misinformation, the specific structures for representing media objects, their versions and publication context, is still evolving. Similarly, best practices for the relationship between [[MediaReview]] and [[ClaimReview]] markup has not yet been finalized. MediaReviewItem: URIRef # Represents an item or group of closely related items treated as a unit for the sake of evaluation in a [[MediaReview]]. Authorship etc. apply to the items rather than to the curation/grouping or reviewing party. @@ -965,7 +965,7 @@ class SDO(DefinedNamespace): Pulmonary: URIRef # A specific branch of medical science that pertains to the study of the respiratory system and its respective disease states. QAPage: URIRef # A QAPage is a WebPage focussed on a specific Question and its Answer(s), e.g. in a question answering site or documenting Frequently Asked Questions (FAQs). QualitativeValue: URIRef # A predefined value for a product characteristic, e.g. the power cord plug type 'US' or the garment sizes 'S', 'M', 'L', and 'XL'. - QuantitativeValue: URIRef # A point value or interval for product characteristics and other purposes. + QuantitativeValue: URIRef # A point value or interval for product characteristics and other purposes. QuantitativeValueDistribution: URIRef # A statistical distribution of values. Quantity: URIRef # Quantities such as distance, time, mass, weight, etc. Particular instances of say Mass are entities like '3 Kg' or '4 milligrams'. Question: URIRef # A specific question - e.g. from a user seeking answers online, or collected in a Frequently Asked Questions (FAQ) document. @@ -2247,7 +2247,7 @@ class SDO(DefinedNamespace): observationDate: URIRef # The observationDate of an [[Observation]]. observedNode: URIRef # The observedNode of an [[Observation]], often a [[StatisticalPopulation]]. occupancy: URIRef # The allowed total occupancy for the accommodation in persons (including infants etc). For individual accommodations, this is not necessarily the legal maximum but defines the permitted usage as per the contractual agreement (e.g. a double room used by a single person). Typical unit code(s): C62 for person - occupationLocation: URIRef # The region/country for which this occupational description is appropriate. Note that educational requirements and qualifications can vary between jurisdictions. + occupationLocation: URIRef # The region/country for which this occupational description is appropriate. Note that educational requirements and qualifications can vary between jurisdictions. occupationalCategory: URIRef # A category describing the job, preferably using a term from a taxonomy such as [BLS O*NET-SOC](http://www.onetcenter.org/taxonomy.html), [ISCO-08](https://www.ilo.org/public/english/bureau/stat/isco/isco08/) or similar, with the property repeated for each applicable value. Ideally the taxonomy should be identified, and both the textual label and formal code for the category should be provided.\n Note: for historical reasons, any textual label and formal code provided as a literal may be assumed to be from O*NET-SOC. occupationalCredentialAwarded: URIRef # A description of the qualification, award, certificate, diploma or other occupational credential awarded as a consequence of successful completion of this course or program. offerCount: URIRef # The number of offers for the product. diff --git a/rdflib/namespace/__init__.py b/rdflib/namespace/__init__.py index 8ce4de79b..e1f0b52b0 100644 --- a/rdflib/namespace/__init__.py +++ b/rdflib/namespace/__init__.py @@ -445,7 +445,7 @@ def compute_qname(self, uri, generate=True): pl_namespace = get_longest_namespace(self.__strie[namespace], uri) if pl_namespace is not None: namespace = pl_namespace - name = uri[len(namespace):] + name = uri[len(namespace) :] namespace = URIRef(namespace) prefix = self.store.prefix(namespace) # warning multiple prefixes problem diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py index b277a283f..2bd856887 100755 --- a/rdflib/plugins/parsers/notation3.py +++ b/rdflib/plugins/parsers/notation3.py @@ -1899,8 +1899,7 @@ def parse(self, source, graph, encoding="utf-8", turtle=True): if encoding not in [None, "utf-8"]: raise ParserError( - "N3/Turtle files are always utf-8 encoded, I was passed: %s" - % encoding + "N3/Turtle files are always utf-8 encoded, I was passed: %s" % encoding ) sink = RDFSink(graph) diff --git a/rdflib/plugins/serializers/xmlwriter.py b/rdflib/plugins/serializers/xmlwriter.py index 99d1e7677..b0f1a06e9 100644 --- a/rdflib/plugins/serializers/xmlwriter.py +++ b/rdflib/plugins/serializers/xmlwriter.py @@ -100,8 +100,8 @@ def qname(self, uri): for pre, ns in self.extra_ns.items(): if uri.startswith(ns): if pre != "": - return ":".join(pre, uri[len(ns):]) + return ":".join(pre, uri[len(ns) :]) else: - return uri[len(ns):] + return uri[len(ns) :] return self.nm.qname_strict(uri) diff --git a/rdflib/plugins/shared/jsonld/context.py b/rdflib/plugins/shared/jsonld/context.py index c91107b48..2bf38f44a 100644 --- a/rdflib/plugins/shared/jsonld/context.py +++ b/rdflib/plugins/shared/jsonld/context.py @@ -37,7 +37,7 @@ from .errors import ( INVALID_REMOTE_CONTEXT, RECURSIVE_CONTEXT_INCLUSION, - INVALID_CONTEXT_ENTRY + INVALID_CONTEXT_ENTRY, ) from .util import source_to_json, urljoin, urlsplit, split_iri, norm_url diff --git a/rdflib/plugins/shared/jsonld/util.py b/rdflib/plugins/shared/jsonld/util.py index 8a0cfa74f..e703c14c9 100644 --- a/rdflib/plugins/shared/jsonld/util.py +++ b/rdflib/plugins/shared/jsonld/util.py @@ -44,6 +44,7 @@ def source_to_json(source): finally: stream.close() + VOCAB_DELIMS = ("#", "/", ":") diff --git a/rdflib/tools/defined_namespace_creator.py b/rdflib/tools/defined_namespace_creator.py index 82803f9d7..f3eeaecf3 100644 --- a/rdflib/tools/defined_namespace_creator.py +++ b/rdflib/tools/defined_namespace_creator.py @@ -82,7 +82,9 @@ def get_target_namespace_elements(g, target_namespace): # only get results for the target namespace (supplied by user) FILTER STRSTARTS(STR(?s), "xxx") } - """.replace("xxx", target_namespace) + """.replace( + "xxx", target_namespace + ) elements = [] for r in g.query(q, initNs=namespaces): elements.append((str(r[0]), str(r[1]))) @@ -92,7 +94,9 @@ def get_target_namespace_elements(g, target_namespace): elements_strs = [] for e in elements: desc = e[1].replace('\n', ' ') - elements_strs.append(f" {e[0].replace(args.target_namespace, '')}: URIRef # {desc}\n") + elements_strs.append( + f" {e[0].replace(args.target_namespace, '')}: URIRef # {desc}\n" + ) return elements, elements_strs @@ -134,7 +138,7 @@ class {object_id}(DefinedNamespace): "target_namespace", type=str, help="The namespace within the ontology that you want to create a " - "DefinedNamespace for.", + "DefinedNamespace for.", ) parser.add_argument( @@ -144,11 +148,12 @@ class {object_id}(DefinedNamespace): ) parser.add_argument( - '-f', "--fail", + '-f', + "--fail", dest='fail', action='store_true', help="Whether (true) or not (false) to mimic ClosedNamespace and fail on " - "non-element use" + "non-element use", ) parser.add_argument('--no-fail', dest='fail', action='store_false') parser.set_defaults(feature=False) @@ -165,8 +170,10 @@ class {object_id}(DefinedNamespace): validate_object_id(args.object_id) - print(f"Creating DefinedNamespace file {args.object_id} " - f"for {args.target_namespace}...") + print( + f"Creating DefinedNamespace file {args.object_id} " + f"for {args.target_namespace}..." + ) print(f"Ontology with {len(g)} triples loaded...") print("Getting all namespace elements...") @@ -175,12 +182,5 @@ class {object_id}(DefinedNamespace): output_file_name = Path().cwd() / f"_{args.object_id}.py" print(f"Creating DefinedNamespace Python file {output_file_name}") make_dn_file( - output_file_name, - args.target_namespace, - elements[1], - args.object_id, - args.fail + output_file_name, args.target_namespace, elements[1], args.object_id, args.fail ) - - - diff --git a/rdflib/tools/rdfs2dot.py b/rdflib/tools/rdfs2dot.py index cb8d0bfd9..a9eeb2442 100644 --- a/rdflib/tools/rdfs2dot.py +++ b/rdflib/tools/rdfs2dot.py @@ -80,21 +80,19 @@ def rdfs2dot(g, stream, opts={}): fields = collections.defaultdict(set) nodes = {} - def node(x): - - if x not in nodes: - nodes[x] = "node%d" % len(nodes) - return nodes[x] - - def label(x, g): - - l_ = g.value(x, RDFS.label) - if l_ is None: + def node(nd): + if nd not in nodes: + nodes[nd] = "node%d" % len(nodes) + return nodes[nd] + + def label(xx, grf): + lbl = g.value(xx, RDFS.label) + if lbl is None: try: - l_ = g.namespace_manager.compute_qname(x)[2] + lbl = grf.namespace_manager.compute_qname(xx)[2] except: pass # bnodes and some weird URIs cannot be split - return l_ + return lbl stream.write('digraph { \n node [ fontname="DejaVu Sans" ] ; \n') From cde35b3c2502163c8b73776128fb4e8aaa699f66 Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Fri, 17 Dec 2021 10:27:23 +1000 Subject: [PATCH 5/6] Update rdflib/tools/rdfs2dot.py Co-authored-by: Iwan Aucamp --- rdflib/tools/rdfs2dot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdflib/tools/rdfs2dot.py b/rdflib/tools/rdfs2dot.py index a9eeb2442..97a4b9750 100644 --- a/rdflib/tools/rdfs2dot.py +++ b/rdflib/tools/rdfs2dot.py @@ -86,7 +86,7 @@ def node(nd): return nodes[nd] def label(xx, grf): - lbl = g.value(xx, RDFS.label) + lbl = grf.value(xx, RDFS.label) if lbl is None: try: lbl = grf.namespace_manager.compute_qname(xx)[2] From 5750a725a2c777f2ca54aaad5378ca5888372e65 Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Fri, 17 Dec 2021 10:27:34 +1000 Subject: [PATCH 6/6] Update .drone.yml Co-authored-by: Iwan Aucamp --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index 4ed89b606..7a46aea6a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -84,6 +84,7 @@ steps: - name: test image: python:3.10 commands: + - apt-get update && apt-get install -y openjdk-11-jdk-headless - pip install --default-timeout 60 -r requirements.txt - pip install --default-timeout 60 -r requirements.dev.txt - python setup.py install