yaml-quilt 0.1.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.
@@ -0,0 +1,3 @@
1
+ * text=auto eol=lf
2
+ *.{cmd,[cC][mM][dD]} text eol=crlf
3
+ *.{bat,[bB][aA][tT]} text eol=crlf
@@ -0,0 +1,7 @@
1
+ .vscode/
2
+ __pycache__/
3
+ .pytest_cache/
4
+ dist/
5
+ *.pyc
6
+ *.egg-info/
7
+ build/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Edwin Shen]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: yaml_quilt
3
+ Version: 0.1.0
4
+ Summary: A Python library that enables features such as inheritance, variables, and instantiation in YAML files.
5
+ Project-URL: Homepage, https://github.com/eshen2210/yaml_quilt
6
+ Project-URL: Issues, https://github.com/eshen2210/yaml_quilt/issues
7
+ Author-email: Edwin Shen <eshen2210@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.md
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.12
13
+ Description-Content-Type: text/markdown
14
+
15
+ # yaml_quilt
16
+
17
+ A Python library that enables inheritance, variables, and instantiation in YAML files via inline declarations.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install yaml_quilt
23
+ ```
24
+
25
+ ## Overview
26
+
27
+ YamlQuilt is a Python library that allows templating of YAML files using **inline declarations** and **depth-first search (DFS)** traversal. This is accomplished through three key features: **Variables**, **File Inheritance**, and **Declarative Rules**. These declaration rules include inheritance rules such as abstract, sealed, private, etc and variable replacement rules such as default, optional, global, etc. The DFS approach allows declarative rules to persist to child elements, even across inherited files.
28
+
29
+ YamlQuilt aims for yaml readability by avoiding {{ Helm-style }} templating and in-line programming logic. YamlQuilt's in-line declarations use a minimal format that always places declaration in the beginning of an element. YamlQuilt eliminates templating logic in Python and and calls YAML files the same way you would pyyaml's load():
30
+
31
+ ```python
32
+ import yaml
33
+ from yaml_quilt import stitch, YamlQuiltException
34
+
35
+ # Define variables in Python code
36
+ injected_variables = {
37
+ "<var1>": "value1"
38
+ }
39
+
40
+ # Process YAML with injected variables
41
+ try:
42
+ result = stitch(
43
+ file_path="root_config.yaml",
44
+ directory="/path/to/config",
45
+ Loader=yaml.SafeLoader,
46
+ variables=injected_variables
47
+ )
48
+ except YamlQuiltException as e:
49
+ print(f"Error: {e}")
50
+ ```
51
+
52
+ Processing behavior is defined within the Yaml file via in-line declarations.
53
+
54
+ ```yaml
55
+ # config.yaml
56
+ (patch): config_path/patch.yaml
57
+ (override) base_key1: <variable1>
58
+ ---
59
+ # patch.yaml
60
+ (abstract) base_key1:
61
+ base_key2: value2
62
+ ---
63
+ # yaml_quilt output
64
+ base_key1: value1
65
+ base_key2: value2
66
+ ```
67
+
68
+ ## Documentation
69
+
70
+ Full documentation is available at **https://eshen2210.github.io/yaml_quilt/**.
71
+
72
+ ## License
73
+
74
+ MIT License
@@ -0,0 +1,60 @@
1
+ # yaml_quilt
2
+
3
+ A Python library that enables inheritance, variables, and instantiation in YAML files via inline declarations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install yaml_quilt
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ YamlQuilt is a Python library that allows templating of YAML files using **inline declarations** and **depth-first search (DFS)** traversal. This is accomplished through three key features: **Variables**, **File Inheritance**, and **Declarative Rules**. These declaration rules include inheritance rules such as abstract, sealed, private, etc and variable replacement rules such as default, optional, global, etc. The DFS approach allows declarative rules to persist to child elements, even across inherited files.
14
+
15
+ YamlQuilt aims for yaml readability by avoiding {{ Helm-style }} templating and in-line programming logic. YamlQuilt's in-line declarations use a minimal format that always places declaration in the beginning of an element. YamlQuilt eliminates templating logic in Python and and calls YAML files the same way you would pyyaml's load():
16
+
17
+ ```python
18
+ import yaml
19
+ from yaml_quilt import stitch, YamlQuiltException
20
+
21
+ # Define variables in Python code
22
+ injected_variables = {
23
+ "<var1>": "value1"
24
+ }
25
+
26
+ # Process YAML with injected variables
27
+ try:
28
+ result = stitch(
29
+ file_path="root_config.yaml",
30
+ directory="/path/to/config",
31
+ Loader=yaml.SafeLoader,
32
+ variables=injected_variables
33
+ )
34
+ except YamlQuiltException as e:
35
+ print(f"Error: {e}")
36
+ ```
37
+
38
+ Processing behavior is defined within the Yaml file via in-line declarations.
39
+
40
+ ```yaml
41
+ # config.yaml
42
+ (patch): config_path/patch.yaml
43
+ (override) base_key1: <variable1>
44
+ ---
45
+ # patch.yaml
46
+ (abstract) base_key1:
47
+ base_key2: value2
48
+ ---
49
+ # yaml_quilt output
50
+ base_key1: value1
51
+ base_key2: value2
52
+ ```
53
+
54
+ ## Documentation
55
+
56
+ Full documentation is available at **https://eshen2210.github.io/yaml_quilt/**.
57
+
58
+ ## License
59
+
60
+ MIT License
@@ -0,0 +1,15 @@
1
+ # Exceptions
2
+
3
+ All exceptions raised by yaml_quilt use a base exception class: `YamlQuiltException`.
4
+
5
+ | Exception | Cause |
6
+ |-----------|-------|
7
+ | `NoOverrideException` | Tried to override a key without `(override)` |
8
+ | `AbstractKeyNotImplementedException` | Sub YAML did not implement an `(abstract)` key |
9
+ | `KeySealedException` | Attempted to override a `(sealed)` key or variable |
10
+ | `ConflictingDeclarationException` | Incompatible declarations applied together |
11
+ | `InvalidInstantiationException` | Bad `(patch)` structure |
12
+ | `CircularInheritanceException` | Cyclic `(patch)` references |
13
+ | `InvalidDeclarationException` | Declaration with incorrect key/value content or format |
14
+ | `MismatchedValueTypeException` | Declaration used with incorrect value type (e.g., `(append)` expects a list but received a dict) |
15
+ | `AmbiguousVariableException` | Overlapping variable keys detected in the same string |
@@ -0,0 +1,66 @@
1
+ # yaml_quilt
2
+
3
+ A Python library that enables inheritance, variables, and instantiation in YAML files via inline declarations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install yaml_quilt
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ YamlQuilt allows templating of YAML files using **inline declarations** and **depth-first search (DFS)** traversal, through three key features: **Variables**, **File Inheritance**, and **Declarative Rules**. The DFS approach allows declarative rules to persist to child elements, even across inherited files.
14
+
15
+ YamlQuilt aims for yaml readability by avoiding {{ Helm-style }} templating and in-line programming logic:
16
+
17
+ ```python
18
+ import yaml
19
+ from yaml_quilt import stitch, YamlQuiltException
20
+
21
+ try:
22
+ result = stitch(
23
+ file_path="root_config.yaml",
24
+ directory="/path/to/config",
25
+ Loader=yaml.SafeLoader,
26
+ variables={"<var1>": "value1"}
27
+ )
28
+ except YamlQuiltException as e:
29
+ print(f"Error: {e}")
30
+ ```
31
+
32
+ ```yaml
33
+ # config.yaml
34
+ (patch): config_path/patch.yaml
35
+ (override) base_key1: <variable1>
36
+ ---
37
+ # patch.yaml
38
+ (abstract) base_key1:
39
+ base_key2: value2
40
+ ---
41
+ # yaml_quilt output
42
+ base_key1: value1
43
+ base_key2: value2
44
+ ```
45
+
46
+ ## Logical Flow
47
+
48
+ 1. **Load YAML** into Python objects (dict/list/scalars) via PyYAML
49
+ 2. Convert **config-level declarations** (like `(override_file)`) into top-level key declarations
50
+ 3. Run **variable substitution** using DFS repeatedly until no more substitutions can occur
51
+ 4. Run **`(patch)` expansion** as a pre-pass: expand all `(patch)` nodes before processing other keys. For each expansion, repeat steps 1–4 and apply inheritance rules via DFS.
52
+ 5. Strip declaration markers from output keys / variable maps
53
+ 6. Return Python objects (dict/list/scalars)
54
+
55
+ ## Declaration Syntax
56
+
57
+ Declarations are inline prefixes. **Spacing matters** — always include a trailing space after the declaration:
58
+
59
+ ✅ `(override) key`
60
+ ❌ `(override)key`
61
+
62
+ Multiple declarations can be combined:
63
+
64
+ ```yaml
65
+ (override) (sealed) (optional) key: <variable1>_some_string_<variable2>
66
+ ```
@@ -0,0 +1,196 @@
1
+ # Inheritance
2
+
3
+ `(patch)` loads another YAML file and **inherits** it into the current node while preserving depth hierarchy.
4
+
5
+ ```yaml
6
+ (patch): path/to/base.yaml
7
+ ```
8
+
9
+ Inherit with variables:
10
+
11
+ ```yaml
12
+ (patch):
13
+ (path): path/to/base.yaml
14
+ (variables):
15
+ <name>: service_a
16
+ <port>: 8080
17
+ ```
18
+
19
+ Inherit multiple files (applied top to bottom):
20
+
21
+ ```yaml
22
+ (patch):
23
+ - path/to/base1.yaml
24
+ - path/to/base2.yaml
25
+ - (path): path/to/base3.yaml
26
+ (variables):
27
+ <name>: base_name3
28
+ ```
29
+
30
+ Variables are scoped locally to each YAML file unless `(global)` or `(carryover)` is used. `(variables)` in the sub YAML do not pass to base YAMLs, and `(variables)` declared within `(patch)` are scoped only to that base YAML.
31
+
32
+ Example:
33
+
34
+ ```yaml
35
+ # Sub YAML
36
+ (variables):
37
+ <name>: sub_name
38
+ sub_name: <name>
39
+ sub_key: sub_value
40
+ services:
41
+ base_service1:
42
+ (patch):
43
+ (path): path/to/base.yaml
44
+ (variables):
45
+ <name>: service_a
46
+ <port>: 8080
47
+ base_service2:
48
+ (patch):
49
+ (path): path/to/base.yaml
50
+ (variables):
51
+ <name>: service_b
52
+ <port>: 8080
53
+ ---
54
+ # Base YAML
55
+ base_name: <name>
56
+ base_port: <port>
57
+ ```
58
+
59
+ Renders to:
60
+
61
+ ```yaml
62
+ sub_name: sub_name
63
+ sub_key: sub_value
64
+ services:
65
+ base_service1:
66
+ base_name: service_a
67
+ base_port: 8080
68
+ base_service2:
69
+ base_name: service_b
70
+ base_port: 8080
71
+ ```
72
+
73
+ ---
74
+
75
+ ## `(override)`, `(abstract)`, `(sealed)`, `(private)`
76
+
77
+ These keywords modify the behavior of `(patch)` inheritance.
78
+
79
+ - `(override)`: When the same key exists in both sub and base, the sub value is used.
80
+ - `(abstract)`: The sub YAML must implement this key at the same depth, or `stitch()` throws `AbstractKeyNotImplementedException`.
81
+ - `(sealed)`: A sub key may not `(override)` this key, or `stitch()` throws `KeySealedException`.
82
+ - `(private)`: The key is deleted before the `(patch)` inheritance process.
83
+
84
+ These keywords persist to all child elements, including `(patch)` YAMLs within those child elements.
85
+
86
+ ```yaml
87
+ # Base YAML
88
+ (abstract) required_key:
89
+ (sealed) locked_key: base_locked
90
+ (private) internal_only: should_not_render
91
+ shared_key: base_shared
92
+ ```
93
+
94
+ ```yaml
95
+ # Sub YAML
96
+ (patch): base.yaml
97
+ required_key: provided_by_sub
98
+ # (override) locked_key: sub_locked # Would throw KeySealedException
99
+ (override) shared_key: sub_shared
100
+ ```
101
+
102
+ Renders to:
103
+
104
+ ```yaml
105
+ required_key: provided_by_sub
106
+ locked_key: base_locked
107
+ shared_key: sub_shared
108
+ ```
109
+
110
+ ---
111
+
112
+ ## `(append)`, `(prepend)`, `(merge)`
113
+
114
+ These keywords modify `(patch)` inheritance when both the sub and base values are sequences.
115
+
116
+ - `(append)`: Appends the sub sequence after the base sequence.
117
+ - `(prepend)`: Inserts the sub sequence before the base sequence.
118
+ - `(merge)`: Each index of the sub sequence applies inheritance rules against the matching index of the base sequence.
119
+
120
+ These keywords **do not persist** to child elements and only apply to matching keys at the same depth. If either value is not a sequence, `stitch()` throws `MismatchedValueTypeException`.
121
+
122
+ ```yaml
123
+ # Base YAML
124
+ append_key:
125
+ - base_key3: data3
126
+ - base_key4: data4
127
+ prepend_key:
128
+ - base_key3: data3
129
+ - base_key4: data4
130
+ merge_key:
131
+ - base_key3: data3
132
+ - base_key4: data4
133
+ override_key:
134
+ - base_key3: data3
135
+ - base_key4: data4
136
+ ---
137
+ # Sub YAML
138
+ (patch): path/to/base.yaml
139
+ (append) append_key:
140
+ - sub_key1: data1
141
+ - sub_key2: data2
142
+ (prepend) prepend_key:
143
+ - sub_key1: data1
144
+ - sub_key2: data2
145
+ (merge) merge_key:
146
+ - sub_key1: data1
147
+ (override) base_key3: overriden_data
148
+ - sub_key2: data2
149
+ (override) override_key:
150
+ - sub_key1: data1
151
+ - sub_key2: data2
152
+ ```
153
+
154
+ Renders to:
155
+
156
+ ```yaml
157
+ append_key:
158
+ - base_key3: data3
159
+ - base_key4: data4
160
+ - sub_key1: data1
161
+ - sub_key2: data2
162
+ prepend_key:
163
+ - sub_key1: data1
164
+ - sub_key2: data2
165
+ - base_key3: data3
166
+ - base_key4: data4
167
+ merge_key:
168
+ - sub_key1: data1
169
+ base_key3: overriden_data
170
+ - sub_key2: data2
171
+ base_key4: data4
172
+ override_key:
173
+ - sub_key1: data1
174
+ - sub_key2: data2
175
+ ```
176
+
177
+ ---
178
+
179
+ ## File-wide Keywords: `(abstract_file)`, `(sealed_file)`, `(override_file)`
180
+
181
+ File keywords apply a keyword to every top-level key in the file.
182
+
183
+ ```yaml
184
+ (abstract_file)
185
+ abstract_key1: must_be_implemented
186
+ abstract_subkey: must_be_implemented
187
+ abstract_key2: must_be_implemented
188
+ ```
189
+
190
+ Is equivalent to:
191
+
192
+ ```yaml
193
+ (abstract) abstract_key1: must_be_implemented
194
+ abstract_subkey: must_be_implemented # Also abstract — abstract persists to child elements
195
+ (abstract) abstract_key2: must_be_implemented
196
+ ```