ogc-na 0.3.48__py3-none-any.whl → 0.3.50__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 CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.3.48'
16
- __version_tuple__ = version_tuple = (0, 3, 48)
15
+ __version__ = version = '0.3.50'
16
+ __version_tuple__ = version_tuple = (0, 3, 50)
ogc/na/annotate_schema.py CHANGED
@@ -117,6 +117,7 @@ from __future__ import annotations
117
117
 
118
118
  import argparse
119
119
  import csv
120
+ import copy
120
121
  import dataclasses
121
122
  import json
122
123
  import logging
@@ -147,7 +148,12 @@ ANNOTATION_IGNORE_EXPAND = [ANNOTATION_CONTEXT, ANNOTATION_EXTRA_TERMS, ANNOTATI
147
148
 
148
149
  CURIE_TERMS = '@id', '@type', '@index'
149
150
 
150
- UNDEFINED = object()
151
+ class Undefined:
152
+
153
+ def __bool__(self):
154
+ return False
155
+
156
+ UNDEFINED = Undefined()
151
157
 
152
158
  context_term_cache = LRUCache(maxsize=20)
153
159
  requests_session = requests_cache.CachedSession('ogc.na.annotate_schema', backend='memory', expire_after=180)
@@ -723,24 +729,29 @@ class ContextBuilder:
723
729
  self.visited_properties[full_property_path_str] = prop_context['@id']
724
730
  self._missed_properties[full_property_path_str] = False
725
731
  if prop_context['@id'] == '@nest':
726
- process_subschema(prop_val, from_schema, onto_context, full_property_path)
732
+ merge_contexts(onto_context, process_subschema(prop_val, from_schema, full_property_path))
727
733
  else:
728
- process_subschema(prop_val, from_schema, prop_context['@context'], full_property_path)
734
+ merge_contexts(prop_context['@context'],
735
+ process_subschema(prop_val, from_schema, full_property_path))
729
736
  if prop not in onto_context or isinstance(onto_context[prop], str):
730
737
  onto_context[prop] = prop_context
731
738
  else:
732
739
  merge_contexts(onto_context[prop], prop_context)
733
740
  else:
734
- process_subschema(prop_val, from_schema, onto_context, full_property_path)
741
+ merge_contexts(onto_context, process_subschema(prop_val, from_schema, full_property_path))
735
742
 
736
743
  imported_prefixes: dict[str | Path, dict[str, str]] = {}
737
744
  imported_extra_terms: dict[str | Path, dict[str, str]] = {}
738
745
 
739
- def process_subschema(subschema: dict, from_schema: ReferencedSchema, onto_context: dict,
740
- schema_path: list[str]) -> dict | None:
746
+ cached_schema_contexts = {}
747
+
748
+ def process_subschema(subschema: dict, from_schema: ReferencedSchema,
749
+ schema_path: list[str]) -> dict:
750
+
751
+ onto_context = {}
741
752
 
742
753
  if not isinstance(subschema, dict):
743
- return None
754
+ return {}
744
755
 
745
756
  if subschema.get(ANNOTATION_BASE):
746
757
  onto_context['@base'] = subschema[ANNOTATION_BASE]
@@ -753,24 +764,25 @@ class ContextBuilder:
753
764
  processed_refs.add(ref_path_str)
754
765
  referenced_schema = self.schema_resolver.resolve_schema(ref, from_schema)
755
766
  if referenced_schema:
756
- process_subschema(referenced_schema.subschema, referenced_schema, onto_context,
757
- schema_path)
767
+ ref_ctx = copy.deepcopy(cached_schema_contexts.get(ref_path_str))
768
+ if ref_ctx is None:
769
+ ref_ctx = process_subschema(referenced_schema.subschema, referenced_schema, schema_path)
770
+ merge_contexts(onto_context, ref_ctx)
758
771
 
759
772
  for i in ('allOf', 'anyOf', 'oneOf'):
760
773
  l = subschema.get(i)
761
774
  if isinstance(l, list):
762
775
  for idx, sub_subschema in enumerate(l):
763
- process_subschema(sub_subschema, from_schema, onto_context,
764
- schema_path)
776
+ merge_contexts(onto_context, process_subschema(sub_subschema, from_schema, schema_path))
765
777
 
766
778
  for i in ('prefixItems', 'items', 'contains', 'then', 'else', 'additionalProperties'):
767
779
  l = subschema.get(i)
768
780
  if isinstance(l, dict):
769
- process_subschema(l, from_schema, onto_context, schema_path)
781
+ merge_contexts(onto_context, process_subschema(l, from_schema, schema_path))
770
782
 
771
783
  for pp_k, pp in subschema.get('patternProperties', {}).items():
772
784
  if isinstance(pp, dict):
773
- process_subschema(pp, from_schema, onto_context, schema_path + [pp_k])
785
+ merge_contexts(onto_context, process_subschema(pp, from_schema, schema_path + [pp_k]))
774
786
 
775
787
  if ANNOTATION_EXTRA_TERMS in subschema:
776
788
  for extra_term, extra_term_context in subschema[ANNOTATION_EXTRA_TERMS].items():
@@ -797,7 +809,10 @@ class ContextBuilder:
797
809
  if isinstance(sub_prefixes, dict):
798
810
  prefixes.update({k: v for k, v in sub_prefixes.items() if k not in prefixes})
799
811
 
800
- process_subschema(root_schema.subschema, root_schema, own_context, [])
812
+ cached_schema_contexts[f"{from_schema.location}#{from_schema.fragment}"] = onto_context
813
+ return onto_context
814
+
815
+ merge_contexts(own_context, process_subschema(root_schema.subschema, root_schema, []))
801
816
 
802
817
  for imported_et in imported_extra_terms.values():
803
818
  for term, v in imported_et.items():
@@ -844,10 +859,13 @@ class ContextBuilder:
844
859
  if isinstance(term_value, dict) and '@context' in term_value:
845
860
  if not term_value['@context']:
846
861
  del term_value['@context']
862
+ changed = True
847
863
  else:
848
864
  while True:
849
865
  if not compact_branch(term_value['@context'], child_context_stack):
850
866
  break
867
+ else:
868
+ changed = True
851
869
 
852
870
  if context_stack:
853
871
  for ctx in context_stack:
@@ -881,7 +899,9 @@ class ContextBuilder:
881
899
  elif '@context' in term_value:
882
900
  compact_uris(term_value['@context'], child_context_stack)
883
901
 
884
- compact_branch(own_context)
902
+ while True:
903
+ if not compact_branch(own_context):
904
+ break
885
905
  compact_uris(own_context)
886
906
 
887
907
  self._parsed_schemas[schema_location] = own_context
ogc/na/util.py CHANGED
@@ -310,6 +310,9 @@ def git_status(repo_path: str | Path = '.'):
310
310
 
311
311
 
312
312
  def merge_contexts(a: dict, b: dict, fix_nest=True) -> dict[str, Any]:
313
+ '''
314
+ Merges two JSON-lD contexts, updating the first one passed to this function (and returning it).
315
+ '''
313
316
  if not b:
314
317
  return a
315
318
  if not a:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ogc_na
3
- Version: 0.3.48
3
+ Version: 0.3.50
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/
@@ -1,6 +1,6 @@
1
1
  ogc/na/__init__.py,sha256=uzcNiJ3uKFNJ1HBfKxIwgAy2HMUFsLAe5RkrUg8ncac,464
2
- ogc/na/_version.py,sha256=mfmW0CWu7aCrV9FPOEgTkXIABLrGuD0h2hvBHzOBkxQ,413
3
- ogc/na/annotate_schema.py,sha256=1pXQM0RYFxyplJpDpMLqvy-XS0RcOkHdP63injGVMbU,40554
2
+ ogc/na/_version.py,sha256=Q_8itBEQeZ4Dn-RIGV0jcZENPIzgmwUxTcLo6vNpPcc,413
3
+ ogc/na/annotate_schema.py,sha256=PFBC1wzo-jiWllKhdSSfU6MS6LyaZmt0pxpAu87_FgQ,41254
4
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
@@ -9,12 +9,12 @@ ogc/na/models.py,sha256=nGV8EALtXvmBtkUbu0FA4KOgwNUqQGWIDuMo7UGOKP8,652
9
9
  ogc/na/profile.py,sha256=T7nesbm7azF2ijF60UenJnQQKjIgJlnJ3pUbGT5nYgM,16511
10
10
  ogc/na/provenance.py,sha256=h7UtUb1wW_9MfEim0fjcqkHd0BYmpXqyE1ADzL9AH7I,5551
11
11
  ogc/na/update_vocabs.py,sha256=joLZxhpBJja5GvaBnt0aHQStKETOCIh5PotUxmJsOHs,18180
12
- ogc/na/util.py,sha256=r-cwqxqVVH1oXWsWuobTvXFGUVCqwlalN97b85nUN4U,11951
12
+ ogc/na/util.py,sha256=Ztju3g1YuguUDbk4n2RJfCrl_IIzNAj7linfy24T6VA,12067
13
13
  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.48.dist-info/METADATA,sha256=UM3HLPc-ItKV-fo-_DfxLMZZ2e5zfOtePf3PFJjrhBE,3829
18
- ogc_na-0.3.48.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
19
- ogc_na-0.3.48.dist-info/top_level.txt,sha256=Kvy3KhzcIhNPT4_nZuJCmS946ptRr_MDyU4IIhZJhCY,4
20
- ogc_na-0.3.48.dist-info/RECORD,,
17
+ ogc_na-0.3.50.dist-info/METADATA,sha256=48l6MgeDMdvsVxOed4gBRnBLpknpt6FK4kzQWx-KMuo,3829
18
+ ogc_na-0.3.50.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
19
+ ogc_na-0.3.50.dist-info/top_level.txt,sha256=Kvy3KhzcIhNPT4_nZuJCmS946ptRr_MDyU4IIhZJhCY,4
20
+ ogc_na-0.3.50.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (71.1.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5