ConfigUpdater 4.0.1__tar.gz → 4.0.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.
- {configupdater-4.0.1 → configupdater-4.0.2}/AUTHORS.rst +2 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/CHANGELOG.rst +10 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/PKG-INFO +1 -1
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/document.py +1 -1
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/option.py +3 -2
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/section.py +1 -1
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_configupdater.py +37 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_option.py +64 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_section.py +33 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/.gitignore +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/CONTRIBUTING.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/LICENSE.txt +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/README.md +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/_static/.gitignore +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/api.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/authors.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/changelog.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/conf.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/contributing.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/README.md +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/banner-1280x645.png +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/banner-640x323.png +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/configupdater.svg +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/configupdater_plain.svg +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/favicon.ico +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/icon-92x128.png +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/icon.svg +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/gfx/sidebar-254x128.png +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/index.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/license.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/docs/usage.rst +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/pyproject.toml +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/__init__.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/block.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/builder.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/configupdater.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/container.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/parser.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/src/configupdater/py.typed +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/conftest.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_optionxform.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_parser.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_readme.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tests/test_setup.cfg +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tools/__init__.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tools/release_notes.py +0 -0
- {configupdater-4.0.1 → configupdater-4.0.2}/tools/stdlib_diff.py +0 -0
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
Changelog
|
|
3
3
|
=========
|
|
4
4
|
|
|
5
|
+
Version 4.0.2
|
|
6
|
+
=============
|
|
7
|
+
|
|
8
|
+
- Make ``Option.as_list()`` use the current value after assignments to or from
|
|
9
|
+
``None``, so ``append()`` no longer discards values added to a valueless option
|
|
10
|
+
and converting an option to ``None`` no longer raises an ``AttributeError``, PR #179
|
|
11
|
+
- Detach every child block when clearing a document or section, so removed
|
|
12
|
+
sections and options can be attached elsewhere without stale parent links
|
|
13
|
+
(follow-up to PR #43), PR #180
|
|
14
|
+
|
|
5
15
|
Version 4.0.1
|
|
6
16
|
=============
|
|
7
17
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: ConfigUpdater
|
|
3
|
-
Version: 4.0.
|
|
3
|
+
Version: 4.0.2
|
|
4
4
|
Summary: Parser like ConfigParser but for updating configuration files
|
|
5
5
|
Project-URL: Homepage, https://github.com/pyscaffold/configupdater
|
|
6
6
|
Project-URL: Documentation, https://configupdater.readthedocs.io/
|
|
@@ -209,10 +209,11 @@ class Option(Block):
|
|
|
209
209
|
Args:
|
|
210
210
|
separator (str): separator for values, default: line separator
|
|
211
211
|
"""
|
|
212
|
-
|
|
212
|
+
value = self.value
|
|
213
|
+
if value is None:
|
|
213
214
|
return []
|
|
214
215
|
else:
|
|
215
|
-
return [v.strip() for v in
|
|
216
|
+
return [v.strip() for v in value.strip().split(separator)]
|
|
216
217
|
|
|
217
218
|
def append(self, value: str, **kwargs: Any) -> Option:
|
|
218
219
|
"""Append a value to a multi-line value
|
|
@@ -372,6 +372,6 @@ class Section(Block, Container[Content], MutableMapping[str, Option]):
|
|
|
372
372
|
return BlockBuilder(self, idx)
|
|
373
373
|
|
|
374
374
|
def clear(self) -> None:
|
|
375
|
-
for block in self._structure:
|
|
375
|
+
for block in self._structure.copy():
|
|
376
376
|
block.detach()
|
|
377
377
|
self._structure.clear()
|
|
@@ -35,6 +35,43 @@ def test_read_write_no_changes(setup_cfg_path, setup_cfg):
|
|
|
35
35
|
assert str(updater) == setup_cfg
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
@pytest.mark.parametrize("reload", [False, True])
|
|
39
|
+
@pytest.mark.parametrize(
|
|
40
|
+
"config",
|
|
41
|
+
[
|
|
42
|
+
"",
|
|
43
|
+
"[one]\nkey = 1\n",
|
|
44
|
+
"[one]\nkey = 1\n[two]\nkey = 2\n[three]\nkey = 3\n",
|
|
45
|
+
"# preamble\n\n[one]\nkey = 1\n\n[two]\nkey = 2\n",
|
|
46
|
+
],
|
|
47
|
+
)
|
|
48
|
+
def test_clear_detaches_all_document_blocks(config, reload):
|
|
49
|
+
updater = ConfigUpdater().read_string(config)
|
|
50
|
+
blocks = list(updater.iter_blocks())
|
|
51
|
+
sections = list(updater.iter_sections())
|
|
52
|
+
original_values = updater.to_dict()
|
|
53
|
+
|
|
54
|
+
if reload:
|
|
55
|
+
updater.read_string("[replacement]\nvalue = new\n")
|
|
56
|
+
assert updater.sections() == ["replacement"]
|
|
57
|
+
else:
|
|
58
|
+
reference = ConfigParser()
|
|
59
|
+
reference.read_string(config)
|
|
60
|
+
reference.clear()
|
|
61
|
+
updater.clear()
|
|
62
|
+
assert str(updater) == ""
|
|
63
|
+
assert updater.sections() == reference.sections() == []
|
|
64
|
+
|
|
65
|
+
for block in blocks:
|
|
66
|
+
assert not block.has_container()
|
|
67
|
+
other = ConfigUpdater()
|
|
68
|
+
for section in sections:
|
|
69
|
+
assert all(option.container is section for option in section.iter_options())
|
|
70
|
+
other.add_section(section)
|
|
71
|
+
assert section.container is other
|
|
72
|
+
assert other.to_dict() == original_values
|
|
73
|
+
|
|
74
|
+
|
|
38
75
|
def test_read_file_like(setup_cfg_path):
|
|
39
76
|
updater = ConfigUpdater()
|
|
40
77
|
with open(setup_cfg_path) as fp:
|
|
@@ -57,6 +57,70 @@ def test_str_for_set_values():
|
|
|
57
57
|
assert str(opt) == "opt = 1, 2, 3, 4\n"
|
|
58
58
|
|
|
59
59
|
|
|
60
|
+
@pytest.mark.parametrize("separator", ["\n", ", "])
|
|
61
|
+
@pytest.mark.parametrize("prepend_newline", [True, False])
|
|
62
|
+
def test_as_list_and_append_after_setting_valueless_option(separator, prepend_newline):
|
|
63
|
+
source = "# keep comment\n[build]\nplugins\nother : unchanged\n"
|
|
64
|
+
cfg = ConfigUpdater(allow_no_value=True, delimiters=(":",)).read_string(source)
|
|
65
|
+
option = cfg["build"]["plugins"]
|
|
66
|
+
assert option.as_list() == []
|
|
67
|
+
assert str(cfg) == source
|
|
68
|
+
kwargs = {"separator": separator, "prepend_newline": prepend_newline}
|
|
69
|
+
option.set_values(["alpha", "beta"], **kwargs)
|
|
70
|
+
assert option.as_list(separator) == ["alpha", "beta"]
|
|
71
|
+
for value in ["gamma", "delta"]:
|
|
72
|
+
option.append(value, **kwargs)
|
|
73
|
+
assert option.as_list(separator) == ["alpha", "beta", "gamma", "delta"]
|
|
74
|
+
output = StringIO()
|
|
75
|
+
cfg.write(output)
|
|
76
|
+
assert output.getvalue().startswith("# keep comment\n[build]\nplugins :")
|
|
77
|
+
assert output.getvalue().endswith("other : unchanged\n")
|
|
78
|
+
parser = ConfigParser(allow_no_value=True, delimiters=(":",))
|
|
79
|
+
parser.read_string(output.getvalue())
|
|
80
|
+
expected = separator.join(["alpha", "beta", "gamma", "delta"])
|
|
81
|
+
if separator == "\n" and prepend_newline:
|
|
82
|
+
expected = "\n" + expected
|
|
83
|
+
assert parser["build"]["plugins"] == expected
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@pytest.mark.parametrize("initial", ["plugins", "plugins = alpha"])
|
|
87
|
+
def test_as_list_after_scalar_assignment(initial):
|
|
88
|
+
cfg = ConfigUpdater(allow_no_value=True).read_string(f"[build]\n{initial}\n")
|
|
89
|
+
option = cfg["build"]["plugins"]
|
|
90
|
+
parser = ConfigParser(allow_no_value=True)
|
|
91
|
+
parser.read_string(f"[build]\n{initial}\n")
|
|
92
|
+
for value in [None, "", "beta", None, "gamma"]:
|
|
93
|
+
option.value = value
|
|
94
|
+
assert option.as_list() == ([] if value is None else [value])
|
|
95
|
+
parser.set("build", "plugins", value)
|
|
96
|
+
output = StringIO()
|
|
97
|
+
cfg.write(output)
|
|
98
|
+
reparsed = ConfigParser(allow_no_value=True)
|
|
99
|
+
reparsed.read_string(output.getvalue())
|
|
100
|
+
assert dict(reparsed["build"]) == dict(parser["build"])
|
|
101
|
+
option.value = None
|
|
102
|
+
option.append("delta")
|
|
103
|
+
option.append("epsilon")
|
|
104
|
+
assert option.as_list() == ["delta", "epsilon"]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@pytest.mark.parametrize("initial", [None, "alpha"])
|
|
108
|
+
def test_as_list_after_setting_empty_values(initial):
|
|
109
|
+
option = Option("plugins", initial)
|
|
110
|
+
option.set_values([])
|
|
111
|
+
assert option.value == ""
|
|
112
|
+
assert option.as_list() == [""]
|
|
113
|
+
assert str(option) == "plugins = \n"
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_append_to_new_valueless_option():
|
|
117
|
+
option = Option("plugins")
|
|
118
|
+
assert option.as_list() == []
|
|
119
|
+
option.append("alpha")
|
|
120
|
+
option.append("beta")
|
|
121
|
+
assert option.as_list() == ["alpha", "beta"]
|
|
122
|
+
|
|
123
|
+
|
|
60
124
|
@pytest.mark.parametrize("delimiters", [("=", ":"), (":", "="), ("=>", ":"), ":="])
|
|
61
125
|
@pytest.mark.parametrize("spaces", [True, False])
|
|
62
126
|
def test_assign_value_to_parsed_no_value_option(delimiters, spaces):
|
|
@@ -9,6 +9,39 @@ from configupdater.block import AlreadyAttachedError, NotAttachedError
|
|
|
9
9
|
from configupdater.parser import Parser
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
@pytest.mark.parametrize(
|
|
13
|
+
"body",
|
|
14
|
+
[
|
|
15
|
+
"",
|
|
16
|
+
"a = 1\n",
|
|
17
|
+
"a = 1\nb = 2\nc = 3\n",
|
|
18
|
+
"a = 1\n# note\nb = 2\n\nc = 3\n",
|
|
19
|
+
],
|
|
20
|
+
)
|
|
21
|
+
def test_clear_detaches_all_section_blocks(body):
|
|
22
|
+
updater = ConfigUpdater().read_string("[source]\n" + body)
|
|
23
|
+
section = updater["source"]
|
|
24
|
+
blocks = list(section.iter_blocks())
|
|
25
|
+
options = list(section.iter_options())
|
|
26
|
+
original_values = section.to_dict()
|
|
27
|
+
reference = ConfigParser()
|
|
28
|
+
reference.read_string("[source]\n" + body)
|
|
29
|
+
reference["source"].clear()
|
|
30
|
+
|
|
31
|
+
section.clear()
|
|
32
|
+
|
|
33
|
+
assert section.container is updater
|
|
34
|
+
assert section.options() == list(reference["source"]) == []
|
|
35
|
+
assert str(section) == "[source]\n"
|
|
36
|
+
for block in blocks:
|
|
37
|
+
assert not block.has_container()
|
|
38
|
+
other = ConfigUpdater().read_string("[target]\n")
|
|
39
|
+
for option in options:
|
|
40
|
+
other["target"].add_option(option)
|
|
41
|
+
assert option.container is other["target"]
|
|
42
|
+
assert other["target"].to_dict() == original_values
|
|
43
|
+
|
|
44
|
+
|
|
12
45
|
def test_add_before_skip_comments():
|
|
13
46
|
doc = Parser().read_string("[first]\na = 1\n")
|
|
14
47
|
doc["first"].add_after.space().comment("target comment").section("target")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|