inmanta-module-git-ops 0.6.0__tar.gz → 0.7.0__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 (68) hide show
  1. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/CHANGELOG.md +5 -0
  2. {inmanta_module_git_ops-0.6.0/inmanta_module_git_ops.egg-info → inmanta_module_git_ops-0.7.0}/PKG-INFO +1 -1
  3. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0/inmanta_module_git_ops.egg-info}/PKG-INFO +1 -1
  4. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/__init__.py +91 -18
  5. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/processors.py +39 -1
  6. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/setup.cfg +1 -1
  7. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/setup.cfg +1 -1
  8. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_processors.py +72 -1
  9. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/MANIFEST.in +0 -0
  10. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/README.md +0 -0
  11. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/README.md +0 -0
  12. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/.editorconfig +0 -0
  13. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/.gitignore +0 -0
  14. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/MANIFEST.in +0 -0
  15. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/README.md +0 -0
  16. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/files/.gitkeep +0 -0
  17. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/files/slices/fs.json +0 -0
  18. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/inmanta_plugins/example/__init__.py +0 -0
  19. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/inmanta_plugins/example/slices/__init__.py +0 -0
  20. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/inmanta_plugins/example/slices/fs.py +0 -0
  21. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/inmanta_plugins/example/slices/recursive.py +0 -0
  22. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/inmanta_plugins/example/slices/simple.py +0 -0
  23. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/model/_init.cf +0 -0
  24. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/model/slices/_init.cf +0 -0
  25. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/model/slices/fs/_init.cf +0 -0
  26. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/model/slices/fs/unroll.cf +0 -0
  27. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/model/slices/recursive/_init.cf +0 -0
  28. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/model/slices/simple/_init.cf +0 -0
  29. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/pyproject.toml +0 -0
  30. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/requirements.dev.txt +0 -0
  31. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/requirements.txt +0 -0
  32. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/setup.cfg +0 -0
  33. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/templates/.gitkeep +0 -0
  34. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/tests/test_basics.py +0 -0
  35. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/docs/example/tests/test_unroll.py +0 -0
  36. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_git_ops/__init__.py +0 -0
  37. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_git_ops/cli.py +0 -0
  38. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_git_ops/const.py +0 -0
  39. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_git_ops/generator.py +0 -0
  40. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_git_ops/py.typed +0 -0
  41. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_module_git_ops.egg-info/SOURCES.txt +0 -0
  42. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_module_git_ops.egg-info/dependency_links.txt +0 -0
  43. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_module_git_ops.egg-info/entry_points.txt +0 -0
  44. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_module_git_ops.egg-info/not-zip-safe +0 -0
  45. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_module_git_ops.egg-info/requires.txt +0 -0
  46. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_module_git_ops.egg-info/top_level.txt +0 -0
  47. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/config.py +0 -0
  48. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/files/.gitkeep +0 -0
  49. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/model/_init.cf +0 -0
  50. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/model/processors.cf +0 -0
  51. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/model/slice/_init.cf +0 -0
  52. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/py.typed +0 -0
  53. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/slice.py +0 -0
  54. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/store.py +0 -0
  55. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/inmanta_plugins/git_ops/templates/.gitkeep +0 -0
  56. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/pyproject.toml +0 -0
  57. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/pytest_inmanta_git_ops/__init__.py +0 -0
  58. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/pytest_inmanta_git_ops/plugin.py +0 -0
  59. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/pytest_inmanta_git_ops/project.py +0 -0
  60. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/pytest_inmanta_git_ops/py.typed +0 -0
  61. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/pytest_inmanta_git_ops/slice.py +0 -0
  62. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_basics.py +0 -0
  63. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_cli.py +0 -0
  64. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_example.py +0 -0
  65. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_migrations.py +0 -0
  66. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_slice_reload.py +0 -0
  67. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_slice_schema.py +0 -0
  68. {inmanta_module_git_ops-0.6.0 → inmanta_module_git_ops-0.7.0}/tests/test_unroll.py +0 -0
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.7.0 - 2026-06-20
4
+
5
+ - Add git_ops::processors::get_template_value processor to convert template references to the rendered template.
6
+ - Add automatic inmanta.plugins.Context injection to the attribute_processor decorator, passed as the first positional argument like the native plugin decorator does.
7
+
3
8
  ## v0.6.0 - 2026-06-17
4
9
 
5
10
  - Only insert the `update` operation on slice elements whose content actually changed, instead of on every element of a slice that has more than one version. Unchanged elements keep the `create` operation; `create` and `delete` are unaffected.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inmanta-module-git-ops
3
- Version: 0.6.0
3
+ Version: 0.7.0
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: inmanta-module-git-ops
3
- Version: 0.6.0
3
+ Version: 0.7.0
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
@@ -18,11 +18,12 @@ Contact: edvgui@gmail.com
18
18
 
19
19
  import functools
20
20
  import importlib
21
+ import inspect
21
22
  import typing
22
23
  from collections.abc import Sequence
23
24
  from dataclasses import asdict, dataclass
24
25
 
25
- from inmanta.plugins import Plugin, plugin
26
+ from inmanta.plugins import Context, Plugin, plugin
26
27
  from inmanta.util import dict_path
27
28
  from inmanta_git_ops import const
28
29
 
@@ -211,7 +212,31 @@ class AttributeProcessorFunction[**P, R](typing.Protocol):
211
212
  pass
212
213
 
213
214
 
214
- def attribute_processor[F: AttributeProcessorFunction](func: F) -> F:
215
+ class ContextAttributeProcessorFunction[**P, R](typing.Protocol):
216
+ """
217
+ Define the interface that processor functions requesting the compiler
218
+ context must implement. The context is passed automatically by the compiler
219
+ as the first positional argument.
220
+ """
221
+
222
+ def __call__(
223
+ self,
224
+ context: Context,
225
+ store_name: str,
226
+ name: str,
227
+ path: str,
228
+ previous_value: R | None,
229
+ *args: P.args,
230
+ **kwargs: P.kwargs,
231
+ ) -> R:
232
+ pass
233
+
234
+
235
+ def attribute_processor[
236
+ F: AttributeProcessorFunction | ContextAttributeProcessorFunction
237
+ ](
238
+ func: F,
239
+ ) -> F:
215
240
  """
216
241
  Register a function as an attribute processor. Attribute processors are
217
242
  called during update compile to process the value of a slice attribute and
@@ -233,8 +258,44 @@ def attribute_processor[F: AttributeProcessorFunction](func: F) -> F:
233
258
  else:
234
259
  return None
235
260
 
261
+ Similarly to the native plugin decorator, a processor can request the
262
+ compiler context by annotating an argument with ``inmanta.plugins.Context``.
263
+ When present, it is automatically passed by the compiler and must be the
264
+ first positional argument:
265
+
266
+ .. code-block:: python
267
+
268
+ @attribute_processor
269
+ def upper(
270
+ context: Context,
271
+ store_name: str,
272
+ name: str,
273
+ path: str,
274
+ previous_value: str | None,
275
+ ) -> str | None:
276
+ ...
277
+
236
278
  :param func: The processor function to register and wrap.
237
279
  """
280
+ # Detect whether the processor requests the compiler context. Mirroring the
281
+ # native plugin decorator, the context is injected by the compiler and, for
282
+ # processors, is only supported as the first positional argument.
283
+ arg_spec = inspect.getfullargspec(func)
284
+ expects_context = (
285
+ bool(arg_spec.args) and arg_spec.annotations.get(arg_spec.args[0]) is Context
286
+ )
287
+ misplaced_context = [
288
+ arg
289
+ for arg in (*arg_spec.args[1:], *arg_spec.kwonlyargs)
290
+ if arg_spec.annotations.get(arg) is Context
291
+ ]
292
+ if misplaced_context:
293
+ func_name = getattr(func, "__name__", repr(func))
294
+ raise ValueError(
295
+ f"Processor {func_name!r} declares a Context argument "
296
+ f"({misplaced_context[0]!r}) that is not the first positional "
297
+ f"argument. The Context must be the first positional argument."
298
+ )
238
299
 
239
300
  # Make sure that the inmanta compiler sees this wrapped function the same way
240
301
  # as the plugin it wraps, with its annotations and defaults
@@ -244,10 +305,6 @@ def attribute_processor[F: AttributeProcessorFunction](func: F) -> F:
244
305
  )
245
306
  def wrapped(
246
307
  self: Plugin,
247
- store_name: str,
248
- name: str,
249
- path: str,
250
- previous_value: object,
251
308
  *args: object,
252
309
  **kwargs: object,
253
310
  ) -> object:
@@ -255,13 +312,27 @@ def attribute_processor[F: AttributeProcessorFunction](func: F) -> F:
255
312
  Wrapper function, getting the value from the slice and, if this is an
256
313
  update compile, also call the processor function and return its result.
257
314
 
258
- :param store_name: The name of the slice store in which the slice is.
259
- :param name: The name of the slice.
260
- :param path: The path within the slice's attributes towards the value that
261
- should be updated.
262
- :param previous_value: The value that is currently in the slice for the
263
- given attribute.
315
+ The positional arguments are, in order: an optional Context object
316
+ (injected by the compiler when the processor requests it), the slice
317
+ store name, the slice name, the path within the slice's attributes
318
+ towards the value that should be updated, and the value that is
319
+ currently in the slice for that attribute (recomputed here and ignored
320
+ if provided).
264
321
  """
322
+ # The compiler injects the optional Context as the first positional
323
+ # argument, shifting the slice-related arguments by one position.
324
+ offset = 1 if expects_context else 0
325
+ store_name = typing.cast(str, args[offset])
326
+ name = typing.cast(str, args[offset + 1])
327
+ path = typing.cast(str, args[offset + 2])
328
+
329
+ # The arguments forwarded as-is to the processor: the optional context
330
+ # followed by the slice store name, slice name and path. The recomputed
331
+ # previous_value sits right after them (at index offset + 3) and is
332
+ # dropped here, any further positional argument is forwarded.
333
+ forward_prefix = args[: offset + 3]
334
+ extra_args = args[offset + 4 :]
335
+
265
336
  # Get the value that is currently set in the slice
266
337
  previous_value = get_slice_attribute(store_name, name, path)
267
338
 
@@ -277,17 +348,19 @@ def attribute_processor[F: AttributeProcessorFunction](func: F) -> F:
277
348
  # We can not modify a deleted slice, stick to the previous value
278
349
  return previous_value
279
350
 
280
- # Call the processor and set the new value in the slice
351
+ # Call the processor and set the new value in the slice. The processor
352
+ # is called dynamically: depending on `expects_context`, the forwarded
353
+ # arguments either start with the injected context or directly with the
354
+ # slice store name.
355
+ processor: typing.Callable[..., object] = func
281
356
  return update_slice_attribute(
282
357
  store_name,
283
358
  name,
284
359
  path,
285
- func(
286
- store_name,
287
- name,
288
- path,
360
+ processor(
361
+ *forward_prefix,
289
362
  previous_value,
290
- *args,
363
+ *extra_args,
291
364
  **kwargs,
292
365
  ),
293
366
  )
@@ -20,7 +20,9 @@ import itertools
20
20
  import typing
21
21
  from collections.abc import Collection, Iterator, Mapping
22
22
 
23
- from inmanta.plugins import ModelType, plugin
23
+ import inmanta_plugins.config
24
+
25
+ from inmanta.plugins import Context, ModelType, plugin
24
26
  from inmanta.util import dict_path
25
27
  from inmanta_plugins.git_ops import Slice, attribute_processor, store
26
28
 
@@ -178,3 +180,39 @@ def simple_value(
178
180
  return value
179
181
  else:
180
182
  return previous_value
183
+
184
+
185
+ @attribute_processor
186
+ def get_template_value(
187
+ context: Context,
188
+ store_name: str,
189
+ name: str,
190
+ path: str,
191
+ previous_value: object | None = None,
192
+ **kwargs: object,
193
+ ) -> object:
194
+ """
195
+ Attribute processor counterpart of the config::get_template_value plugin.
196
+ The value currently stored in the slice is treated as a potential template
197
+ path: if it resolves to a jinja (`.j2`) file, the template is rendered (with
198
+ access to the extra kwargs and to all the compiler plugins as filters) and
199
+ the result is saved back into the slice. Otherwise the value is kept as is.
200
+
201
+ The compiler context is required to render the template and is passed
202
+ automatically as the first positional argument.
203
+
204
+ :param context: The compiler context, automatically injected.
205
+ :param store_name: The name of the slice store in which the slice is.
206
+ :param name: The name of the slice.
207
+ :param path: The path within the slice's attributes towards the value that
208
+ should be processed.
209
+ :param previous_value: The value currently stored in the slice for the given
210
+ attribute.
211
+ :param kwargs: Any value that should be accessible to the template.
212
+ """
213
+ return inmanta_plugins.config.get_template_value(
214
+ context,
215
+ {"value": previous_value},
216
+ "value",
217
+ **kwargs,
218
+ )
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = inmanta-module-git-ops
3
- version = 0.6.0
3
+ version = 0.7.0
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
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = inmanta-module-git-ops
3
- version = 0.6.0
3
+ version = 0.7.0
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
@@ -16,12 +16,17 @@ limitations under the License.
16
16
  Contact: edvgui@gmail.com
17
17
  """
18
18
 
19
+ import pathlib
20
+
19
21
  import pytest
20
22
  import yaml
21
23
  from inmanta_plugins.example.slices import recursive
24
+ from inmanta_plugins.example.slices.recursive import EmbeddedSlice, Slice
22
25
  from pytest_inmanta.plugin import Project
23
26
 
24
- from inmanta_plugins.git_ops import const, processors
27
+ from inmanta.plugins import Context
28
+ from inmanta_plugins.git_ops import attribute_processor, const, processors
29
+ from inmanta_plugins.git_ops.store import SliceStore
25
30
 
26
31
 
27
32
  def test_fs(project: Project, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -93,3 +98,69 @@ def test_fs(project: Project, monkeypatch: pytest.MonkeyPatch) -> None:
93
98
  ),
94
99
  )()
95
100
  ) == {1, 2}
101
+
102
+
103
+ def test_get_template_value(
104
+ project: Project, tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch
105
+ ) -> None:
106
+ # Define a basic store
107
+ store = SliceStore(
108
+ name="test_template",
109
+ folder="file://" + str(tmp_path / "test"),
110
+ schema=Slice,
111
+ )
112
+
113
+ # A jinja template that the processor should render, using a value passed
114
+ # to it as keyword argument
115
+ template = tmp_path / "greeting.j2"
116
+ template.write_text("Hello {{ who }}")
117
+
118
+ model = """
119
+ import git_ops
120
+ import git_ops::processors
121
+
122
+ for slice in git_ops::unroll_slices("test_template"):
123
+ git_ops::processors::get_template_value(
124
+ slice["store_name"],
125
+ slice["name"],
126
+ "description",
127
+ who="world",
128
+ )
129
+ end
130
+ """
131
+
132
+ # Add one slice whose description points to the template
133
+ s1_obj = Slice(
134
+ name="a",
135
+ description="file://" + str(template),
136
+ embedded_required=EmbeddedSlice(
137
+ name="aa",
138
+ ),
139
+ )
140
+ s1 = store.source_path / "s1.yaml"
141
+ s1.parent.mkdir(parents=True, exist_ok=True)
142
+ s1.write_text(yaml.safe_dump(s1_obj.model_dump(mode="json")))
143
+
144
+ # The processor needs the compiler context to render the template, it should
145
+ # be passed automatically as first positional argument
146
+ with monkeypatch.context() as ctx:
147
+ ctx.setattr(const, "COMPILE_MODE", const.COMPILE_UPDATE)
148
+ project.compile(model, no_dedent=False)
149
+
150
+ # The template path should have been rendered and saved back in the slice
151
+ assert yaml.safe_load(s1.read_text())["description"] == "Hello world"
152
+
153
+
154
+ def test_context_must_be_first_positional() -> None:
155
+ # A Context argument is only supported as the first positional argument
156
+ with pytest.raises(ValueError, match="first positional argument"):
157
+
158
+ @attribute_processor
159
+ def misplaced_context(
160
+ store_name: str,
161
+ name: str,
162
+ path: str,
163
+ context: Context,
164
+ previous_value: object | None = None,
165
+ ) -> object:
166
+ return previous_value