tro-utils 0.4.4__tar.gz → 0.4.5__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.
Files changed (80) hide show
  1. {tro_utils-0.4.4 → tro_utils-0.4.5}/PKG-INFO +1 -1
  2. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_cli.py +4 -4
  3. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_extra_context.py +28 -28
  4. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/_version.py +3 -3
  5. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/cli.py +3 -3
  6. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/tro.py +19 -12
  7. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/tro_utils.py +1 -1
  8. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils.egg-info/PKG-INFO +1 -1
  9. {tro_utils-0.4.4 → tro_utils-0.4.5}/.coveragerc +0 -0
  10. {tro_utils-0.4.4 → tro_utils-0.4.5}/.editorconfig +0 -0
  11. {tro_utils-0.4.4 → tro_utils-0.4.5}/.github/ISSUE_TEMPLATE.md +0 -0
  12. {tro_utils-0.4.4 → tro_utils-0.4.5}/.github/workflows/release.yml +0 -0
  13. {tro_utils-0.4.4 → tro_utils-0.4.5}/.github/workflows/test.yml +0 -0
  14. {tro_utils-0.4.4 → tro_utils-0.4.5}/.gitignore +0 -0
  15. {tro_utils-0.4.4 → tro_utils-0.4.5}/.readthedocs.yaml +0 -0
  16. {tro_utils-0.4.4 → tro_utils-0.4.5}/.travis.yml +0 -0
  17. {tro_utils-0.4.4 → tro_utils-0.4.5}/LICENSE +0 -0
  18. {tro_utils-0.4.4 → tro_utils-0.4.5}/MANIFEST.in +0 -0
  19. {tro_utils-0.4.4 → tro_utils-0.4.5}/Makefile +0 -0
  20. {tro_utils-0.4.4 → tro_utils-0.4.5}/README.md +0 -0
  21. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/Makefile +0 -0
  22. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/authors.md +0 -0
  23. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/conf.py +0 -0
  24. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/contributing.md +0 -0
  25. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/history.md +0 -0
  26. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/index.md +0 -0
  27. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/installation.md +0 -0
  28. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/make.bat +0 -0
  29. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/readme.md +0 -0
  30. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/requirements.txt +0 -0
  31. {tro_utils-0.4.4 → tro_utils-0.4.5}/docs/usage.md +0 -0
  32. {tro_utils-0.4.4 → tro_utils-0.4.5}/pyproject.toml +0 -0
  33. {tro_utils-0.4.4 → tro_utils-0.4.5}/pytest.ini +0 -0
  34. {tro_utils-0.4.4 → tro_utils-0.4.5}/requirements_dev.txt +0 -0
  35. {tro_utils-0.4.4 → tro_utils-0.4.5}/setup.cfg +0 -0
  36. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/__init__.py +0 -0
  37. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/conftest.py +0 -0
  38. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/helpers.py +0 -0
  39. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_artifact_arrangement.py +0 -0
  40. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_artifact_composition.py +0 -0
  41. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_artifact_location.py +0 -0
  42. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_composition_fingerprint.py +0 -0
  43. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_hash_value.py +0 -0
  44. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_performance.py +0 -0
  45. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_research_artifact.py +0 -0
  46. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_transparent_research_object.py +0 -0
  47. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_trs.py +0 -0
  48. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_models_tsa.py +0 -0
  49. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_replication_package_model.py +0 -0
  50. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_replication_package_verification.py +0 -0
  51. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_arrangements.py +0 -0
  52. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_creation.py +0 -0
  53. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_hashing.py +0 -0
  54. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_performances.py +0 -0
  55. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_reporting.py +0 -0
  56. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_save_load.py +0 -0
  57. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_signing.py +0 -0
  58. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_timestamping.py +0 -0
  59. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_utility_methods.py +0 -0
  60. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_tro_workflow.py +0 -0
  61. {tro_utils-0.4.4 → tro_utils-0.4.5}/tests/test_version.py +0 -0
  62. {tro_utils-0.4.4 → tro_utils-0.4.5}/tox.ini +0 -0
  63. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/__init__.py +0 -0
  64. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/default.jinja2 +0 -0
  65. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/__init__.py +0 -0
  66. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/_base.py +0 -0
  67. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/arrangement.py +0 -0
  68. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/artifact.py +0 -0
  69. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/attribute.py +0 -0
  70. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/composition.py +0 -0
  71. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/hash_value.py +0 -0
  72. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/performance.py +0 -0
  73. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/trs.py +0 -0
  74. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/models/tsa.py +0 -0
  75. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils/replication_package.py +0 -0
  76. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils.egg-info/SOURCES.txt +0 -0
  77. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils.egg-info/dependency_links.txt +0 -0
  78. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils.egg-info/entry_points.txt +0 -0
  79. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils.egg-info/requires.txt +0 -0
  80. {tro_utils-0.4.4 → tro_utils-0.4.5}/tro_utils.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tro-utils
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Utilities for creating, editing and interacting with TROs
5
5
  Author-email: Kacper Kowalik <xarthisius.kk@gmail.com>, Craig Willis <willis8@illinois.edu>
6
6
  Maintainer-email: Kacper Kowalik <xarthisius.kk@gmail.com>
@@ -690,7 +690,7 @@ class TestExtraContextCLI:
690
690
  assert result.exit_code == 0, result.output
691
691
  with open(tro_file) as f:
692
692
  data = json.load(f)
693
- assert {"ex": "http://example.org/"} in data["@context"]
693
+ assert data["@context"]["ex"] == "http://example.org/"
694
694
 
695
695
  def test_extra_context_multiple(
696
696
  self, runner, tmp_path, temp_workspace, trs_profile
@@ -716,8 +716,8 @@ class TestExtraContextCLI:
716
716
  assert result.exit_code == 0, result.output
717
717
  with open(tro_file) as f:
718
718
  data = json.load(f)
719
- assert {"ex": "http://example.org/"} in data["@context"]
720
- assert {"foaf": "http://xmlns.com/foaf/0.1/"} in data["@context"]
719
+ assert data["@context"]["ex"] == "http://example.org/"
720
+ assert data["@context"]["foaf"] == "http://xmlns.com/foaf/0.1/"
721
721
 
722
722
  def test_extra_context_invalid_format(
723
723
  self, runner, tmp_path, temp_workspace, trs_profile
@@ -761,7 +761,7 @@ class TestExtraContextCLI:
761
761
  )
762
762
  with open(tro_file) as f:
763
763
  data = json.load(f)
764
- base = data["@context"][0]
764
+ base = data["@context"]
765
765
  assert "trov" in base
766
766
 
767
767
  def test_cli_help_shows_extra_context(self, runner):
@@ -12,82 +12,82 @@ class TestExtraContext:
12
12
  """Tests for extra vocabulary support in @context."""
13
13
 
14
14
  def test_extra_context_default_empty(self):
15
- """TransparentResearchObject.extra_context defaults to an empty list."""
15
+ """TransparentResearchObject.extra_context defaults to an empty dict."""
16
16
  tro = TransparentResearchObject()
17
- assert tro.extra_context == []
17
+ assert tro.extra_context == {}
18
18
 
19
19
  def test_extra_context_dict_in_jsonld(self):
20
20
  """A dict extra_context entry appears in the serialised @context."""
21
21
  tro = TransparentResearchObject()
22
- tro.extra_context = [{"ex": "http://example.org/"}]
22
+ tro.extra_context = {"ex": "http://example.org/"}
23
23
  data = tro.to_jsonld()
24
- assert {"ex": "http://example.org/"} in data["@context"]
24
+ assert data["@context"]["ex"] == "http://example.org/"
25
25
 
26
26
  def test_extra_context_multiple_entries(self):
27
- """Multiple extra_context dict entries all appear in @context."""
27
+ """Multiple extra_context entries all appear in @context."""
28
28
  tro = TransparentResearchObject()
29
- tro.extra_context = [
30
- {"ex": "http://example.org/"},
31
- {"foaf": "http://xmlns.com/foaf/0.1/"},
32
- ]
29
+ tro.extra_context = {
30
+ "ex": "http://example.org/",
31
+ "foaf": "http://xmlns.com/foaf/0.1/",
32
+ }
33
33
  data = tro.to_jsonld()
34
- assert {"ex": "http://example.org/"} in data["@context"]
35
- assert {"foaf": "http://xmlns.com/foaf/0.1/"} in data["@context"]
34
+ assert data["@context"]["ex"] == "http://example.org/"
35
+ assert data["@context"]["foaf"] == "http://xmlns.com/foaf/0.1/"
36
36
 
37
37
  def test_extra_context_base_context_still_present(self):
38
- """The standard base context is always the first entry in @context."""
38
+ """The standard base context keys are always present in @context."""
39
39
  tro = TransparentResearchObject()
40
- tro.extra_context = [{"ex": "http://example.org/"}]
40
+ tro.extra_context = {"ex": "http://example.org/"}
41
41
  data = tro.to_jsonld()
42
- base = data["@context"][0]
42
+ base = data["@context"]
43
43
  assert "trov" in base
44
44
  assert "rdf" in base
45
45
 
46
46
  def test_extra_context_roundtrip(self, tmp_path):
47
- """Extra context dict entries survive a save/load roundtrip."""
47
+ """Extra context entries survive a save/load roundtrip."""
48
48
  tro = TransparentResearchObject()
49
- tro.extra_context = [
50
- {"ex": "http://example.org/"},
51
- {"foaf": "http://xmlns.com/foaf/0.1/"},
52
- ]
49
+ tro.extra_context = {
50
+ "ex": "http://example.org/",
51
+ "foaf": "http://xmlns.com/foaf/0.1/",
52
+ }
53
53
  filepath = tmp_path / "tro_with_extra_ctx.jsonld"
54
54
  tro.save(str(filepath))
55
55
 
56
56
  loaded = TransparentResearchObject.load(str(filepath))
57
- assert {"ex": "http://example.org/"} in loaded.extra_context
58
- assert {"foaf": "http://xmlns.com/foaf/0.1/"} in loaded.extra_context
57
+ assert loaded.extra_context["ex"] == "http://example.org/"
58
+ assert loaded.extra_context["foaf"] == "http://xmlns.com/foaf/0.1/"
59
59
 
60
60
  def test_extra_context_via_tro_facade(self, tmp_path):
61
61
  """TRO facade propagates extra_context to the underlying model."""
62
62
  tro_file = tmp_path / "tro.jsonld"
63
63
  tro = TRO(
64
64
  filepath=str(tro_file),
65
- extra_context=[{"ex": "http://example.org/"}],
65
+ extra_context={"ex": "http://example.org/"},
66
66
  )
67
67
  tro.save()
68
68
 
69
69
  with open(tro_file) as f:
70
70
  data = json.load(f)
71
- assert {"ex": "http://example.org/"} in data["@context"]
71
+ assert data["@context"]["ex"] == "http://example.org/"
72
72
 
73
73
  def test_extra_context_via_tro_facade_extends_existing(self, tmp_path):
74
- """TRO facade appends extra_context to any context already in the file."""
74
+ """TRO facade merges extra_context into any context already in the file."""
75
75
  tro_file = tmp_path / "tro.jsonld"
76
76
  # First save with one extra context entry
77
77
  tro = TRO(
78
78
  filepath=str(tro_file),
79
- extra_context=[{"ex": "http://example.org/"}],
79
+ extra_context={"ex": "http://example.org/"},
80
80
  )
81
81
  tro.save()
82
82
 
83
83
  # Re-open and add a second entry
84
84
  tro2 = TRO(
85
85
  filepath=str(tro_file),
86
- extra_context=[{"foaf": "http://xmlns.com/foaf/0.1/"}],
86
+ extra_context={"foaf": "http://xmlns.com/foaf/0.1/"},
87
87
  )
88
88
  tro2.save()
89
89
 
90
90
  with open(tro_file) as f:
91
91
  data = json.load(f)
92
- assert {"ex": "http://example.org/"} in data["@context"]
93
- assert {"foaf": "http://xmlns.com/foaf/0.1/"} in data["@context"]
92
+ assert data["@context"]["ex"] == "http://example.org/"
93
+ assert data["@context"]["foaf"] == "http://xmlns.com/foaf/0.1/"
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.4.4'
22
- __version_tuple__ = version_tuple = (0, 4, 4)
21
+ __version__ = version = '0.4.5'
22
+ __version_tuple__ = version_tuple = (0, 4, 5)
23
23
 
24
- __commit_id__ = commit_id = 'g49075ca80'
24
+ __commit_id__ = commit_id = 'g95ec41b0d'
@@ -22,11 +22,11 @@ def _parse_arrangement_ref(value: str) -> tuple[str, str | None]:
22
22
 
23
23
 
24
24
  def _parse_extra_context_value(ctx, param, value):
25
- """Parse ``--extra-context`` values into JSON-LD context dicts.
25
+ """Parse ``--extra-context`` values into a JSON-LD context dict.
26
26
 
27
27
  Each value must be in ``PREFIX=URI`` form (e.g. ``ex=http://example.org/``).
28
28
  """
29
- result = []
29
+ result = {}
30
30
  for v in value:
31
31
  if "=" not in v:
32
32
  raise click.BadParameter(
@@ -35,7 +35,7 @@ def _parse_extra_context_value(ctx, param, value):
35
35
  ctx=ctx,
36
36
  )
37
37
  prefix, _, uri = v.partition("=")
38
- result.append({prefix: uri})
38
+ result[prefix] = uri
39
39
  return result
40
40
 
41
41
 
@@ -28,14 +28,12 @@ from .tsa import TimeStampingAuthority
28
28
 
29
29
  TROV_VOCABULARY_VERSION = Version("0.1")
30
30
 
31
- _JSONLD_CONTEXT = [
32
- {
33
- "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
34
- "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
35
- "trov": f"https://w3id.org/trace/trov/{TROV_VOCABULARY_VERSION}#",
36
- "schema": "https://schema.org",
37
- }
38
- ]
31
+ _JSONLD_CONTEXT = {
32
+ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
33
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
34
+ "trov": f"https://w3id.org/trace/trov/{TROV_VOCABULARY_VERSION}#",
35
+ "schema": "https://schema.org/",
36
+ }
39
37
 
40
38
 
41
39
  @dataclass
@@ -56,7 +54,7 @@ class TransparentResearchObject(TROVModel):
56
54
  arrangements: list[ArtifactArrangement] = field(default_factory=list)
57
55
  performances: list[TrustedResearchPerformance] = field(default_factory=list)
58
56
  attributes: list[TROAttribute] = field(default_factory=list)
59
- extra_context: list[dict] = field(default_factory=list)
57
+ extra_context: dict = field(default_factory=dict)
60
58
 
61
59
  # ------------------------------------------------------------------
62
60
  # File I/O
@@ -327,7 +325,7 @@ class TransparentResearchObject(TROVModel):
327
325
  graph_node["trov:hasPerformance"][i].update(extra)
328
326
 
329
327
  return {
330
- "@context": _JSONLD_CONTEXT + self.extra_context,
328
+ "@context": {**_JSONLD_CONTEXT, **self.extra_context},
331
329
  "@graph": [graph_node],
332
330
  }
333
331
 
@@ -346,8 +344,17 @@ class TransparentResearchObject(TROVModel):
346
344
  """
347
345
  graph = data["@graph"][0]
348
346
 
349
- raw_context = data.get("@context", [])
350
- extra_context = list(raw_context[1:]) if isinstance(raw_context, list) else []
347
+ raw_context = data.get("@context", {})
348
+ if isinstance(raw_context, list):
349
+ # backward compat: merge list of dicts into a single dict
350
+ merged: dict = {}
351
+ for item in raw_context:
352
+ if isinstance(item, dict):
353
+ merged.update(item)
354
+ raw_context = merged
355
+ extra_context = {
356
+ k: v for k, v in raw_context.items() if k not in _JSONLD_CONTEXT
357
+ }
351
358
 
352
359
  vocab_version = Version(graph.get("trov:vocabularyVersion", "0.0.1"))
353
360
  if vocab_version < TROV_VOCABULARY_VERSION:
@@ -82,7 +82,7 @@ class TRO:
82
82
  self._model = TransparentResearchObject.load(self.tro_filename)
83
83
 
84
84
  if extra_context:
85
- self._model.extra_context.extend(extra_context)
85
+ self._model.extra_context.update(extra_context)
86
86
 
87
87
  self.gpg = gnupg.GPG(gnupghome=GPG_HOME, verbose=False)
88
88
  if gpg_fingerprint:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tro-utils
3
- Version: 0.4.4
3
+ Version: 0.4.5
4
4
  Summary: Utilities for creating, editing and interacting with TROs
5
5
  Author-email: Kacper Kowalik <xarthisius.kk@gmail.com>, Craig Willis <willis8@illinois.edu>
6
6
  Maintainer-email: Kacper Kowalik <xarthisius.kk@gmail.com>
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