annet 3.17.0__py3-none-any.whl → 3.18.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.

Potentially problematic release.


This version of annet might be problematic. Click here for more details.

annet/annlib/jsontools.py CHANGED
@@ -6,13 +6,16 @@ import json
6
6
  from collections.abc import Mapping, Sequence
7
7
  from itertools import starmap
8
8
  from operator import itemgetter
9
- from typing import Any, Dict, Iterable, List, Optional
9
+ from typing import Any, Dict, Final, Iterable, List, Optional
10
10
 
11
11
  import jsonpatch
12
12
  import jsonpointer
13
13
  from ordered_set import OrderedSet
14
14
 
15
15
 
16
+ EVERYTHING_ACL: Final = "/*"
17
+
18
+
16
19
  def format_json(data: Any, stable: bool = False) -> str:
17
20
  """Serialize to json."""
18
21
  return json.dumps(data, indent=4, ensure_ascii=False, sort_keys=not stable) + "\n"
@@ -21,14 +24,17 @@ def format_json(data: Any, stable: bool = False) -> str:
21
24
  def apply_json_fragment(
22
25
  old: Dict[str, Any],
23
26
  new_fragment: Dict[str, Any], *,
24
- acl: Sequence[str],
27
+ acl: Sequence[str] | None = None,
25
28
  filters: Sequence[str] | None = None,
26
29
  ) -> Dict[str, Any]:
27
30
  """
28
- Replace parts of the old document with 'new_fragment' using ACL restrictions.
31
+ Replace parts of the old document with 'new_fragment'.
32
+ If `acl` is not `None`, replacement will only be made within specified keys.
29
33
  If `filter` is not `None`, only those parts which also matches at least one filter
30
34
  from the list will be modified (updated or deleted).
31
35
  """
36
+ if acl is None:
37
+ acl = [EVERYTHING_ACL]
32
38
  full_new_config = copy.deepcopy(old)
33
39
  for acl_item in acl:
34
40
  new_pointers = _resolve_json_pointers(acl_item, new_fragment)
@@ -91,7 +97,23 @@ def _pointer_set(pointer: jsonpointer.JsonPointer, doc: Any, value: Any) -> None
91
97
 
92
98
  def make_patch(old: Dict[str, Any], new: Dict[str, Any]) -> List[Dict[str, Any]]:
93
99
  """Generate a JSON patch by comparing the old document with the new one."""
94
- return sorted(jsonpatch.make_patch(old, new).patch, key=itemgetter("path"))
100
+ # NOTE: changing order of the patch operations (e.g. sorting)
101
+ # may interfere with the `move` logic.
102
+ # E.g.:
103
+ # ```python
104
+ # old = [["a", "b"], ["c", "d"]]
105
+ # new = [["d", "c"], ["b", "a"]]
106
+ # ```
107
+ # produces the following patch:
108
+ # ```json
109
+ # [{"op": "move", "path": "/0/0", "from": "/1/0"},
110
+ # {"op": "move", "path": "/1/0", "from": "/0/2"},
111
+ # {"op": "move", "path": "/0/0", "from": "/1/1"},
112
+ # {"op": "move", "path": "/1/1", "from": "/0/2"}]
113
+ # ```
114
+ # which relies on proper ordering to be correctly applied.
115
+ # See https://github.com/annetutil/annet/pull/452 for details.
116
+ return jsonpatch.make_patch(old, new).patch
95
117
 
96
118
 
97
119
  def apply_patch(content: Optional[bytes], patch_bytes: bytes) -> bytes:
annet/gen.py CHANGED
@@ -267,11 +267,20 @@ def _old_new_per_device(ctx: OldNewDeviceContext, device: Device, filterer: Filt
267
267
  filters = filters_text.removesuffix("\n").split("\n")
268
268
 
269
269
  old_json_fragment_files = old_files.json_fragment_files.copy()
270
- new_json_fragment_files = res.new_json_fragment_files(old_json_fragment_files, filters=filters)
270
+ new_json_fragment_files = res.new_json_fragment_files(
271
+ old_json_fragment_files,
272
+ use_acl=not ctx.args.no_acl,
273
+ filters=filters,
274
+ )
271
275
 
272
276
  if ctx.args.acl_safe:
273
277
  safe_new_files = res.new_files(safe=True)
274
- safe_new_json_fragment_files = res.new_json_fragment_files(old_json_fragment_files, safe=True, filters=filters)
278
+ safe_new_json_fragment_files = res.new_json_fragment_files(
279
+ old_json_fragment_files,
280
+ use_acl=not ctx.args.no_acl,
281
+ safe=True,
282
+ filters=filters,
283
+ )
275
284
 
276
285
  if ctx.args.profile:
277
286
  perf = res.perf_mesures()
@@ -85,6 +85,7 @@ class RunGeneratorResult:
85
85
  def new_json_fragment_files(
86
86
  self,
87
87
  old_files: Dict[str, Optional[str]],
88
+ use_acl: bool = True,
88
89
  safe: bool = False,
89
90
  filters: Sequence[str] | None = None,
90
91
  ) -> Dict[str, Tuple[Any, Optional[str]]]:
@@ -98,9 +99,12 @@ class RunGeneratorResult:
98
99
  files[filepath] = (old_files[filepath], None)
99
100
  else:
100
101
  files[filepath] = ({}, None)
101
- result_acl = generator_result.acl
102
- if safe:
103
- result_acl = generator_result.acl_safe
102
+ if use_acl:
103
+ result_acl = generator_result.acl
104
+ if safe:
105
+ result_acl = generator_result.acl_safe
106
+ else:
107
+ result_acl = None
104
108
  previous_config: Dict[str, Any] = files[filepath][0]
105
109
  new_fragment = generator_result.config
106
110
  new_config = jsontools.apply_json_fragment(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: annet
3
- Version: 3.17.0
3
+ Version: 3.18.0
4
4
  Summary: annet
5
5
  Home-page: https://github.com/annetutil/annet
6
6
  License: MIT
@@ -9,7 +9,7 @@ annet/deploy.py,sha256=toIaR2QLvLJxpdeXoJhZzKdXfhn784ciTNZlMGT9huo,7709
9
9
  annet/deploy_ui.py,sha256=XsN1i7E9cNp1SAf1YBwhEBuwN91MvlNMSrLhnQrumA8,28672
10
10
  annet/diff.py,sha256=kD_2kxz5wc2TP10xj-BHs6IPq1yNKkXxIco8czjeC6M,9497
11
11
  annet/filtering.py,sha256=ZtqxPsKdV9reZoRxtQyBg22BqyMqd-2SotYcxZ-68AQ,903
12
- annet/gen.py,sha256=yDEXyilu_FSBu4pzWW4dFX4tAF6Kb_GtXdTd8QCU2mI,30668
12
+ annet/gen.py,sha256=LyoKx_bQLBL0N0TeP368HXl27UVZ_s_Q-PjRsbLtDzc,30852
13
13
  annet/hardware.py,sha256=O2uadehcavZ10ssPr-db3XYHK8cpbG7C7XFkO-I6r_s,1161
14
14
  annet/implicit.py,sha256=yDYiCIx9dNhynoVsROZPhFp6YCLNx-Zmm6IkERwjDGw,6858
15
15
  annet/lib.py,sha256=4N4X6jCCrig5rk7Ua4AofrV9zK9jhzkBq57fLsfBJjw,4812
@@ -55,7 +55,7 @@ annet/annlib/command.py,sha256=GsgzQ8oFiHFan1Tfyo340rWgfhyU4_sCKJGhBm2jG6Y,1258
55
55
  annet/annlib/diff.py,sha256=MZ6eQAU3cadQp8KaSE6uAYFtcfMDCIe_eNuVROnYkCk,4496
56
56
  annet/annlib/errors.py,sha256=jBcSFzY6Vj-FxR__vqjFm-87AwYQ0xHuAopTirii5AU,287
57
57
  annet/annlib/filter_acl.py,sha256=ZJvNpSwE5MzJS_sKLenQpZgTuM-IrngwcbukQRq90do,7195
58
- annet/annlib/jsontools.py,sha256=H9O-NM1Ix8okD3QOiTppfzkODKVTqQeE3FvBMuAiMiU,7441
58
+ annet/annlib/jsontools.py,sha256=iHSLuewc1GmDmImjruNOSONi71hUQG2_Uqm996L0poI,8216
59
59
  annet/annlib/lib.py,sha256=lxmYrbeablFMhFtvFmADVpVShSFi9TN4gNWaBs_Ygm0,14952
60
60
  annet/annlib/output.py,sha256=g8d_LyNg5snywt0iPQuL9OFpoxKMdN59VW-vcrKitTQ,7674
61
61
  annet/annlib/patching.py,sha256=1bxlLDRx15GjB6aNk6kAx7t3WPPLHffYvSy7VLGnCig,21506
@@ -86,7 +86,7 @@ annet/generators/jsonfragment.py,sha256=Cl43t9_OtNWRxesk3B69h60KvD37tiK9W7sLLmpp
86
86
  annet/generators/partial.py,sha256=XI01KDA--XwjSEU33SOQCCJZRXFq5boRz1uJA8lVA1g,3502
87
87
  annet/generators/perf.py,sha256=IaAcfEVtX7UNO11VOCXzp-FPj_tOx_CDQ34HGThCn4c,2225
88
88
  annet/generators/ref.py,sha256=QVdeL8po1D0kBsVLOpCjFR81D8yNTk-kaQj5WUM4hng,438
89
- annet/generators/result.py,sha256=8fBfKQ7vWi9DlGOUFYz0y47UlCI1gTqix3riX2CgQng,5065
89
+ annet/generators/result.py,sha256=YFXKWHzTyNweF2ioVpKiH3IVSw475qLsqJPsCToWFFE,5187
90
90
  annet/generators/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
91
  annet/generators/common/initial.py,sha256=qYBxXFhyOPy34cxc6hsIXseod-lYCmmbuNHpM0uteY0,1244
92
92
  annet/mesh/__init__.py,sha256=lcgdnBIxc2MAN7Er1bcErEKPqrjWO4uIp_1FldMXTYg,557
@@ -208,8 +208,8 @@ annet/vendors/library/optixtrans.py,sha256=VdME69Ca4HAEgoaKN21fZxnmmsqqaxOe_HZja
208
208
  annet/vendors/library/pc.py,sha256=vfv31_NPi7M-4AUDL89UcpawK2E6xvCpELA209cd1ho,1086
209
209
  annet/vendors/library/ribbon.py,sha256=DDOBq-_-FL9dCxqXs2inEWZ-pvw-dJ-A-prA7cKMhec,1216
210
210
  annet/vendors/library/routeros.py,sha256=iQa7m_4wjuvcgBOI9gyZwlw1BvzJfOkvUbyoEk-NI9I,1254
211
- annet-3.17.0.dist-info/licenses/AUTHORS,sha256=rh3w5P6gEgqmuC-bw-HB68vBCr-yIBFhVL0PG4hguLs,878
212
- annet-3.17.0.dist-info/licenses/LICENSE,sha256=yPxl7dno02Pw7gAcFPIFONzx_gapwDoPXsIsh6Y7lC0,1079
211
+ annet-3.18.0.dist-info/licenses/AUTHORS,sha256=rh3w5P6gEgqmuC-bw-HB68vBCr-yIBFhVL0PG4hguLs,878
212
+ annet-3.18.0.dist-info/licenses/LICENSE,sha256=yPxl7dno02Pw7gAcFPIFONzx_gapwDoPXsIsh6Y7lC0,1079
213
213
  annet_generators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
214
214
  annet_generators/example/__init__.py,sha256=OJ77uj8axc-FIyIu_Xdcnzmde3oQW5mk5qbODkhuVc8,355
215
215
  annet_generators/example/hostname.py,sha256=RloLzNVetEoWPLITzfJ13Nk3CC0yi-cZB1RTd6dnuhI,2541
@@ -222,8 +222,8 @@ annet_generators/rpl_example/generator.py,sha256=EWah19gOH8G-QyNyWqxCqdRi0BK7GbM
222
222
  annet_generators/rpl_example/items.py,sha256=HPgxScDvSqJPdz0c2SppDrH82DZYC4zUaniQwcWmh4A,1176
223
223
  annet_generators/rpl_example/mesh.py,sha256=z_WgfDZZ4xnyh3cSf75igyH09hGvtexEVwy1gCD_DzA,288
224
224
  annet_generators/rpl_example/route_policy.py,sha256=z6nPb0VDeQtKD1NIg9sFvmUxBD5tVs2frfNIuKdM-5c,2318
225
- annet-3.17.0.dist-info/METADATA,sha256=C87PBTHYS5svy-j2qCf-0TBBtFM0jbbB7FcQ1cvzg-0,850
226
- annet-3.17.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
227
- annet-3.17.0.dist-info/entry_points.txt,sha256=5lIaDGlGi3l6QQ2ry2jZaqViP5Lvt8AmsegdD0Uznck,192
228
- annet-3.17.0.dist-info/top_level.txt,sha256=QsoTZBsUtwp_FEcmRwuN8QITBmLOZFqjssRfKilGbP8,23
229
- annet-3.17.0.dist-info/RECORD,,
225
+ annet-3.18.0.dist-info/METADATA,sha256=BzSwXAELrXMy0FfrX33OkF9h-iiKfXkeIKAroB_Z9D4,850
226
+ annet-3.18.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
227
+ annet-3.18.0.dist-info/entry_points.txt,sha256=5lIaDGlGi3l6QQ2ry2jZaqViP5Lvt8AmsegdD0Uznck,192
228
+ annet-3.18.0.dist-info/top_level.txt,sha256=QsoTZBsUtwp_FEcmRwuN8QITBmLOZFqjssRfKilGbP8,23
229
+ annet-3.18.0.dist-info/RECORD,,
File without changes