ogc-na 0.3.45__py3-none-any.whl → 0.3.47__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ogc-na might be problematic. Click here for more details.
- ogc/na/_version.py +2 -2
- ogc/na/annotate_schema.py +34 -25
- ogc/na/domain_config.py +2 -2
- {ogc_na-0.3.45.dist-info → ogc_na-0.3.47.dist-info}/METADATA +2 -1
- {ogc_na-0.3.45.dist-info → ogc_na-0.3.47.dist-info}/RECORD +7 -7
- {ogc_na-0.3.45.dist-info → ogc_na-0.3.47.dist-info}/WHEEL +1 -1
- {ogc_na-0.3.45.dist-info → ogc_na-0.3.47.dist-info}/top_level.txt +0 -0
ogc/na/_version.py
CHANGED
ogc/na/annotate_schema.py
CHANGED
|
@@ -127,6 +127,7 @@ from pathlib import Path
|
|
|
127
127
|
from typing import Any, AnyStr, Callable, Sequence, Iterable
|
|
128
128
|
from urllib.parse import urlparse, urljoin
|
|
129
129
|
|
|
130
|
+
import jsonpointer
|
|
130
131
|
import jsonschema
|
|
131
132
|
import requests_cache
|
|
132
133
|
|
|
@@ -180,26 +181,21 @@ class SchemaResolver:
|
|
|
180
181
|
|
|
181
182
|
def __init__(self, working_directory=Path()):
|
|
182
183
|
self.working_directory = working_directory.resolve()
|
|
183
|
-
self._schema_cache: dict[str | Path,
|
|
184
|
+
self._schema_cache: dict[str | Path, Any] = {}
|
|
184
185
|
|
|
185
186
|
@staticmethod
|
|
186
187
|
def _get_branch(schema: dict, ref: str):
|
|
187
|
-
|
|
188
|
-
pointer = schema
|
|
189
|
-
for item in path:
|
|
190
|
-
if item:
|
|
191
|
-
pointer = pointer[item]
|
|
192
|
-
return pointer
|
|
188
|
+
return jsonpointer.resolve_pointer(schema, re.sub('^#', '', ref))
|
|
193
189
|
|
|
194
190
|
def load_contents(self, s: str | Path) -> tuple[dict, bool]:
|
|
195
191
|
"""
|
|
196
192
|
Load the contents of a schema. Can be overriden by subclasses to alter the loading process.
|
|
197
193
|
"""
|
|
198
|
-
contents
|
|
194
|
+
contents = self._schema_cache.get(s)
|
|
199
195
|
if contents is None:
|
|
200
|
-
contents
|
|
201
|
-
self._schema_cache[s] = contents
|
|
202
|
-
return contents
|
|
196
|
+
contents = read_contents(s)[0]
|
|
197
|
+
self._schema_cache[s] = contents
|
|
198
|
+
return load_json_yaml(contents)
|
|
203
199
|
|
|
204
200
|
def resolve_ref(self, ref: str | Path, from_schema: ReferencedSchema | None = None) -> tuple[Path | str, str]:
|
|
205
201
|
location = ref
|
|
@@ -230,7 +226,8 @@ class SchemaResolver:
|
|
|
230
226
|
|
|
231
227
|
return location, fragment
|
|
232
228
|
|
|
233
|
-
def resolve_schema(self, ref: str | Path, from_schema: ReferencedSchema | None = None
|
|
229
|
+
def resolve_schema(self, ref: str | Path, from_schema: ReferencedSchema | None = None,
|
|
230
|
+
force_contents: dict | None = None) -> ReferencedSchema | None:
|
|
234
231
|
chain = from_schema.chain + [from_schema] if from_schema else []
|
|
235
232
|
try:
|
|
236
233
|
schema_source, fragment = self.resolve_ref(ref, from_schema)
|
|
@@ -251,6 +248,8 @@ class SchemaResolver:
|
|
|
251
248
|
is_json=from_schema.is_json)
|
|
252
249
|
|
|
253
250
|
contents, is_json = self.load_contents(schema_source)
|
|
251
|
+
if force_contents:
|
|
252
|
+
contents = force_contents
|
|
254
253
|
if fragment:
|
|
255
254
|
return ReferencedSchema(location=schema_source, fragment=fragment,
|
|
256
255
|
subschema=SchemaResolver._get_branch(contents, fragment),
|
|
@@ -457,12 +456,8 @@ class SchemaAnnotator:
|
|
|
457
456
|
def process_schema(self, location: Path | str | None,
|
|
458
457
|
default_context: str | Path | dict | None = None,
|
|
459
458
|
contents: dict | None = None) -> AnnotatedSchema | None:
|
|
460
|
-
resolved_schema = self.schema_resolver.resolve_schema(location)
|
|
461
|
-
|
|
462
|
-
# overriden
|
|
463
|
-
schema = contents
|
|
464
|
-
else:
|
|
465
|
-
schema = resolved_schema.subschema
|
|
459
|
+
resolved_schema = self.schema_resolver.resolve_schema(location, force_contents=contents)
|
|
460
|
+
schema = resolved_schema.subschema
|
|
466
461
|
|
|
467
462
|
if all(x not in schema for x in ('schema', 'openapi')):
|
|
468
463
|
validate_schema(schema)
|
|
@@ -568,6 +563,13 @@ class SchemaAnnotator:
|
|
|
568
563
|
|
|
569
564
|
used_terms = set()
|
|
570
565
|
|
|
566
|
+
# Annotate definitions and $defs - can later be overridden if referenced from a different path
|
|
567
|
+
for p in ('definitions', '$defs'):
|
|
568
|
+
defs = subschema.get(p)
|
|
569
|
+
if defs and isinstance(defs, dict):
|
|
570
|
+
for entry in defs.values():
|
|
571
|
+
used_terms.update(process_subschema(entry, context_stack, from_schema, level + 1))
|
|
572
|
+
|
|
571
573
|
if '$ref' in subschema and id(subschema) not in updated_refs:
|
|
572
574
|
if self._ref_mapper:
|
|
573
575
|
subschema['$ref'] = self._ref_mapper(subschema['$ref'], subschema)
|
|
@@ -585,13 +587,6 @@ class SchemaAnnotator:
|
|
|
585
587
|
for entry in collection:
|
|
586
588
|
used_terms.update(process_subschema(entry, context_stack, from_schema, level + 1))
|
|
587
589
|
|
|
588
|
-
# Annotate definitions and $defs
|
|
589
|
-
for p in ('definitions', '$defs'):
|
|
590
|
-
defs = subschema.get(p)
|
|
591
|
-
if defs and isinstance(defs, dict):
|
|
592
|
-
for entry in defs.values():
|
|
593
|
-
used_terms.update(process_subschema(entry, context_stack, from_schema, level + 1))
|
|
594
|
-
|
|
595
590
|
for p in ('then', 'else', 'additionalProperties'):
|
|
596
591
|
branch = subschema.get(p)
|
|
597
592
|
if branch and isinstance(branch, dict):
|
|
@@ -693,6 +688,9 @@ class ContextBuilder:
|
|
|
693
688
|
if prefixes:
|
|
694
689
|
own_context.update(prefixes)
|
|
695
690
|
|
|
691
|
+
# store processed $defs and definitions to avoid parsing them twice
|
|
692
|
+
processed_refs = set()
|
|
693
|
+
|
|
696
694
|
def read_properties(subschema: dict, from_schema: ReferencedSchema,
|
|
697
695
|
onto_context: dict, schema_path: list[str]) -> dict | None:
|
|
698
696
|
if schema_path:
|
|
@@ -751,6 +749,8 @@ class ContextBuilder:
|
|
|
751
749
|
|
|
752
750
|
if '$ref' in subschema:
|
|
753
751
|
ref = subschema['$ref']
|
|
752
|
+
ref_path_str = f"{from_schema.location}{ref}"
|
|
753
|
+
processed_refs.add(ref_path_str)
|
|
754
754
|
referenced_schema = self.schema_resolver.resolve_schema(ref, from_schema)
|
|
755
755
|
if referenced_schema:
|
|
756
756
|
process_subschema(referenced_schema.subschema, referenced_schema, onto_context,
|
|
@@ -772,6 +772,15 @@ class ContextBuilder:
|
|
|
772
772
|
if isinstance(pp, dict):
|
|
773
773
|
process_subschema(pp, from_schema, onto_context, schema_path + [pp_k])
|
|
774
774
|
|
|
775
|
+
for p in ('definitions', '$defs'):
|
|
776
|
+
defs = subschema.get(p)
|
|
777
|
+
if defs and isinstance(defs, dict):
|
|
778
|
+
for entry_key, entry in defs.items():
|
|
779
|
+
def_path = schema_path + [entry_key]
|
|
780
|
+
def_path_str = f"{from_schema.location}#{'/'.join(def_path)}"
|
|
781
|
+
if def_path_str not in processed_refs:
|
|
782
|
+
process_subschema(entry, from_schema, onto_context, def_path)
|
|
783
|
+
|
|
775
784
|
if ANNOTATION_EXTRA_TERMS in subschema:
|
|
776
785
|
for extra_term, extra_term_context in subschema[ANNOTATION_EXTRA_TERMS].items():
|
|
777
786
|
if extra_term not in onto_context:
|
ogc/na/domain_config.py
CHANGED
|
@@ -11,7 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
from typing import Union, Optional, Sequence, cast, IO, TypeVar, Iterable
|
|
12
12
|
|
|
13
13
|
import wcmatch.glob
|
|
14
|
-
from rdflib import Graph, Namespace, URIRef, DCTERMS, DCAT, Literal
|
|
14
|
+
from rdflib import Graph, Namespace, URIRef, DCTERMS, DCAT, Literal, RDF
|
|
15
15
|
from wcmatch.glob import globmatch
|
|
16
16
|
|
|
17
17
|
from ogc.na.profile import ProfileRegistry
|
|
@@ -214,7 +214,7 @@ class DomainConfiguration:
|
|
|
214
214
|
|
|
215
215
|
identifier = cfg_graph.value(cfg_ref, DCTERMS.identifier) or str(cfg_ref)
|
|
216
216
|
|
|
217
|
-
if
|
|
217
|
+
if (cfg_ref, RDF.type, DCFG.DomainConfiguration) in cfg_graph:
|
|
218
218
|
self.entries.append(DomainConfigurationEntry(
|
|
219
219
|
working_directory=self.working_directory,
|
|
220
220
|
glob=globs,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ogc_na
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.47
|
|
4
4
|
Summary: OGC Naming Authority tools
|
|
5
5
|
Author-email: Rob Atkinson <ratkinson@ogc.org>, Piotr Zaborowski <pzaborowski@ogc.org>, Alejandro Villar <avillar@ogc.org>
|
|
6
6
|
Project-URL: Homepage, https://github.com/opengeospatial/ogc-na-tools/
|
|
@@ -26,6 +26,7 @@ Requires-Dist: GitPython >=3.1.32
|
|
|
26
26
|
Requires-Dist: rfc3987
|
|
27
27
|
Requires-Dist: requests-cache
|
|
28
28
|
Requires-Dist: xmltodict
|
|
29
|
+
Requires-Dist: jsonpointer ~=2.4
|
|
29
30
|
Requires-Dist: setuptools
|
|
30
31
|
Provides-Extra: dev
|
|
31
32
|
Requires-Dist: mkdocs >=1.4.2 ; extra == 'dev'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
ogc/na/__init__.py,sha256=uzcNiJ3uKFNJ1HBfKxIwgAy2HMUFsLAe5RkrUg8ncac,464
|
|
2
|
-
ogc/na/_version.py,sha256=
|
|
3
|
-
ogc/na/annotate_schema.py,sha256=
|
|
4
|
-
ogc/na/domain_config.py,sha256=
|
|
2
|
+
ogc/na/_version.py,sha256=MU1To0oLGMljUY5xtLtnFwxvNZIg8MhRIqWxqn6vDSQ,413
|
|
3
|
+
ogc/na/annotate_schema.py,sha256=1W0gS190-s1f9cnmjzPakM82YB15aBYCHl1mmy2SehM,41052
|
|
4
|
+
ogc/na/domain_config.py,sha256=ORzITa1rTrD1MQdpWYrIVW5SwSa9lJd3hnyHIxNgiIU,13947
|
|
5
5
|
ogc/na/download.py,sha256=2afrLyl4WsAlxkCgXsl47fs9mNKfDmhVpeT2iwNSoq0,3354
|
|
6
6
|
ogc/na/gsp.py,sha256=KGa2G9i8kPefYTHNPUDoXnNyF7Tiwt8K__Ew_Qa7eeg,6048
|
|
7
7
|
ogc/na/ingest_json.py,sha256=V_hZmU8veM6YqARjh8jy50dyhVCcjLLpjdXH6duTL_Y,35503
|
|
@@ -14,7 +14,7 @@ ogc/na/validation.py,sha256=5xjHH55NZKM8HtUk8XgVzm8W5ZlZY00u_qsWfXK_8dM,3732
|
|
|
14
14
|
ogc/na/input_filters/__init__.py,sha256=AhE7n_yECwxFKwOM3Jc0ft96TtF5i_Z-fHrS4HYOjaE,1179
|
|
15
15
|
ogc/na/input_filters/csv.py,sha256=nFfB1XQF_QApcGGzMqEvzD_b3pBtCtsfUECsZ9UGE6s,2616
|
|
16
16
|
ogc/na/input_filters/xml.py,sha256=9qYjp_w5JLInFM48zB15IYH9eTafjp1Aqd_8kfuW3aA,2074
|
|
17
|
-
ogc_na-0.3.
|
|
18
|
-
ogc_na-0.3.
|
|
19
|
-
ogc_na-0.3.
|
|
20
|
-
ogc_na-0.3.
|
|
17
|
+
ogc_na-0.3.47.dist-info/METADATA,sha256=t22dnhWzSyECXYG8MiMqXAiTv3Hk-TYJGxV6mNN9MUY,3829
|
|
18
|
+
ogc_na-0.3.47.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
|
|
19
|
+
ogc_na-0.3.47.dist-info/top_level.txt,sha256=Kvy3KhzcIhNPT4_nZuJCmS946ptRr_MDyU4IIhZJhCY,4
|
|
20
|
+
ogc_na-0.3.47.dist-info/RECORD,,
|
|
File without changes
|