configaroo 0.2.1__tar.gz → 0.2.2__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 (24) hide show
  1. {configaroo-0.2.1 → configaroo-0.2.2}/LICENSE +1 -1
  2. {configaroo-0.2.1 → configaroo-0.2.2}/PKG-INFO +1 -1
  3. {configaroo-0.2.1 → configaroo-0.2.2}/README.md +1 -1
  4. {configaroo-0.2.1 → configaroo-0.2.2}/pyproject.toml +2 -1
  5. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/__init__.py +1 -1
  6. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/configuration.py +16 -3
  7. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo.egg-info/PKG-INFO +1 -1
  8. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_configuration.py +18 -0
  9. {configaroo-0.2.1 → configaroo-0.2.2}/setup.cfg +0 -0
  10. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/exceptions.py +0 -0
  11. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/loaders/__init__.py +0 -0
  12. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/loaders/json.py +0 -0
  13. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/loaders/toml.py +0 -0
  14. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo/py.typed +0 -0
  15. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo.egg-info/SOURCES.txt +0 -0
  16. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo.egg-info/dependency_links.txt +0 -0
  17. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo.egg-info/requires.txt +0 -0
  18. {configaroo-0.2.1 → configaroo-0.2.2}/src/configaroo.egg-info/top_level.txt +0 -0
  19. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_dynamic.py +0 -0
  20. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_environment.py +0 -0
  21. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_json.py +0 -0
  22. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_loaders.py +0 -0
  23. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_toml.py +0 -0
  24. {configaroo-0.2.1 → configaroo-0.2.2}/tests/test_validation.py +0 -0
@@ -17,4 +17,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
17
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
18
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
19
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Bouncy handling of configuration files
5
5
  Author-email: Geir Arne Hjelle <geirarne@gmail.com>
6
6
  Maintainer-email: Geir Arne Hjelle <geirarne@gmail.com>
@@ -7,4 +7,4 @@ Configaroo is a light configuration package for Python that offers the following
7
7
  - Override key configuration settings with environment variables
8
8
  - Validate a configuration based on a Pydantic model
9
9
  - Convert the type of configuration values based on a Pydantic model
10
- - Dynamically format certain configuration values
10
+ - Dynamically format certain configuration values
@@ -40,6 +40,7 @@ build = ["build>=1.2.2.post1", "twine>=6.1.0"]
40
40
  dev = [
41
41
  "bumpver>=2024.1130",
42
42
  "ipython>=8.36.0",
43
+ "pre-commit>=4.2.0",
43
44
  "pytest>=8.3.5",
44
45
  "ruff>=0.11.11",
45
46
  "tomli-w>=1.2.0",
@@ -50,7 +51,7 @@ dev = [
50
51
  version = { attr = "configaroo.__version__" }
51
52
 
52
53
  [tool.bumpver]
53
- current_version = "v0.2.1"
54
+ current_version = "v0.2.2"
54
55
  version_pattern = "vMAJOR.MINOR.PATCH"
55
56
  commit_message = "bump version {old_version} -> {new_version}"
56
57
  tag_message = "{new_version}"
@@ -14,4 +14,4 @@ __all__ = [
14
14
  "UnsupportedLoaderError",
15
15
  ]
16
16
 
17
- __version__ = "0.2.1"
17
+ __version__ = "0.2.2"
@@ -18,6 +18,19 @@ ModelT = TypeVar("ModelT", bound=BaseModel)
18
18
  class Configuration(UserDict):
19
19
  """A Configuration is a dict-like structure with some conveniences"""
20
20
 
21
+ @classmethod
22
+ def from_dict(cls, data: dict[str, Any] | UserDict[str, Any] | Self) -> Self:
23
+ """Construct a Configuration from a dictionary
24
+
25
+ The dictionary is referenced directly, a copy isn't made
26
+ """
27
+ configuration = cls()
28
+ if isinstance(data, UserDict | Configuration):
29
+ configuration.data = data.data
30
+ else:
31
+ configuration.data = data
32
+ return configuration
33
+
21
34
  @classmethod
22
35
  def from_file(
23
36
  cls,
@@ -54,7 +67,7 @@ class Configuration(UserDict):
54
67
  """Make sure nested sections have type Configuration"""
55
68
  value = self.data[key]
56
69
  if isinstance(value, dict | UserDict | Configuration):
57
- return Configuration(value)
70
+ return Configuration.from_dict(value)
58
71
  else:
59
72
  return value
60
73
 
@@ -67,11 +80,11 @@ class Configuration(UserDict):
67
80
  f"'{type(self).__name__}' has no attribute or key '{key}'"
68
81
  )
69
82
 
70
- def __contains__(self, key: str) -> bool:
83
+ def __contains__(self, key: object) -> bool:
71
84
  """Add support for dotted keys"""
72
85
  if key in self.data:
73
86
  return True
74
- prefix, _, rest = key.partition(".")
87
+ prefix, _, rest = str(key).partition(".")
75
88
  try:
76
89
  return rest in self[prefix]
77
90
  except KeyError:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: configaroo
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Bouncy handling of configuration files
5
5
  Author-email: Geir Arne Hjelle <geirarne@gmail.com>
6
6
  Maintainer-email: Geir Arne Hjelle <geirarne@gmail.com>
@@ -72,6 +72,24 @@ def test_update_preserves_type(config):
72
72
  assert isinstance(config, Configuration)
73
73
 
74
74
 
75
+ def test_update_changes_values(config):
76
+ """Test that an update adds or changes values"""
77
+ updated_config = config | {"number": 14, "new": "brand new!"}
78
+ assert updated_config.number == 14
79
+ assert updated_config.new == "brand new!"
80
+
81
+ config.update({"number": 14, "new": "brand new!"})
82
+ assert config.number == 14
83
+ assert config.new == "brand new!"
84
+
85
+
86
+ def test_update_nested_values(config):
87
+ """Test that a nested section can be updated"""
88
+ config.nested.deep.update({"sea": "Mjoesa", "depth": 456})
89
+ assert config.nested.deep.sea == "Mjoesa"
90
+ assert config.nested.deep.depth == 456
91
+
92
+
75
93
  def test_dump_to_dict(config):
76
94
  """Test that dumping to a dictionary unwraps nested sections"""
77
95
  config_dict = config.to_dict()
File without changes