commented-configparser 2.0.0__tar.gz → 2.1.0__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 (33) hide show
  1. {commented_configparser-2.0.0/src/commented_configparser.egg-info → commented_configparser-2.1.0}/PKG-INFO +1 -1
  2. {commented_configparser-2.0.0 → commented_configparser-2.1.0/src/commented_configparser.egg-info}/PKG-INFO +1 -1
  3. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/commentedconfigparser.py +11 -10
  4. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.flake8 +0 -0
  5. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.github/workflows/python-tests.yml +0 -0
  6. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.gitignore +0 -0
  7. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.pre-commit-config.yaml +0 -0
  8. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/CONTRIBUTING.md +0 -0
  9. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/LICENSE +0 -0
  10. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/README.md +0 -0
  11. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/noxfile.py +0 -0
  12. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/pyproject.toml +0 -0
  13. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements-dev.txt +0 -0
  14. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements-test.txt +0 -0
  15. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements.in +0 -0
  16. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements.txt +0 -0
  17. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/setup.cfg +0 -0
  18. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/SOURCES.txt +0 -0
  19. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/dependency_links.txt +0 -0
  20. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/requires.txt +0 -0
  21. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/top_level.txt +0 -0
  22. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/__init__.py +0 -0
  23. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/py.typed +0 -0
  24. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/commentedconfigparser_test.py +0 -0
  25. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/header_expected.ini +0 -0
  26. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/header_input.ini +0 -0
  27. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/multi01_input.ini +0 -0
  28. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/multi02_input.ini +0 -0
  29. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/multi_expected.ini +0 -0
  30. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/pydocs_expected.ini +0 -0
  31. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/pydocs_input.ini +0 -0
  32. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/regression_original_expected.ini +0 -0
  33. {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/regression_original_input.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commented-configparser
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Custom ConfigParser class that preserves comments in file when writing
5
5
  Author-email: Preocts <preocts@preocts.com>
6
6
  License: MIT License
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commented-configparser
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Custom ConfigParser class that preserves comments in file when writing
5
5
  Author-email: Preocts <preocts@preocts.com>
6
6
  License: MIT License
@@ -25,15 +25,6 @@ SECTION_PATTERN = re.compile(r"^\s*\[(.+)\]\s*$")
25
25
  class CommentedConfigParser(ConfigParser):
26
26
  """Custom ConfigParser that preserves comments when writing a loaded config out."""
27
27
 
28
- def __init__(self) -> None:
29
- # The header contains any comments that arrive before a section
30
- # is declared. These cannot be translated to options and must
31
- # be stored internally.
32
- self._headers: list[str] = []
33
- self._commentprefix = 0
34
-
35
- super().__init__()
36
-
37
28
  def read(
38
29
  self,
39
30
  filenames: StrOrBytesPath | Iterable[StrOrBytesPath],
@@ -83,6 +74,14 @@ class CommentedConfigParser(ConfigParser):
83
74
  """Translate comments to section options while storing header."""
84
75
  seen_section = False
85
76
 
77
+ # To save the pain of mirroring ConfigParser's __init__ these two
78
+ # attributes are created in the instance here, when needed.
79
+ if not hasattr(self, "_headers"):
80
+ self._headers: list[str] = []
81
+
82
+ if not hasattr(self, "_commentprefix"):
83
+ self._commentprefix = 0
84
+
86
85
  translated_lines = []
87
86
  for idx, line in enumerate(content):
88
87
  if SECTION_PATTERN.match(line):
@@ -117,7 +116,9 @@ class CommentedConfigParser(ConfigParser):
117
116
  def _restore_comments(self, content: str) -> str:
118
117
  """Restore comment options to comments."""
119
118
  # Apply the headers before parsing the config lines
120
- rendered = [] + self._headers
119
+ rendered = []
120
+ if hasattr(self, "_headers"):
121
+ rendered += self._headers
121
122
 
122
123
  for line in content.splitlines():
123
124
  comment_match = COMMENT_OPTION_PATTERN.match(line)