commented-configparser 1.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.1.0/.flake8 +7 -0
- commented_configparser-2.1.0/.github/workflows/python-tests.yml +108 -0
- commented_configparser-2.1.0/.gitignore +14 -0
- commented_configparser-2.1.0/.pre-commit-config.yaml +50 -0
- commented_configparser-2.1.0/CONTRIBUTING.md +186 -0
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/LICENSE +1 -1
- commented_configparser-2.1.0/PKG-INFO +155 -0
- commented_configparser-2.1.0/README.md +107 -0
- commented_configparser-2.1.0/noxfile.py +160 -0
- commented_configparser-2.1.0/pyproject.toml +79 -0
- commented_configparser-2.1.0/requirements/requirements-dev.txt +8 -0
- commented_configparser-2.1.0/requirements/requirements-test.txt +6 -0
- commented_configparser-2.1.0/requirements/requirements.in +1 -0
- commented_configparser-2.1.0/requirements/requirements.txt +6 -0
- commented_configparser-2.1.0/src/commented_configparser.egg-info/PKG-INFO +155 -0
- commented_configparser-2.1.0/src/commented_configparser.egg-info/SOURCES.txt +31 -0
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/requires.txt +1 -1
- commented_configparser-2.1.0/src/commentedconfigparser/commentedconfigparser.py +130 -0
- commented_configparser-2.1.0/tests/commentedconfigparser_test.py +201 -0
- commented_configparser-2.1.0/tests/header_expected.ini +11 -0
- commented_configparser-2.1.0/tests/header_input.ini +10 -0
- commented_configparser-2.1.0/tests/multi01_input.ini +6 -0
- commented_configparser-2.1.0/tests/multi02_input.ini +6 -0
- commented_configparser-2.1.0/tests/multi_expected.ini +11 -0
- commented_configparser-2.1.0/tests/pydocs_expected.ini +43 -0
- commented_configparser-2.1.0/tests/pydocs_input.ini +43 -0
- commented_configparser-2.1.0/tests/regression_original_expected.ini +21 -0
- commented_configparser-2.1.0/tests/regression_original_input.ini +21 -0
- commented-configparser-1.0.0/PKG-INFO +0 -286
- commented-configparser-1.0.0/README.md +0 -248
- commented-configparser-1.0.0/pyproject.toml +0 -146
- commented-configparser-1.0.0/setup.py +0 -5
- commented-configparser-1.0.0/src/commented_configparser.egg-info/PKG-INFO +0 -286
- commented-configparser-1.0.0/src/commented_configparser.egg-info/SOURCES.txt +0 -12
- commented-configparser-1.0.0/src/commentedconfigparser/commentedconfigparser.py +0 -199
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/setup.cfg +0 -0
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/dependency_links.txt +0 -0
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/src/commented_configparser.egg-info/top_level.txt +0 -0
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/__init__.py +0 -0
- {commented-configparser-1.0.0 → commented_configparser-2.1.0}/src/commentedconfigparser/py.typed +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
name: "python tests and coverage"
|
|
2
|
+
# Uses:
|
|
3
|
+
# https://github.com/actions/setup-python
|
|
4
|
+
# https://github.com/actions/checkout
|
|
5
|
+
# https://github.com/actions/download-artifact
|
|
6
|
+
# https://github.com/actions/upload-artifact
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
pull_request:
|
|
10
|
+
branches:
|
|
11
|
+
- "*"
|
|
12
|
+
push:
|
|
13
|
+
branches:
|
|
14
|
+
- "main"
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
run-tests-and-coverage:
|
|
18
|
+
name: "Run nox for tests and coverage"
|
|
19
|
+
runs-on: "${{ matrix.os }}"
|
|
20
|
+
strategy:
|
|
21
|
+
fail-fast: false
|
|
22
|
+
matrix:
|
|
23
|
+
os:
|
|
24
|
+
- "macos-latest"
|
|
25
|
+
- "windows-latest"
|
|
26
|
+
- "ubuntu-latest"
|
|
27
|
+
python-version:
|
|
28
|
+
- "3.8"
|
|
29
|
+
- "3.9"
|
|
30
|
+
- "3.10"
|
|
31
|
+
- "3.11"
|
|
32
|
+
- "3.12"
|
|
33
|
+
- "3.13"
|
|
34
|
+
|
|
35
|
+
steps:
|
|
36
|
+
- name: "Repo checkout"
|
|
37
|
+
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11"
|
|
38
|
+
|
|
39
|
+
- name: "Set up Python ${{ matrix.python-version }}"
|
|
40
|
+
uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c"
|
|
41
|
+
with:
|
|
42
|
+
python-version: "${{ matrix.python-version }}"
|
|
43
|
+
allow-prereleases: true
|
|
44
|
+
|
|
45
|
+
- name: "Install nox"
|
|
46
|
+
run: |
|
|
47
|
+
python -m pip install --upgrade pip nox
|
|
48
|
+
|
|
49
|
+
- name: "Run tests and coverage via nox"
|
|
50
|
+
run: |
|
|
51
|
+
nox --session tests_with_coverage-${{ matrix.python-version }}
|
|
52
|
+
|
|
53
|
+
- name: "Save coverage artifact"
|
|
54
|
+
uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3"
|
|
55
|
+
with:
|
|
56
|
+
name: "coverage-artifact-${{ matrix.os}}-${{ matrix.python-version}}"
|
|
57
|
+
path: ".coverage.*"
|
|
58
|
+
retention-days: 1
|
|
59
|
+
|
|
60
|
+
coverage-compile:
|
|
61
|
+
name: "coverage compile"
|
|
62
|
+
needs: "run-tests-and-coverage"
|
|
63
|
+
runs-on: "ubuntu-latest"
|
|
64
|
+
steps:
|
|
65
|
+
- name: "Repo checkout"
|
|
66
|
+
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11"
|
|
67
|
+
|
|
68
|
+
- name: "Set up Python"
|
|
69
|
+
uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c"
|
|
70
|
+
with:
|
|
71
|
+
python-version: "3.12"
|
|
72
|
+
|
|
73
|
+
- name: "Install nox"
|
|
74
|
+
run: |
|
|
75
|
+
python -m pip install --upgrade pip nox
|
|
76
|
+
|
|
77
|
+
- name: "Download coverage artifacts"
|
|
78
|
+
uses: "actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427"
|
|
79
|
+
with:
|
|
80
|
+
pattern: "coverage-artifact-*"
|
|
81
|
+
merge-multiple: true
|
|
82
|
+
|
|
83
|
+
- name: "Compile coverage data, print report"
|
|
84
|
+
run: |
|
|
85
|
+
nox --session coverage_combine_and_report
|
|
86
|
+
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
|
|
87
|
+
echo "TOTAL=$TOTAL" >> $GITHUB_ENV
|
|
88
|
+
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
|
|
89
|
+
|
|
90
|
+
mypy-check:
|
|
91
|
+
name: "mypy strict enforcement"
|
|
92
|
+
runs-on: "ubuntu-latest"
|
|
93
|
+
steps:
|
|
94
|
+
- name: "Repo checkout"
|
|
95
|
+
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11"
|
|
96
|
+
|
|
97
|
+
- name: "Set up Python"
|
|
98
|
+
uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c"
|
|
99
|
+
with:
|
|
100
|
+
python-version: "3.12"
|
|
101
|
+
|
|
102
|
+
- name: "Install nox"
|
|
103
|
+
run: |
|
|
104
|
+
python -m pip install --upgrade pip nox
|
|
105
|
+
|
|
106
|
+
- name: "Enforce strict type annotations with mypy"
|
|
107
|
+
run: |
|
|
108
|
+
nox --session mypy_check
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
ci:
|
|
2
|
+
autoupdate_schedule: monthly
|
|
3
|
+
exclude: ^.+\.ini$
|
|
4
|
+
repos:
|
|
5
|
+
# Batch of helpful formatters and patterns
|
|
6
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
7
|
+
rev: "v4.6.0"
|
|
8
|
+
hooks:
|
|
9
|
+
- id: check-json
|
|
10
|
+
- id: check-toml
|
|
11
|
+
- id: check-yaml
|
|
12
|
+
- id: trailing-whitespace
|
|
13
|
+
- id: end-of-file-fixer
|
|
14
|
+
- id: check-docstring-first
|
|
15
|
+
- id: debug-statements
|
|
16
|
+
- id: mixed-line-ending
|
|
17
|
+
|
|
18
|
+
# Adds a standard feel to import segments
|
|
19
|
+
- repo: https://github.com/pycqa/isort
|
|
20
|
+
rev: 5.13.2
|
|
21
|
+
hooks:
|
|
22
|
+
- id: isort
|
|
23
|
+
args:
|
|
24
|
+
- "--force-single-line-imports"
|
|
25
|
+
- "--add-import"
|
|
26
|
+
- "from __future__ import annotations"
|
|
27
|
+
- "--profile"
|
|
28
|
+
- "black"
|
|
29
|
+
|
|
30
|
+
# Format code. No, I don't like everything black does either.
|
|
31
|
+
- repo: https://github.com/psf/black-pre-commit-mirror
|
|
32
|
+
rev: 24.4.2
|
|
33
|
+
hooks:
|
|
34
|
+
- id: black
|
|
35
|
+
|
|
36
|
+
# Flake8 for linting, line-length adjusted to match Black default
|
|
37
|
+
- repo: https://github.com/PyCQA/flake8
|
|
38
|
+
rev: 7.1.0
|
|
39
|
+
hooks:
|
|
40
|
+
- id: flake8
|
|
41
|
+
additional_dependencies:
|
|
42
|
+
- flake8-builtins
|
|
43
|
+
- flake8-pep585
|
|
44
|
+
- pep8-naming
|
|
45
|
+
|
|
46
|
+
# Type enforcement for Python
|
|
47
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
48
|
+
rev: v1.11.1
|
|
49
|
+
hooks:
|
|
50
|
+
- id: mypy
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Before contributing, please either ask to claim an existing open issue or create
|
|
4
|
+
a new issue to discuss your proposed changes with the owner(s) of this repo
|
|
5
|
+
before making any changes.
|
|
6
|
+
|
|
7
|
+
Any pull requests without a clearly defined issue being solved will be closed.
|
|
8
|
+
|
|
9
|
+
### Bug reports
|
|
10
|
+
|
|
11
|
+
Found a bug but do not have time or do not wish to contribute a fix? Please
|
|
12
|
+
submit an issue for our awareness. Your feedback drives the continued
|
|
13
|
+
development of the project!
|
|
14
|
+
|
|
15
|
+
### Pull Request
|
|
16
|
+
|
|
17
|
+
All pull requests must:
|
|
18
|
+
|
|
19
|
+
- Pass all linting and formatting checks
|
|
20
|
+
- Have tests that cover all branches of the added feature
|
|
21
|
+
- If the PR is a bug fix there must be a test that duplicates the bug, proving
|
|
22
|
+
it is fixed
|
|
23
|
+
|
|
24
|
+
### Code Style
|
|
25
|
+
|
|
26
|
+
Follow the patterns seen in the code. Walk where others have walked.
|
|
27
|
+
|
|
28
|
+
The majority of code style nits will be met when passing `pre-commit` checks
|
|
29
|
+
prior to submitting a pull request.
|
|
30
|
+
|
|
31
|
+
### Tests
|
|
32
|
+
|
|
33
|
+
- Smaller tests are easier to work with
|
|
34
|
+
- Mock at a minimum
|
|
35
|
+
- No test should be dependent on another
|
|
36
|
+
- No test should be dependent on secrets/tokens
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
# Local developer installation
|
|
42
|
+
|
|
43
|
+
The following steps outline how to install this repo for local development.
|
|
44
|
+
|
|
45
|
+
## Prerequisites
|
|
46
|
+
|
|
47
|
+
### Clone repo
|
|
48
|
+
|
|
49
|
+
```console
|
|
50
|
+
git clone https://github.com/Preocts/commented-configparser
|
|
51
|
+
|
|
52
|
+
cd commented-configparser
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Virtual Environment
|
|
56
|
+
|
|
57
|
+
Use a ([`venv`](https://docs.python.org/3/library/venv.html)), or equivalent,
|
|
58
|
+
when working with python projects. Leveraging a `venv` will ensure the installed
|
|
59
|
+
dependency files will not impact other python projects or any system
|
|
60
|
+
dependencies.
|
|
61
|
+
|
|
62
|
+
**Windows users**: Depending on your python install you will use `py` in place
|
|
63
|
+
of `python` to create the `venv`.
|
|
64
|
+
|
|
65
|
+
**Linux/Mac users**: Replace `python`, if needed, with the appropriate call to
|
|
66
|
+
the desired version while creating the `venv`. (e.g. `python3` or `python3.12`)
|
|
67
|
+
|
|
68
|
+
**All users**: Once inside an active `venv` all systems should allow the use of
|
|
69
|
+
`python` for command line instructions. This will ensure you are using the
|
|
70
|
+
`venv`'s python and not the system level python.
|
|
71
|
+
|
|
72
|
+
### Create the `venv`:
|
|
73
|
+
|
|
74
|
+
```console
|
|
75
|
+
python -m venv venv
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Activate the `venv`:
|
|
79
|
+
|
|
80
|
+
```console
|
|
81
|
+
# Linux/Mac
|
|
82
|
+
. venv/bin/activate
|
|
83
|
+
|
|
84
|
+
# Windows
|
|
85
|
+
venv\Scripts\activate
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The command prompt should now have a `(venv)` prefix on it. `python` will now
|
|
89
|
+
call the version of the interpreter used to create the `venv`
|
|
90
|
+
|
|
91
|
+
To deactivate (exit) the `venv`:
|
|
92
|
+
|
|
93
|
+
```console
|
|
94
|
+
deactivate
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Developer Installation Steps
|
|
100
|
+
|
|
101
|
+
### Install editable library and development requirements
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
python -m pip install --editable .[dev,test]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Install pre-commit [(see below for details)](#pre-commit)
|
|
108
|
+
|
|
109
|
+
```console
|
|
110
|
+
pre-commit install
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Install with nox
|
|
114
|
+
|
|
115
|
+
If you have `nox` installed with `pipx` or in the current venv you can use the
|
|
116
|
+
following session. This is an alternative to the two steps above.
|
|
117
|
+
|
|
118
|
+
```console
|
|
119
|
+
nox -s install
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Pre-commit and nox tools
|
|
125
|
+
|
|
126
|
+
### Run pre-commit on all files
|
|
127
|
+
|
|
128
|
+
```console
|
|
129
|
+
pre-commit run --all-files
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Run tests with coverage (quick)
|
|
133
|
+
|
|
134
|
+
```console
|
|
135
|
+
nox -e coverage
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Run tests (slow)
|
|
139
|
+
|
|
140
|
+
```console
|
|
141
|
+
nox
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Build dist
|
|
145
|
+
|
|
146
|
+
```console
|
|
147
|
+
nox -e build
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Updating dependencies
|
|
153
|
+
|
|
154
|
+
New dependencys can be added to the `requirements-*.in` file. It is recommended
|
|
155
|
+
to only use pins when specific versions or upgrades beyond a certain version are
|
|
156
|
+
to be avoided. Otherwise, allow `pip-compile` to manage the pins in the
|
|
157
|
+
generated `requirements-*.txt` files.
|
|
158
|
+
|
|
159
|
+
Once updated following the steps below, the package can be installed if needed.
|
|
160
|
+
|
|
161
|
+
### Update the generated files with changes
|
|
162
|
+
|
|
163
|
+
```console
|
|
164
|
+
nox -e update
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Upgrade all generated dependencies
|
|
168
|
+
|
|
169
|
+
```console
|
|
170
|
+
nox -e upgrade
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## [pre-commit](https://pre-commit.com)
|
|
176
|
+
|
|
177
|
+
> A framework for managing and maintaining multi-language pre-commit hooks.
|
|
178
|
+
|
|
179
|
+
This repo is setup with a `.pre-commit-config.yaml` with the expectation that
|
|
180
|
+
any code submitted for review already passes all selected pre-commit checks.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Error: File "setup.py" not found
|
|
185
|
+
|
|
186
|
+
Update `pip` to at least version 22.3.1
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: commented-configparser
|
|
3
|
+
Version: 2.1.0
|
|
4
|
+
Summary: Custom ConfigParser class that preserves comments in file when writing
|
|
5
|
+
Author-email: Preocts <preocts@preocts.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Preocts
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: homepage, https://github.com/Preocts/commented-configparser
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
32
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
33
|
+
Requires-Python: >=3.8
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
38
|
+
Requires-Dist: black; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy; extra == "dev"
|
|
40
|
+
Requires-Dist: flake8; extra == "dev"
|
|
41
|
+
Requires-Dist: flake8-builtins; extra == "dev"
|
|
42
|
+
Requires-Dist: flake8-pep585; extra == "dev"
|
|
43
|
+
Provides-Extra: test
|
|
44
|
+
Requires-Dist: pytest; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-randomly; extra == "test"
|
|
46
|
+
Requires-Dist: coverage; extra == "test"
|
|
47
|
+
Requires-Dist: nox; extra == "test"
|
|
48
|
+
|
|
49
|
+
[](https://www.python.org/downloads)
|
|
50
|
+
[](https://github.com/psf/black)
|
|
51
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
52
|
+
|
|
53
|
+
[](https://results.pre-commit.ci/latest/github/Preocts/commented-configparser/main)
|
|
54
|
+
[](https://github.com/Preocts/commented-configparser/actions/workflows/python-tests.yml)
|
|
55
|
+
|
|
56
|
+
# commented-configparser
|
|
57
|
+
|
|
58
|
+
A custom ConfigParser class that preserves comments and option casing when writing loaded config out.
|
|
59
|
+
|
|
60
|
+
This library gives you a custom class of the standard library's `configparser.ConfigParger` which will preserve the comments of a loaded config file when writing that file back out.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Install via pip
|
|
65
|
+
|
|
66
|
+
From pypi:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m pip install commented-configparser
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
From github:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
python -m pip install commented-configparser@git+https://github.com/Preocts/commented-configparser@x.x.x
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Note:** Replace `x.x.x` with the desired tag or branch.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Example use
|
|
83
|
+
|
|
84
|
+
```py
|
|
85
|
+
from commentedconfigparser import CommentedConfigParser
|
|
86
|
+
|
|
87
|
+
# Load the config like normal
|
|
88
|
+
config = CommentedConfigParser()
|
|
89
|
+
config.read("myconfig.ini")
|
|
90
|
+
|
|
91
|
+
# Use the config like normal
|
|
92
|
+
...
|
|
93
|
+
|
|
94
|
+
# Update the config like normal
|
|
95
|
+
...
|
|
96
|
+
|
|
97
|
+
# Save the config back to the file
|
|
98
|
+
with open("myconfig.ini", "w") as savefile:
|
|
99
|
+
config.write(savefile)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Results
|
|
103
|
+
|
|
104
|
+
We favor the line spacing choices of the `ConfigParser` class so the input format may not be preserved completely. However, the comments will be preserved.
|
|
105
|
+
|
|
106
|
+
### Before
|
|
107
|
+
|
|
108
|
+
```ini
|
|
109
|
+
# Welcome to our config
|
|
110
|
+
[DEFAULT]
|
|
111
|
+
# This value has some meaning to someone
|
|
112
|
+
foo=bar
|
|
113
|
+
# Make sure to add this when you need it
|
|
114
|
+
trace=false
|
|
115
|
+
logging=true
|
|
116
|
+
; This is a comment as well
|
|
117
|
+
|
|
118
|
+
# so we need to track all of them
|
|
119
|
+
|
|
120
|
+
; and many could be between things
|
|
121
|
+
[NEW SECTION]
|
|
122
|
+
# Another comment
|
|
123
|
+
multi-line=
|
|
124
|
+
value01
|
|
125
|
+
value02
|
|
126
|
+
value03
|
|
127
|
+
closing=0
|
|
128
|
+
# Trailing comment
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### After
|
|
133
|
+
|
|
134
|
+
```ini
|
|
135
|
+
# Welcome to our config
|
|
136
|
+
[DEFAULT]
|
|
137
|
+
# This value has some meaning to someone
|
|
138
|
+
foo = bar
|
|
139
|
+
# Make sure to add this when you need it
|
|
140
|
+
trace = false
|
|
141
|
+
logging = true
|
|
142
|
+
; This is a comment as well
|
|
143
|
+
# so we need to track all of them
|
|
144
|
+
; and many could be between things
|
|
145
|
+
|
|
146
|
+
[NEW SECTION]
|
|
147
|
+
# Another comment
|
|
148
|
+
multi-line =
|
|
149
|
+
value01
|
|
150
|
+
value02
|
|
151
|
+
value03
|
|
152
|
+
closing = 0
|
|
153
|
+
# Trailing comment
|
|
154
|
+
|
|
155
|
+
```
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
[](https://www.python.org/downloads)
|
|
2
|
+
[](https://github.com/psf/black)
|
|
3
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
4
|
+
|
|
5
|
+
[](https://results.pre-commit.ci/latest/github/Preocts/commented-configparser/main)
|
|
6
|
+
[](https://github.com/Preocts/commented-configparser/actions/workflows/python-tests.yml)
|
|
7
|
+
|
|
8
|
+
# commented-configparser
|
|
9
|
+
|
|
10
|
+
A custom ConfigParser class that preserves comments and option casing when writing loaded config out.
|
|
11
|
+
|
|
12
|
+
This library gives you a custom class of the standard library's `configparser.ConfigParger` which will preserve the comments of a loaded config file when writing that file back out.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Install via pip
|
|
17
|
+
|
|
18
|
+
From pypi:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m pip install commented-configparser
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
From github:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python -m pip install commented-configparser@git+https://github.com/Preocts/commented-configparser@x.x.x
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Note:** Replace `x.x.x` with the desired tag or branch.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Example use
|
|
35
|
+
|
|
36
|
+
```py
|
|
37
|
+
from commentedconfigparser import CommentedConfigParser
|
|
38
|
+
|
|
39
|
+
# Load the config like normal
|
|
40
|
+
config = CommentedConfigParser()
|
|
41
|
+
config.read("myconfig.ini")
|
|
42
|
+
|
|
43
|
+
# Use the config like normal
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
# Update the config like normal
|
|
47
|
+
...
|
|
48
|
+
|
|
49
|
+
# Save the config back to the file
|
|
50
|
+
with open("myconfig.ini", "w") as savefile:
|
|
51
|
+
config.write(savefile)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Results
|
|
55
|
+
|
|
56
|
+
We favor the line spacing choices of the `ConfigParser` class so the input format may not be preserved completely. However, the comments will be preserved.
|
|
57
|
+
|
|
58
|
+
### Before
|
|
59
|
+
|
|
60
|
+
```ini
|
|
61
|
+
# Welcome to our config
|
|
62
|
+
[DEFAULT]
|
|
63
|
+
# This value has some meaning to someone
|
|
64
|
+
foo=bar
|
|
65
|
+
# Make sure to add this when you need it
|
|
66
|
+
trace=false
|
|
67
|
+
logging=true
|
|
68
|
+
; This is a comment as well
|
|
69
|
+
|
|
70
|
+
# so we need to track all of them
|
|
71
|
+
|
|
72
|
+
; and many could be between things
|
|
73
|
+
[NEW SECTION]
|
|
74
|
+
# Another comment
|
|
75
|
+
multi-line=
|
|
76
|
+
value01
|
|
77
|
+
value02
|
|
78
|
+
value03
|
|
79
|
+
closing=0
|
|
80
|
+
# Trailing comment
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### After
|
|
85
|
+
|
|
86
|
+
```ini
|
|
87
|
+
# Welcome to our config
|
|
88
|
+
[DEFAULT]
|
|
89
|
+
# This value has some meaning to someone
|
|
90
|
+
foo = bar
|
|
91
|
+
# Make sure to add this when you need it
|
|
92
|
+
trace = false
|
|
93
|
+
logging = true
|
|
94
|
+
; This is a comment as well
|
|
95
|
+
# so we need to track all of them
|
|
96
|
+
; and many could be between things
|
|
97
|
+
|
|
98
|
+
[NEW SECTION]
|
|
99
|
+
# Another comment
|
|
100
|
+
multi-line =
|
|
101
|
+
value01
|
|
102
|
+
value02
|
|
103
|
+
value03
|
|
104
|
+
closing = 0
|
|
105
|
+
# Trailing comment
|
|
106
|
+
|
|
107
|
+
```
|