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.
- {commented_configparser-2.0.0/src/commented_configparser.egg-info → commented_configparser-2.1.0}/PKG-INFO +1 -1
- {commented_configparser-2.0.0 → commented_configparser-2.1.0/src/commented_configparser.egg-info}/PKG-INFO +1 -1
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/commentedconfigparser.py +11 -10
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.flake8 +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.github/workflows/python-tests.yml +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.gitignore +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/.pre-commit-config.yaml +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/CONTRIBUTING.md +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/LICENSE +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/README.md +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/noxfile.py +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/pyproject.toml +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements-dev.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements-test.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements.in +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/setup.cfg +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/SOURCES.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/dependency_links.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/requires.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/top_level.txt +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/__init__.py +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/py.typed +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/commentedconfigparser_test.py +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/header_expected.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/header_input.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/multi01_input.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/multi02_input.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/multi_expected.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/pydocs_expected.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/pydocs_input.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/regression_original_expected.ini +0 -0
- {commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/regression_original_input.ini +0 -0
|
@@ -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 = []
|
|
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)
|
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/.github/workflows/python-tests.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements-dev.txt
RENAMED
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/requirements/requirements-test.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/__init__.py
RENAMED
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/py.typed
RENAMED
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/commentedconfigparser_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/regression_original_expected.ini
RENAMED
|
File without changes
|
{commented_configparser-2.0.0 → commented_configparser-2.1.0}/tests/regression_original_input.ini
RENAMED
|
File without changes
|