Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit 800b043

Browse files
authored
Fixes load_values in PlainConfig (#167)
* Fixes #165 - Fixes `load_values` for `PlainConfig` where accessing item with `__getitem__` returns value so lower level method needs to be used in lookup * Tested with Python 3.6 and 3.7 * Warn users about the state of the library Thanks @haizaar
1 parent 9dc73cb commit 800b043

7 files changed

Lines changed: 29 additions & 9 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.34.0
2+
current_version = 1.34.1
33
commit = true
44
tag = false
55

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
configmanager
22
=============
33

4+
**Update on 2018-10-20**: I no longer use this library. It tries to do too many things. It was written in
5+
Python 2.7 and made work with Python 3. With type hints, dataclasses, and many other cool features in Python 3.6+
6+
you can express the same things in a much nicer way than this.
7+
8+
----
9+
410
.. image:: https://travis-ci.org/jbasko/configmanager.svg?branch=master
511
:target: https://travis-ci.org/jbasko/configmanager
612

configmanager/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '1.34.0'
1+
__version__ = '1.34.1'
22

33
from .managers import Config
44
from .items import Item

configmanager/sections.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,17 @@ def load_values(self, dictionary, as_defaults=False, flat=False):
574574
self[name] = self.create_item(name, default=value)
575575
else:
576576
# Skip unknown names if not interpreting dictionary as defaults
577-
continue
578-
elif is_config_item(self[name]):
577+
pass
578+
continue
579+
580+
resolution = self._get_item_or_section(name, handle_not_found=False)
581+
if is_config_item(resolution):
579582
if as_defaults:
580-
self[name].default = value
583+
resolution.default = value
581584
else:
582-
self[name].value = value
585+
resolution.value = value
583586
else:
584-
self[name].load_values(value, as_defaults=as_defaults)
587+
resolution.load_values(value, as_defaults=as_defaults)
585588

586589
def create_item(self, *args, **kwargs):
587590
"""

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def read(fname):
3939
'Programming Language :: Python :: 2.7',
4040
'Programming Language :: Python :: 3',
4141
'Programming Language :: Python :: 3.5',
42+
'Programming Language :: Python :: 3.6',
43+
'Programming Language :: Python :: 3.7',
4244
'License :: OSI Approved :: MIT License',
4345
],
4446
)

tests/test_yaml.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import six
33

4-
from configmanager import Config
4+
from configmanager import Config, PlainConfig
55

66

77
@pytest.fixture
@@ -31,6 +31,15 @@ def test_config_written_to_and_read_from_yaml_file(yaml_path1):
3131
assert config2.dump_values() == original_values
3232

3333

34+
def test_plain_config_loaded_from_yaml_file(yaml_path1):
35+
with open(yaml_path1, "w") as f:
36+
f.write("name: bar\n")
37+
38+
config = PlainConfig(schema={"name": "foo"})
39+
config.yaml.load(yaml_path1)
40+
assert config["name"] == "bar"
41+
42+
3443
def test_config_written_to_and_read_from_yaml_string():
3544
config_str = (
3645
'uploads:\n'

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# For more information about tox, see https://tox.readthedocs.io/en/latest/
22
[tox]
3-
envlist = py27,py35
3+
envlist = py{27,35,36,37}
44
skip_missing_interpreters = True
55

66
[testenv]

0 commit comments

Comments
 (0)