ConfigUpdater 4.0.2__tar.gz → 4.1__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 (47) hide show
  1. {configupdater-4.0.2 → configupdater-4.1}/CHANGELOG.rst +9 -0
  2. {configupdater-4.0.2 → configupdater-4.1}/PKG-INFO +1 -1
  3. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/option.py +5 -3
  4. {configupdater-4.0.2 → configupdater-4.1}/tests/test_option.py +25 -2
  5. {configupdater-4.0.2 → configupdater-4.1}/.gitignore +0 -0
  6. {configupdater-4.0.2 → configupdater-4.1}/AUTHORS.rst +0 -0
  7. {configupdater-4.0.2 → configupdater-4.1}/CONTRIBUTING.rst +0 -0
  8. {configupdater-4.0.2 → configupdater-4.1}/LICENSE.txt +0 -0
  9. {configupdater-4.0.2 → configupdater-4.1}/README.md +0 -0
  10. {configupdater-4.0.2 → configupdater-4.1}/docs/_static/.gitignore +0 -0
  11. {configupdater-4.0.2 → configupdater-4.1}/docs/api.rst +0 -0
  12. {configupdater-4.0.2 → configupdater-4.1}/docs/authors.rst +0 -0
  13. {configupdater-4.0.2 → configupdater-4.1}/docs/changelog.rst +0 -0
  14. {configupdater-4.0.2 → configupdater-4.1}/docs/conf.py +0 -0
  15. {configupdater-4.0.2 → configupdater-4.1}/docs/contributing.rst +0 -0
  16. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/README.md +0 -0
  17. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/banner-1280x645.png +0 -0
  18. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/banner-640x323.png +0 -0
  19. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/configupdater.svg +0 -0
  20. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/configupdater_plain.svg +0 -0
  21. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/favicon.ico +0 -0
  22. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/icon-92x128.png +0 -0
  23. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/icon.svg +0 -0
  24. {configupdater-4.0.2 → configupdater-4.1}/docs/gfx/sidebar-254x128.png +0 -0
  25. {configupdater-4.0.2 → configupdater-4.1}/docs/index.rst +0 -0
  26. {configupdater-4.0.2 → configupdater-4.1}/docs/license.rst +0 -0
  27. {configupdater-4.0.2 → configupdater-4.1}/docs/usage.rst +0 -0
  28. {configupdater-4.0.2 → configupdater-4.1}/pyproject.toml +0 -0
  29. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/__init__.py +0 -0
  30. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/block.py +0 -0
  31. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/builder.py +0 -0
  32. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/configupdater.py +0 -0
  33. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/container.py +0 -0
  34. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/document.py +0 -0
  35. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/parser.py +0 -0
  36. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/py.typed +0 -0
  37. {configupdater-4.0.2 → configupdater-4.1}/src/configupdater/section.py +0 -0
  38. {configupdater-4.0.2 → configupdater-4.1}/tests/conftest.py +0 -0
  39. {configupdater-4.0.2 → configupdater-4.1}/tests/test_configupdater.py +0 -0
  40. {configupdater-4.0.2 → configupdater-4.1}/tests/test_optionxform.py +0 -0
  41. {configupdater-4.0.2 → configupdater-4.1}/tests/test_parser.py +0 -0
  42. {configupdater-4.0.2 → configupdater-4.1}/tests/test_readme.py +0 -0
  43. {configupdater-4.0.2 → configupdater-4.1}/tests/test_section.py +0 -0
  44. {configupdater-4.0.2 → configupdater-4.1}/tests/test_setup.cfg +0 -0
  45. {configupdater-4.0.2 → configupdater-4.1}/tools/__init__.py +0 -0
  46. {configupdater-4.0.2 → configupdater-4.1}/tools/release_notes.py +0 -0
  47. {configupdater-4.0.2 → configupdater-4.1}/tools/stdlib_diff.py +0 -0
@@ -2,6 +2,15 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ Version 4.1
6
+ ===========
7
+
8
+ - **Behavior change:** ``Option.as_list()`` returns an empty list instead of
9
+ ``[""]`` for an empty value, e.g. ``key =`` or after ``set_values([])``. An
10
+ empty list and a single empty value are written the same way, so ``set_values([])``
11
+ now round-trips and a later ``append()`` no longer adds an empty first entry,
12
+ PR #182
13
+
5
14
  Version 4.0.2
6
15
  =============
7
16
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ConfigUpdater
3
- Version: 4.0.2
3
+ Version: 4.1
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/
@@ -203,14 +203,16 @@ class Option(Block):
203
203
  def as_list(self, separator: str = "\n") -> list[str]:
204
204
  """Returns the (multi-line/element) value as a list
205
205
 
206
- Empty list if value is None, single-element list for a one-element
207
- value and an element for each line in a multi-element value.
206
+ Empty list if value is None or empty (only whitespace), single-element
207
+ list for a one-element value and an element for each line in a
208
+ multi-element value. Since an empty list and a list with a single empty
209
+ string are written the same way, ``set_values([])`` round-trips to ``[]``.
208
210
 
209
211
  Args:
210
212
  separator (str): separator for values, default: line separator
211
213
  """
212
214
  value = self.value
213
- if value is None:
215
+ if value is None or not value.strip():
214
216
  return []
215
217
  else:
216
218
  return [v.strip() for v in value.strip().split(separator)]
@@ -91,7 +91,7 @@ def test_as_list_after_scalar_assignment(initial):
91
91
  parser.read_string(f"[build]\n{initial}\n")
92
92
  for value in [None, "", "beta", None, "gamma"]:
93
93
  option.value = value
94
- assert option.as_list() == ([] if value is None else [value])
94
+ assert option.as_list() == ([value] if value else [])
95
95
  parser.set("build", "plugins", value)
96
96
  output = StringIO()
97
97
  cfg.write(output)
@@ -109,8 +109,31 @@ def test_as_list_after_setting_empty_values(initial):
109
109
  option = Option("plugins", initial)
110
110
  option.set_values([])
111
111
  assert option.value == ""
112
- assert option.as_list() == [""]
112
+ assert option.as_list() == []
113
113
  assert str(option) == "plugins = \n"
114
+ option.append("beta")
115
+ assert option.as_list() == ["beta"]
116
+ assert str(option) == "plugins =\n beta\n"
117
+
118
+
119
+ @pytest.mark.parametrize("value", ["", " ", "\n ", "\n \n "])
120
+ @pytest.mark.parametrize("separator", ["\n", ","])
121
+ def test_as_list_of_empty_value(value, separator):
122
+ option = Option("plugins", "x")
123
+ option.set_values([value], separator=separator, prepend_newline=False)
124
+ assert option.as_list(separator) == []
125
+
126
+
127
+ def test_as_list_of_parsed_empty_value():
128
+ source = "[build]\nplugins =\nother =\n \n"
129
+ cfg = ConfigUpdater().read_string(source)
130
+ parser = ConfigParser()
131
+ parser.read_string(source)
132
+ assert cfg["build"]["plugins"].value == parser["build"]["plugins"] == ""
133
+ assert cfg["build"]["plugins"].as_list() == []
134
+ assert cfg["build"]["other"].as_list() == []
135
+ cfg["build"]["plugins"].append("alpha")
136
+ assert cfg["build"]["plugins"].as_list() == ["alpha"]
114
137
 
115
138
 
116
139
  def test_append_to_new_valueless_option():
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes