toml-combine 0.2.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

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.
toml_combine/combiner.py CHANGED
@@ -4,7 +4,7 @@ import copy
4
4
  import dataclasses
5
5
  from collections.abc import Mapping, Sequence
6
6
  from functools import partial
7
- from typing import Any
7
+ from typing import Any, TypeVar
8
8
 
9
9
  from . import exceptions
10
10
 
@@ -89,7 +89,10 @@ def override_sort_key(
89
89
  return tuple(result)
90
90
 
91
91
 
92
- def merge_configs(a: Any, b: Any, /) -> Any:
92
+ T = TypeVar("T", dict, list, str, int, float, bool)
93
+
94
+
95
+ def merge_configs(a: T, b: T, /) -> T:
93
96
  """
94
97
  Recursively merge two configuration dictionaries, with b taking precedence.
95
98
  """
@@ -100,7 +103,7 @@ def merge_configs(a: Any, b: Any, /) -> Any:
100
103
  return b
101
104
 
102
105
  result = a.copy()
103
- for key, b_value in b.items():
106
+ for key, b_value in b.items(): # type: ignore
104
107
  if a_value := a.get(key):
105
108
  result[key] = merge_configs(a_value, b_value)
106
109
  else:
@@ -183,4 +186,4 @@ def generate_for_mapping(
183
186
  if mapping_matches_override(mapping=mapping, override=override):
184
187
  result = merge_configs(result, override.config)
185
188
 
186
- return {"dimensions": mapping, **result}
189
+ return result
toml_combine/toml.py CHANGED
@@ -22,6 +22,6 @@ def dumps(config: dict) -> str:
22
22
  # features. The easiest way to turn tomlkit objects into plain dicts and strings
23
23
  # is through a json round-trip.
24
24
  try:
25
- return tomlkit.dumps(json.loads(json.dumps(config)))
25
+ return tomlkit.dumps(json.loads(json.dumps(config)), sort_keys=False)
26
26
  except tomlkit.exceptions.TOMLKitError as e:
27
27
  raise exceptions.TomlEncodeError from e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toml-combine
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: A tool for combining complex configurations in TOML format.
5
5
  Author-email: Joachim Jablon <ewjoachim@gmail.com>
6
6
  License-Expression: MIT
@@ -131,8 +131,7 @@ list and use that name as a key. Also, yes, you'll loose ordering.
131
131
  When you call the tool either with the CLI or the lib (see both below), you will have to
132
132
  provide a mapping of the desired dimentions. These values will be compared to overrides
133
133
  to apply overrides when relevant. It's ok to omit some dimensions, corresponding
134
- overrides won't be selected. The mapping you pass is also returned in the output as a
135
- dict under the `dimensions` key.
134
+ overrides won't be selected.
136
135
 
137
136
  By default, the output is `toml` though you can switch to `json` with `--format=json`
138
137
 
@@ -160,7 +159,6 @@ result = toml_combine.combine(config_file=config_file, environment="staging")
160
159
 
161
160
  print(result)
162
161
  {
163
- "dimensions": {"environment": "staging"},
164
162
  "fruits": {"apple": {"color": "red"}, "orange": {"color": "orange"}}
165
163
  }
166
164
  ```
@@ -203,13 +201,10 @@ container.env.ENABLE_EXPENSIVE_MONITORING = false
203
201
  This produces the following configs:
204
202
 
205
203
  ```console
206
- $ uv run toml-combine example.toml --environment=production --service=frontend
204
+ $ toml-combine example.toml --environment=production --service=frontend
207
205
  registry = "gcr.io/my-project/"
208
206
  service_account = "my-service-account"
209
207
  name = "service-frontend"
210
- [dimensions]
211
- environment = "production"
212
- service = "frontend"
213
208
 
214
209
  [container]
215
210
  image_name = "my-image-frontend"
@@ -220,9 +215,6 @@ $ toml-combine example.toml --environment=production --service=backend
220
215
  registry = "gcr.io/my-project/"
221
216
  service_account = "my-service-account"
222
217
  name = "service-backend"
223
- [dimensions]
224
- environment = "production"
225
- service = "backend"
226
218
 
227
219
  [container]
228
220
  image_name = "my-image-backend"
@@ -234,9 +226,6 @@ $ toml-combine example.toml --environment=staging --service=frontend
234
226
  registry = "gcr.io/my-project/"
235
227
  service_account = "my-service-account"
236
228
  name = "service-frontend"
237
- [dimensions]
238
- environment = "staging"
239
- service = "frontend"
240
229
 
241
230
  [container]
242
231
  image_name = "my-image-frontend"
@@ -247,9 +236,6 @@ $ toml-combine example.toml --environment=staging --service=backend
247
236
  registry = "gcr.io/my-project/"
248
237
  service_account = "my-service-account"
249
238
  name = "service-backend"
250
- [dimensions]
251
- environment = "staging"
252
- service = "backend"
253
239
 
254
240
  [container]
255
241
  image_name = "my-image-backend"
@@ -264,9 +250,6 @@ $ toml-combine example.toml --environment=dev --service=backend
264
250
  registry = "gcr.io/my-project/"
265
251
  service_account = "my-service-account"
266
252
  name = "service-backend"
267
- [dimensions]
268
- environment = "dev"
269
- service = "backend"
270
253
 
271
254
  [container]
272
255
  image_name = "my-image-backend"
@@ -1,11 +1,11 @@
1
1
  toml_combine/__init__.py,sha256=TDkOwwEM-nS6hOh79u9Qae6g2Q6VfANpPpnKGfSgu80,84
2
2
  toml_combine/__main__.py,sha256=hmF8N8xX6UEApzbKTVZ-4E1HU5-rjgUkdXNLO-mF6vo,100
3
3
  toml_combine/cli.py,sha256=hG03eDKz7xU-ydJIa1kDuu6WlFzNS3GTMJ6zals9M9c,2843
4
- toml_combine/combiner.py,sha256=LLjBFNKz4sjwiyOM5hq9JaqvyNuogdzdyWJbGS5hpXs,5500
4
+ toml_combine/combiner.py,sha256=RhhCevncnVvxFYNywvtVWkVMpiqtF0mq_APjg76Tg4Q,5546
5
5
  toml_combine/exceptions.py,sha256=tAFTDRSg6d10bBruBhsasZXrNNgLTmr_nKfvIsRR_yU,991
6
6
  toml_combine/lib.py,sha256=Iw7F8SCyQMlhaqSD2vtnmM6jbnrgzCZeX0d-LTM3VVg,1683
7
- toml_combine/toml.py,sha256=hqWEdBQiM960uga_9A6gXRhWhT2gVZT8IiLRc3jkyT8,797
8
- toml_combine-0.2.0.dist-info/METADATA,sha256=tuHxaP5V3DhE0unQt-XOnsL_TmCrNGP3mpxrSLuk30E,7777
9
- toml_combine-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- toml_combine-0.2.0.dist-info/entry_points.txt,sha256=dXUQNom54uZt_7ylEG81iNYMamYpaFo9-ItcZJU6Uzc,58
11
- toml_combine-0.2.0.dist-info/RECORD,,
7
+ toml_combine/toml.py,sha256=iBV8xj0qWcvGp2AZaML8FCT3i2X9DL7iA6jd-wcP5Bc,814
8
+ toml_combine-0.4.0.dist-info/METADATA,sha256=WKLq2pGpPRwfLhdpBuqxoAtCwVKXipgcega_4GTl_r4,7347
9
+ toml_combine-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ toml_combine-0.4.0.dist-info/entry_points.txt,sha256=dXUQNom54uZt_7ylEG81iNYMamYpaFo9-ItcZJU6Uzc,58
11
+ toml_combine-0.4.0.dist-info/RECORD,,