inmanta-module-git-ops 0.7.0__tar.gz → 0.7.2__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 (69) hide show
  1. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/CHANGELOG.md +9 -0
  2. {inmanta_module_git_ops-0.7.0/inmanta_module_git_ops.egg-info → inmanta_module_git_ops-0.7.2}/PKG-INFO +1 -1
  3. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_git_ops/generator.py +48 -27
  4. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2/inmanta_module_git_ops.egg-info}/PKG-INFO +1 -1
  5. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_module_git_ops.egg-info/SOURCES.txt +1 -0
  6. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/setup.cfg +1 -1
  7. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/slice.py +3 -1
  8. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/setup.cfg +1 -1
  9. inmanta_module_git_ops-0.7.2/tests/test_generator.py +50 -0
  10. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_slice_schema.py +29 -0
  11. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/MANIFEST.in +0 -0
  12. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/README.md +0 -0
  13. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/README.md +0 -0
  14. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/.editorconfig +0 -0
  15. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/.gitignore +0 -0
  16. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/MANIFEST.in +0 -0
  17. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/README.md +0 -0
  18. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/files/.gitkeep +0 -0
  19. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/files/slices/fs.json +0 -0
  20. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/inmanta_plugins/example/__init__.py +0 -0
  21. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/inmanta_plugins/example/slices/__init__.py +0 -0
  22. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/inmanta_plugins/example/slices/fs.py +0 -0
  23. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/inmanta_plugins/example/slices/recursive.py +0 -0
  24. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/inmanta_plugins/example/slices/simple.py +0 -0
  25. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/model/_init.cf +0 -0
  26. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/model/slices/_init.cf +0 -0
  27. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/model/slices/fs/_init.cf +0 -0
  28. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/model/slices/fs/unroll.cf +0 -0
  29. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/model/slices/recursive/_init.cf +0 -0
  30. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/model/slices/simple/_init.cf +0 -0
  31. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/pyproject.toml +0 -0
  32. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/requirements.dev.txt +0 -0
  33. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/requirements.txt +0 -0
  34. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/setup.cfg +0 -0
  35. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/templates/.gitkeep +0 -0
  36. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/tests/test_basics.py +0 -0
  37. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/docs/example/tests/test_unroll.py +0 -0
  38. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_git_ops/__init__.py +0 -0
  39. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_git_ops/cli.py +0 -0
  40. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_git_ops/const.py +0 -0
  41. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_git_ops/py.typed +0 -0
  42. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_module_git_ops.egg-info/dependency_links.txt +0 -0
  43. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_module_git_ops.egg-info/entry_points.txt +0 -0
  44. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_module_git_ops.egg-info/not-zip-safe +0 -0
  45. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_module_git_ops.egg-info/requires.txt +0 -0
  46. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_module_git_ops.egg-info/top_level.txt +0 -0
  47. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/__init__.py +0 -0
  48. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/config.py +0 -0
  49. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/files/.gitkeep +0 -0
  50. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/model/_init.cf +0 -0
  51. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/model/processors.cf +0 -0
  52. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/model/slice/_init.cf +0 -0
  53. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/processors.py +0 -0
  54. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/py.typed +0 -0
  55. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/store.py +0 -0
  56. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/inmanta_plugins/git_ops/templates/.gitkeep +0 -0
  57. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/pyproject.toml +0 -0
  58. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/pytest_inmanta_git_ops/__init__.py +0 -0
  59. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/pytest_inmanta_git_ops/plugin.py +0 -0
  60. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/pytest_inmanta_git_ops/project.py +0 -0
  61. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/pytest_inmanta_git_ops/py.typed +0 -0
  62. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/pytest_inmanta_git_ops/slice.py +0 -0
  63. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_basics.py +0 -0
  64. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_cli.py +0 -0
  65. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_example.py +0 -0
  66. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_migrations.py +0 -0
  67. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_processors.py +0 -0
  68. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_slice_reload.py +0 -0
  69. {inmanta_module_git_ops-0.7.0 → inmanta_module_git_ops-0.7.2}/tests/test_unroll.py +0 -0
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.7.2 - 2026-09-28
4
+
5
+ - Support discriminated unions with a single member (`typing.Annotated[A, pydantic.Field(discriminator="type")]`), to declare a polymorphic relation before its second member exists.
6
+
7
+ ## v0.7.1 - 2026-08-08
8
+
9
+ - Fix unstable ordering of index fields in the generated model: the generator now emits index fields in the order the keys are declared on the slice schema, instead of the arbitrary order of the entity's field set.
10
+
11
+
3
12
  ## v0.7.0 - 2026-06-20
4
13
 
5
14
  - Add git_ops::processors::get_template_value processor to convert template references to the rendered template.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inmanta-module-git-ops
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: Declarative parametrization, extension and validation of Inmanta DSL models.
5
5
  Author: Guillaume Everarts de Velp
6
6
  Author-email: edvgui@gmail.com
@@ -195,6 +195,39 @@ def get_attribute(
195
195
  )
196
196
 
197
197
 
198
+ def get_key_fields(
199
+ entity: Entity,
200
+ keys: Sequence[str],
201
+ *,
202
+ parent_relation: EntityRelation | None,
203
+ ) -> Sequence[EntityField]:
204
+ """
205
+ Collect the fields that make up the index of an entity, in a stable order:
206
+ the parent relation first (when set), followed by the key attributes in the
207
+ exact order in which they are declared on the slice schema.
208
+
209
+ Iterating ``entity.all_fields()`` directly is not stable: it returns a set,
210
+ so the resulting index field order is arbitrary and changes from one
211
+ generation to the next.
212
+
213
+ :param entity: The entity whose key fields to collect.
214
+ :param keys: The names of the key attributes, in the desired order.
215
+ :param parent_relation: When set, the parent relation to prepend to the
216
+ index fields.
217
+ """
218
+ fields_by_name = {field.name: field for field in entity.all_fields()}
219
+
220
+ key_fields: dict[str, EntityField] = {}
221
+ if parent_relation is not None:
222
+ key_fields[parent_relation.name] = parent_relation
223
+
224
+ for key in keys:
225
+ if key in fields_by_name:
226
+ key_fields[key] = fields_by_name[key]
227
+
228
+ return list(key_fields.values())
229
+
230
+
198
231
  def get_relation(
199
232
  schema: slice.SliceEntityRelationSchema,
200
233
  *,
@@ -255,17 +288,15 @@ def get_relation(
255
288
  )
256
289
  builder.add_module_element(helper)
257
290
 
258
- helper_key_fields: dict[str, EntityField] = {
259
- parent_relation.name: parent_relation,
260
- }
261
- for field in helper.all_fields():
262
- if field.name in sub_schema.keys:
263
- helper_key_fields[field.name] = field
264
291
  builder.add_module_element(
265
292
  Index(
266
293
  path=helper.path,
267
294
  entity=helper,
268
- fields=helper_key_fields.values(),
295
+ fields=get_key_fields(
296
+ helper,
297
+ sub_schema.keys,
298
+ parent_relation=parent_relation,
299
+ ),
269
300
  )
270
301
  )
271
302
  builder.add_module_element(
@@ -303,20 +334,15 @@ def get_relation(
303
334
 
304
335
  builder.add_module_element(embedded_entity)
305
336
 
306
- key_fields: dict[str, EntityField] = {}
307
-
308
- if parent_relation is not None:
309
- key_fields[parent_relation.name] = parent_relation
310
-
311
- for field in embedded_entity.all_fields():
312
- if field.name in schema.entity.keys:
313
- key_fields[field.name] = field
314
-
315
337
  builder.add_module_element(
316
338
  Index(
317
339
  path=embedded_entity.path,
318
340
  entity=embedded_entity,
319
- fields=key_fields.values(),
341
+ fields=get_key_fields(
342
+ embedded_entity,
343
+ schema.entity.keys,
344
+ parent_relation=parent_relation,
345
+ ),
320
346
  )
321
347
  )
322
348
 
@@ -431,20 +457,15 @@ def get_entity(
431
457
  # keys are carried by its concrete sub entities, which define their own
432
458
  # indexes, so no index is generated for the base itself.
433
459
  if (slice_root or parent_relation is not None) and schema.discriminator is None:
434
- key_fields: dict[str, EntityField] = {}
435
-
436
- if parent_relation is not None:
437
- key_fields[parent_relation.name] = parent_relation
438
-
439
- for field in entity.all_fields():
440
- if field.name in schema.keys:
441
- key_fields[field.name] = field
442
-
443
460
  builder.add_module_element(
444
461
  Index(
445
462
  path=entity.path,
446
463
  entity=entity,
447
- fields=key_fields.values(),
464
+ fields=get_key_fields(
465
+ entity,
466
+ schema.keys,
467
+ parent_relation=parent_relation,
468
+ ),
448
469
  )
449
470
  )
450
471
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inmanta-module-git-ops
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: Declarative parametrization, extension and validation of Inmanta DSL models.
5
5
  Author: Guillaume Everarts de Velp
6
6
  Author-email: edvgui@gmail.com
@@ -60,6 +60,7 @@ pytest_inmanta_git_ops/slice.py
60
60
  tests/test_basics.py
61
61
  tests/test_cli.py
62
62
  tests/test_example.py
63
+ tests/test_generator.py
63
64
  tests/test_migrations.py
64
65
  tests/test_processors.py
65
66
  tests/test_slice_reload.py
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = inmanta-module-git-ops
3
- version = 0.7.0
3
+ version = 0.7.2
4
4
  description = Declarative parametrization, extension and validation of Inmanta DSL models.
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
@@ -261,9 +261,11 @@ def discriminated_union(
261
261
  return None
262
262
 
263
263
  union_type = typing.get_args(resolved)[0]
264
+ # A union with a single member (e.g. the first of a family of types that
265
+ # will grow later) is not a typing union, pydantic accepts it anyway.
264
266
  members = [
265
267
  member
266
- for member in typing.get_args(union_type)
268
+ for member in typing.get_args(union_type) or (union_type,)
267
269
  if inspect.isclass(member) and issubclass(member, EmbeddedSliceObjectABC)
268
270
  ]
269
271
  if not members:
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = inmanta-module-git-ops
3
- version = 0.7.0
3
+ version = 0.7.2
4
4
  description = Declarative parametrization, extension and validation of Inmanta DSL models.
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
@@ -0,0 +1,50 @@
1
+ """
2
+ Copyright 2026 Guillaume Everarts de Velp
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ Contact: edvgui@gmail.com
17
+ """
18
+
19
+ from inmanta_module_factory.inmanta import Index
20
+ from inmanta_plugins.example.slices.fs import RootFolder
21
+
22
+ from inmanta_git_ops import generator
23
+
24
+
25
+ def test_index_field_order_matches_keys() -> None:
26
+ """
27
+ The generated index of an entity must list its fields in the exact order in
28
+ which the keys are declared on the slice schema.
29
+
30
+ The generator used to build the index by iterating ``entity.all_fields()``,
31
+ which returns a set: the resulting field order was arbitrary and unstable
32
+ from one generation to the next. RootFolder declares its keys as
33
+ ``["root", "name"]`` where ``root`` is defined on the entity itself and
34
+ ``name`` is inherited, a case where the set iteration order is very unlikely
35
+ to match the declared order.
36
+ """
37
+ schema = RootFolder.entity_schema()
38
+ assert list(schema.keys) == ["root", "name"]
39
+
40
+ entity = generator.get_entity(schema, slice_root=True)
41
+
42
+ builder = generator.get_module_builder("example")
43
+ indexes = [
44
+ element
45
+ for element in builder._model_files[entity.path_string]
46
+ if isinstance(element, Index) and element.entity is entity
47
+ ]
48
+ assert len(indexes) == 1
49
+
50
+ assert [field.name for field in indexes[0].fields] == list(schema.keys)
@@ -235,3 +235,32 @@ def test_scaffold_discriminated_union() -> None:
235
235
  # the placeholder
236
236
  "broken": const.SLICE_PLACEHOLDER,
237
237
  }
238
+
239
+
240
+ def test_single_member_discriminated_union() -> None:
241
+ """
242
+ A discriminated union with a single member is not a typing union, but it
243
+ is still accepted by pydantic, and it should be modeled like any other
244
+ union: a base entity carrying the discriminator, extended by the member.
245
+ """
246
+
247
+ class A(slice.EmbeddedSliceObjectABC):
248
+ type: typing.Literal["a"] = "a"
249
+ value: str
250
+
251
+ OnlyA = typing.Annotated[A, pydantic.Field(discriminator="type")]
252
+
253
+ class Root(slice.SliceObjectABC):
254
+ name: str
255
+ items: Sequence[OnlyA] = pydantic.Field(default_factory=list)
256
+
257
+ # The entity schema can only be built for classes of an inmanta module
258
+ for cls in (A, Root):
259
+ cls.__module__ = "inmanta_plugins.example.slices.single"
260
+
261
+ root = Root(name="root", items=[{"type": "a", "value": "x"}])
262
+ assert root.items == [A(value="x")]
263
+
264
+ items = next(r for r in Root.entity_schema().all_relations() if r.name == "items")
265
+ assert items.entity.discriminator == "type"
266
+ assert [sub.name for sub in items.entity.sub_entities] == ["A"]