ogc-na 0.3.49__tar.gz → 0.3.51__tar.gz

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.

Files changed (54) hide show
  1. {ogc_na-0.3.49 → ogc_na-0.3.51}/PKG-INFO +1 -1
  2. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/_version.py +2 -2
  3. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/annotate_schema.py +29 -10
  4. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/ingest_json.py +3 -1
  5. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc_na.egg-info/PKG-INFO +1 -1
  6. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/test_annotate_schema.py +20 -1
  7. {ogc_na-0.3.49 → ogc_na-0.3.51}/.github/workflows/mkdocs.yml +0 -0
  8. {ogc_na-0.3.49 → ogc_na-0.3.51}/.github/workflows/python-publish.yml +0 -0
  9. {ogc_na-0.3.49 → ogc_na-0.3.51}/.gitignore +0 -0
  10. {ogc_na-0.3.49 → ogc_na-0.3.51}/MANIFEST.in +0 -0
  11. {ogc_na-0.3.49 → ogc_na-0.3.51}/README.md +0 -0
  12. {ogc_na-0.3.49 → ogc_na-0.3.51}/docs/examples.md +0 -0
  13. {ogc_na-0.3.49 → ogc_na-0.3.51}/docs/gen_ref_pages.py +0 -0
  14. {ogc_na-0.3.49 → ogc_na-0.3.51}/docs/index.md +0 -0
  15. {ogc_na-0.3.49 → ogc_na-0.3.51}/docs/jsonld-uplift.md +0 -0
  16. {ogc_na-0.3.49 → ogc_na-0.3.51}/docs/tutorials.md +0 -0
  17. {ogc_na-0.3.49 → ogc_na-0.3.51}/mkdocs.yml +0 -0
  18. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/__init__.py +0 -0
  19. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/domain_config.py +0 -0
  20. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/download.py +0 -0
  21. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/gsp.py +0 -0
  22. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/input_filters/__init__.py +0 -0
  23. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/input_filters/csv.py +0 -0
  24. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/input_filters/xml.py +0 -0
  25. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/models.py +0 -0
  26. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/profile.py +0 -0
  27. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/provenance.py +0 -0
  28. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/update_vocabs.py +0 -0
  29. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/util.py +0 -0
  30. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc/na/validation.py +0 -0
  31. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc_na.egg-info/SOURCES.txt +0 -0
  32. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc_na.egg-info/dependency_links.txt +0 -0
  33. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc_na.egg-info/requires.txt +0 -0
  34. {ogc_na-0.3.49 → ogc_na-0.3.51}/ogc_na.egg-info/top_level.txt +0 -0
  35. {ogc_na-0.3.49 → ogc_na-0.3.51}/pyproject.toml +0 -0
  36. {ogc_na-0.3.49 → ogc_na-0.3.51}/rdf/catalog-v001.xml +0 -0
  37. {ogc_na-0.3.49 → ogc_na-0.3.51}/rdf/domaincfg.vocab.ttl +0 -0
  38. {ogc_na-0.3.49 → ogc_na-0.3.51}/requirements.txt +0 -0
  39. {ogc_na-0.3.49 → ogc_na-0.3.51}/setup.cfg +0 -0
  40. {ogc_na-0.3.49 → ogc_na-0.3.51}/setup.py +0 -0
  41. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/__init__.py +0 -0
  42. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/empty.ttl +0 -0
  43. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/headers.csv +0 -0
  44. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/no-headers.csv +0 -0
  45. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/profile_tree.ttl +0 -0
  46. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/profile_tree_cyclic.ttl +0 -0
  47. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/sample-context.jsonld +0 -0
  48. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/sample-schema-prop-c.yml +0 -0
  49. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/sample-schema.yml +0 -0
  50. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/schema-vocab.yml +0 -0
  51. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/data/uplift_context_valid.yml +0 -0
  52. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/test_ingest_json.py +0 -0
  53. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/test_input_filters_csv.py +0 -0
  54. {ogc_na-0.3.49 → ogc_na-0.3.51}/test/test_profile.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ogc_na
3
- Version: 0.3.49
3
+ Version: 0.3.51
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/
@@ -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.49'
16
- __version_tuple__ = version_tuple = (0, 3, 49)
15
+ __version__ = version = '0.3.51'
16
+ __version_tuple__ = version_tuple = (0, 3, 51)
@@ -143,12 +143,18 @@ ANNOTATION_ID = f'{ANNOTATION_PREFIX}id'
143
143
  ANNOTATION_PREFIXES = f'{ANNOTATION_PREFIX}prefixes'
144
144
  ANNOTATION_EXTRA_TERMS = f'{ANNOTATION_PREFIX}extra-terms'
145
145
  ANNOTATION_BASE = f'{ANNOTATION_PREFIX}base'
146
+ ANNOTATION_VOCAB = f'{ANNOTATION_PREFIX}vocab'
146
147
 
147
148
  ANNOTATION_IGNORE_EXPAND = [ANNOTATION_CONTEXT, ANNOTATION_EXTRA_TERMS, ANNOTATION_PREFIXES]
148
149
 
149
150
  CURIE_TERMS = '@id', '@type', '@index'
150
151
 
151
- UNDEFINED = object()
152
+ class Undefined:
153
+
154
+ def __bool__(self):
155
+ return False
156
+
157
+ UNDEFINED = Undefined()
152
158
 
153
159
  context_term_cache = LRUCache(maxsize=20)
154
160
  requests_session = requests_cache.CachedSession('ogc.na.annotate_schema', backend='memory', expire_after=180)
@@ -228,7 +234,7 @@ class SchemaResolver:
228
234
  return location, fragment
229
235
 
230
236
  def resolve_schema(self, ref: str | Path, from_schema: ReferencedSchema | None = None,
231
- force_contents: dict | None = None) -> ReferencedSchema | None:
237
+ force_contents: dict | str | None = None) -> ReferencedSchema | None:
232
238
  chain = from_schema.chain + [from_schema] if from_schema else []
233
239
  try:
234
240
  schema_source, fragment = self.resolve_ref(ref, from_schema)
@@ -248,9 +254,14 @@ class SchemaResolver:
248
254
  ref=ref,
249
255
  is_json=from_schema.is_json)
250
256
 
251
- contents, is_json = self.load_contents(schema_source)
252
257
  if force_contents:
253
- contents = force_contents
258
+ is_json = False
259
+ if isinstance(force_contents, str):
260
+ contents = load_yaml(content=force_contents)
261
+ else:
262
+ contents = force_contents
263
+ else:
264
+ contents, is_json = self.load_contents(schema_source)
254
265
  if fragment:
255
266
  return ReferencedSchema(location=schema_source, fragment=fragment,
256
267
  subschema=SchemaResolver._get_branch(contents, fragment),
@@ -635,6 +646,10 @@ class SchemaAnnotator:
635
646
 
636
647
  process_subschema(schema, [context], resolved_schema)
637
648
 
649
+ for key in ('@base', '@vocab'):
650
+ if context.get(key):
651
+ schema[f"{ANNOTATION_PREFIX}{key[1:]}"] = context[key]
652
+
638
653
  if prefixes:
639
654
  schema[ANNOTATION_PREFIXES] = prefixes
640
655
 
@@ -650,9 +665,10 @@ class ContextBuilder:
650
665
  Builds a JSON-LD context from a set of annotated JSON schemas.
651
666
  """
652
667
 
653
- def __init__(self, location: Path | str = None,
668
+ def __init__(self, location: Path | str,
654
669
  compact: bool = True,
655
670
  schema_resolver: SchemaResolver = None,
671
+ contents: dict | str | None = None,
656
672
  version=1.1):
657
673
  """
658
674
  :param location: file or URL load the annotated schema from
@@ -668,19 +684,20 @@ class ContextBuilder:
668
684
 
669
685
  self.visited_properties: dict[str, str | None] = {}
670
686
  self._missed_properties: dict[str, Any] = {} # Dict instead of set to keep order of insertion
671
- context = self._build_context(self.location, compact)
687
+ context = self._build_context(self.location, compact, contents=contents)
672
688
  if context:
673
689
  context['@version'] = version
674
690
  self.context = {'@context': context}
675
691
 
676
692
  def _build_context(self, schema_location: str | Path,
677
- compact: bool = True) -> dict:
693
+ compact: bool = True,
694
+ contents: dict | str | None = None) -> dict:
678
695
 
679
696
  parsed = self._parsed_schemas.get(schema_location)
680
697
  if parsed:
681
698
  return parsed
682
699
 
683
- root_schema = self.schema_resolver.resolve_schema(schema_location)
700
+ root_schema = self.schema_resolver.resolve_schema(schema_location, force_contents=contents)
684
701
 
685
702
  prefixes = {}
686
703
 
@@ -748,8 +765,10 @@ class ContextBuilder:
748
765
  if not isinstance(subschema, dict):
749
766
  return {}
750
767
 
751
- if subschema.get(ANNOTATION_BASE):
752
- onto_context['@base'] = subschema[ANNOTATION_BASE]
768
+ for key in (ANNOTATION_BASE, ANNOTATION_VOCAB):
769
+ top_level_value = subschema.get(key)
770
+ if top_level_value:
771
+ onto_context[f"@{key[len(ANNOTATION_PREFIX):]}"] = top_level_value
753
772
 
754
773
  read_properties(subschema, from_schema, onto_context, schema_path)
755
774
 
@@ -686,7 +686,7 @@ def process(input_files: str | Path | Sequence[str | Path],
686
686
  if isinstance(input_files, str) or not isinstance(input_files, Sequence):
687
687
  input_files = (input_files,)
688
688
  if batch:
689
- logger.info("Input files: %s", input_files)
689
+ logger.info("Input files: %s", [str(x) for x in input_files])
690
690
  remaining_fn: deque = deque()
691
691
  for input_file in input_files:
692
692
  if isinstance(input_file, str):
@@ -735,6 +735,8 @@ def process(input_files: str | Path | Sequence[str | Path],
735
735
  logger.warning("Error processing JSON/JSON-LD file, skipping: %s", getattr(e, 'msg', str(e)))
736
736
  else:
737
737
  raise
738
+ except Exception as e:
739
+ raise IOError(f'Error processing input file {fn}') from e
738
740
  else:
739
741
  for input_file in input_files:
740
742
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ogc_na
3
- Version: 0.3.49
3
+ Version: 0.3.51
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/
@@ -2,7 +2,7 @@ import unittest
2
2
  from pathlib import Path
3
3
 
4
4
  from ogc.na import annotate_schema
5
- from ogc.na.annotate_schema import SchemaAnnotator
5
+ from ogc.na.annotate_schema import SchemaAnnotator, ContextBuilder
6
6
 
7
7
  THIS_DIR = Path(__file__).parent
8
8
  DATA_DIR = THIS_DIR / 'data'
@@ -90,3 +90,22 @@ class AnnotateSchemaTest(unittest.TestCase):
90
90
  self.assertEqual(deep_get(schema, 'properties', 'propB', 'x-jsonld-id'), '@id')
91
91
  self.assertEqual(deep_get(schema, 'properties', 'propC', 'x-jsonld-id'), 'http://www.another.com/')
92
92
  self.assertEqual(deep_get(schema, 'properties', 'propD', 'x-jsonld-id'), vocab + 'propD')
93
+
94
+ def test_top_level_keywords(self):
95
+ annotator = SchemaAnnotator()
96
+ vocab = 'http://example.com/vocab#'
97
+ base = 'http://example.net/'
98
+ schema = annotator.process_schema(DATA_DIR / 'sample-schema-prop-c.yml', default_context={
99
+ '@context': {
100
+ '@base': base,
101
+ '@vocab': vocab,
102
+ }
103
+ }).schema
104
+
105
+ self.assertEqual(schema.get('x-jsonld-vocab'), vocab)
106
+ self.assertEqual(schema.get('x-jsonld-base'), base)
107
+
108
+ builder = ContextBuilder('http://example.com/schema.yaml', contents=schema)
109
+
110
+ self.assertEqual(deep_get(builder.context, '@context', '@vocab'), vocab)
111
+ self.assertEqual(deep_get(builder.context, '@context', '@base'), base)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes