zpp_config 2.2.2__tar.gz → 2.2.4__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 (29) hide show
  1. {zpp_config-2.2.2/zpp_config.egg-info → zpp_config-2.2.4}/PKG-INFO +8 -1
  2. {zpp_config-2.2.2 → zpp_config-2.2.4}/README.md +7 -0
  3. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/config.py +45 -7
  4. {zpp_config-2.2.2 → zpp_config-2.2.4/zpp_config.egg-info}/PKG-INFO +8 -1
  5. {zpp_config-2.2.2 → zpp_config-2.2.4}/LICENSE +0 -0
  6. {zpp_config-2.2.2 → zpp_config-2.2.4}/setup.cfg +0 -0
  7. {zpp_config-2.2.2 → zpp_config-2.2.4}/tests/test_access.py +0 -0
  8. {zpp_config-2.2.2 → zpp_config-2.2.4}/tests/test_backends.py +0 -0
  9. {zpp_config-2.2.2 → zpp_config-2.2.4}/tests/test_merge_update_delete.py +0 -0
  10. {zpp_config-2.2.2 → zpp_config-2.2.4}/tests/test_validation.py +0 -0
  11. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/__init__.py +0 -0
  12. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/__init__.py +0 -0
  13. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/cfg.py +0 -0
  14. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/global_backend.py +0 -0
  15. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/ini.py +0 -0
  16. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/json.py +0 -0
  17. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/toml.py +0 -0
  18. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/backend/yaml.py +0 -0
  19. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/cli.py +0 -0
  20. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/core/__init__.py +0 -0
  21. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/core/autoreload.py +0 -0
  22. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/core/logs.py +0 -0
  23. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/core/vault.py +0 -0
  24. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config/core/vault_encryption.py +0 -0
  25. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config.egg-info/SOURCES.txt +0 -0
  26. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config.egg-info/dependency_links.txt +0 -0
  27. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config.egg-info/entry_points.txt +0 -0
  28. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config.egg-info/requires.txt +0 -0
  29. {zpp_config-2.2.2 → zpp_config-2.2.4}/zpp_config.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zpp_config
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
4
  Summary: Module pour le chargement et la modification de fichier de configuration
5
5
  Home-page: https://github.com/ZephyrOff/zpp_config
6
6
  Author:
@@ -71,10 +71,15 @@ Le backend est automatiquement choisi selon l’extension du fichier, mais il es
71
71
  Lors de l'initialisation, il est également possible de définir plusieurs paramètres qui seront utile pour le render Jinja.
72
72
 
73
73
  **context**: défini un dictionnaire contenant les variables Jinja
74
+
74
75
  **vault_file**: emplacement du fichier vault
76
+
75
77
  **vault_keyfile**: emplacement du fichier contenant le mot de passe du vault
78
+
76
79
  **vault_password**: mot de passe du vault
80
+
77
81
  **vault_encryption_keyfile**: emplacement du fichier contenant le mot de passe du vault_encryption
82
+
78
83
  **vault_encryption_password**: mot de passe du vault_encryption
79
84
 
80
85
  ```python
@@ -144,6 +149,8 @@ db_host = config["db.host"]
144
149
  ```python
145
150
  db_host = config.get("db.host", default="127.0.0.1")
146
151
  ```
152
+ Par défaut, la méthode get va renvoyer un ConfigNode, mais il est possible de forcer l'envoi d'un dict brut avec dict_strict=True
153
+
147
154
  #### Itération
148
155
  ```python
149
156
  for key, sub in config.db.items():
@@ -32,10 +32,15 @@ Le backend est automatiquement choisi selon l’extension du fichier, mais il es
32
32
  Lors de l'initialisation, il est également possible de définir plusieurs paramètres qui seront utile pour le render Jinja.
33
33
 
34
34
  **context**: défini un dictionnaire contenant les variables Jinja
35
+
35
36
  **vault_file**: emplacement du fichier vault
37
+
36
38
  **vault_keyfile**: emplacement du fichier contenant le mot de passe du vault
39
+
37
40
  **vault_password**: mot de passe du vault
41
+
38
42
  **vault_encryption_keyfile**: emplacement du fichier contenant le mot de passe du vault_encryption
43
+
39
44
  **vault_encryption_password**: mot de passe du vault_encryption
40
45
 
41
46
  ```python
@@ -105,6 +110,8 @@ db_host = config["db.host"]
105
110
  ```python
106
111
  db_host = config.get("db.host", default="127.0.0.1")
107
112
  ```
113
+ Par défaut, la méthode get va renvoyer un ConfigNode, mais il est possible de forcer l'envoi d'un dict brut avec dict_strict=True
114
+
108
115
  #### Itération
109
116
  ```python
110
117
  for key, sub in config.db.items():
@@ -1,6 +1,7 @@
1
1
  import impmagic
2
2
  from jinja2 import FileSystemLoader
3
3
  from pathlib import Path
4
+ import copy
4
5
 
5
6
  class ValidationError(Exception):
6
7
  pass
@@ -111,7 +112,10 @@ class ConfigNode:
111
112
  val = self._get_value()
112
113
  if isinstance(val, dict):
113
114
  for k, v in val.items():
114
- yield k, ConfigNode(self._config or self, f"{self._full_path(k)}")
115
+ if isinstance(v, dict):
116
+ yield k, ConfigNode(self._config or self, self._full_path(k))
117
+ else:
118
+ yield k, v
115
119
 
116
120
  def keys(self):
117
121
  # autoload
@@ -129,7 +133,7 @@ class ConfigNode:
129
133
  for k in val:
130
134
  yield ConfigNode(self._config or self, f"{self._full_path(k)}")
131
135
 
132
- def get(self, path, default=None, strict: bool = False):
136
+ def get(self, path, default=None, strict=False, dict_strict=False):
133
137
  # autoload
134
138
  object.__getattribute__(self, "_autoload")()
135
139
 
@@ -141,6 +145,11 @@ class ConfigNode:
141
145
  raise KeyError(path)
142
146
  return default
143
147
  node = node[k]
148
+
149
+ if not dict_strict:
150
+ if isinstance(node, dict):
151
+ return ConfigNode(self._config or self, self._full_path(path))
152
+
144
153
  return node
145
154
 
146
155
  def set(self, path, value):
@@ -350,6 +359,18 @@ class ConfigNode:
350
359
 
351
360
  self.delete(path)
352
361
 
362
+ def __len__(self):
363
+ object.__getattribute__(self, "_autoload")()
364
+
365
+ val = self._get_value()
366
+ return len(val) if isinstance(val, dict) else 0
367
+
368
+ def copy(self):
369
+ object.__getattribute__(self, "_autoload")()
370
+
371
+ data = copy.deepcopy(self.to_dict())
372
+ return ConfigNode(config=None, path="", _data=data)
373
+
353
374
 
354
375
  class Config(ConfigNode):
355
376
  @impmagic.loader(
@@ -363,7 +384,7 @@ class Config(ConfigNode):
363
384
  {'module':'jinja2', 'submodule': ['Environment']},
364
385
  {'module':'zpp_config.core.vault_encryption', 'submodule': ['vault_decrypt']},
365
386
  )
366
- def __init__(self, filename, filetype=None, context=None, vault_file=None, vault_keyfile=None, vault_password=None, vault_encryption_keyfile=None, vault_encryption_password=None):
387
+ def __init__(self, filename, filetype=None, context=None, vault_file=None, vault_keyfile=None, vault_password=None, vault_encryption_keyfile=None, vault_encryption_password=None, disable_jinja_render=False):
367
388
  self._filename = Path(filename)
368
389
  self._context = context or {}
369
390
 
@@ -383,6 +404,7 @@ class Config(ConfigNode):
383
404
  loader=SafeFileSystemLoader(self._filename.parent),
384
405
  autoescape=False
385
406
  )
407
+ self._disable_jinja_render = disable_jinja_render
386
408
 
387
409
  # Fonction pour récupérer une clé dans un vault
388
410
  def vault(key):
@@ -440,18 +462,34 @@ class Config(ConfigNode):
440
462
  self._loaded = False
441
463
  super().__init__(path="", _data={})
442
464
 
465
+ def _read_source(self):
466
+ """
467
+ Read file content using the Jinja loader logic
468
+ (handles UTF-8 + Windows cp1252 fallback).
469
+ """
470
+ # On passe volontairement par le loader Jinja
471
+ source, _, _ = self._env.loader.get_source(
472
+ self._env, self._filename.name
473
+ )
474
+ return source
475
+
443
476
  def load(self):
444
477
  """Render Jinja + parse via backend"""
445
478
  if not self._filename.exists():
446
479
  self._data = {}
447
480
  self._loaded = True
481
+ return
448
482
 
483
+ raw = self._read_source()
484
+
485
+ if self._disable_jinja_render:
486
+ data = raw
449
487
  else:
450
- template = self._env.get_template(self._filename.name)
451
- data_render = template.render(**self._context)
488
+ template = self._env.from_string(raw)
489
+ data = template.render(**self._context)
452
490
 
453
- self._data = self._backend.load_data(data_render)
454
- self._loaded = True
491
+ self._data = self._backend.load_data(data)
492
+ self._loaded = True
455
493
 
456
494
  def reload(self):
457
495
  """Re-render si le context a changé"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zpp_config
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
4
  Summary: Module pour le chargement et la modification de fichier de configuration
5
5
  Home-page: https://github.com/ZephyrOff/zpp_config
6
6
  Author:
@@ -71,10 +71,15 @@ Le backend est automatiquement choisi selon l’extension du fichier, mais il es
71
71
  Lors de l'initialisation, il est également possible de définir plusieurs paramètres qui seront utile pour le render Jinja.
72
72
 
73
73
  **context**: défini un dictionnaire contenant les variables Jinja
74
+
74
75
  **vault_file**: emplacement du fichier vault
76
+
75
77
  **vault_keyfile**: emplacement du fichier contenant le mot de passe du vault
78
+
76
79
  **vault_password**: mot de passe du vault
80
+
77
81
  **vault_encryption_keyfile**: emplacement du fichier contenant le mot de passe du vault_encryption
82
+
78
83
  **vault_encryption_password**: mot de passe du vault_encryption
79
84
 
80
85
  ```python
@@ -144,6 +149,8 @@ db_host = config["db.host"]
144
149
  ```python
145
150
  db_host = config.get("db.host", default="127.0.0.1")
146
151
  ```
152
+ Par défaut, la méthode get va renvoyer un ConfigNode, mais il est possible de forcer l'envoi d'un dict brut avec dict_strict=True
153
+
147
154
  #### Itération
148
155
  ```python
149
156
  for key, sub in config.db.items():
File without changes
File without changes
File without changes