A custom ConfigParser class that preserves comments and most formatting when writing loaded config out.
Project description
commented-configparser
A custom ConfigParser class that preserves comments and most formatting when writing loaded config out.
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.
Install via pip
From pypi:
python -m pip install commented-configparser
From github:
python -m pip install commented-configparser@git+https://github.com/Preocts/commented-configparser@x.x.x
Note: Replace x.x.x with the desired tag or branch.
Example use
from commentedconfigparser import CommentedConfigParser
# Load the config like normal
config = CommentedConfigParser()
config.read("myconfig.ini")
# Use the config like normal
...
# Update the config like normal
...
# Save the config back to the file
with open("myconfig.ini", "w") as savefile:
config.write(savefile)
Results
There is the attempt to retain the original format. Known formats that will not be preserved:
- Indents will not be preserved outside of multi-line values
- Spacing around assignments will be normalized.
Before
# Welcome to our config
[DEFAULT]
# This value has some meaning to someone
foo=bar
# Make sure to add this when you need it
trace=false
logging=true
; This is a comment as well
# so we need to track all of them
; and many could be between things
[NEW SECTION]
# Another comment
multiLine=
value01
value02
value03
closing=0
# Trailing comment
After
# Welcome to our config
[DEFAULT]
# This value has some meaning to someone
foo = bar
# Make sure to add this when you need it
trace = false
logging = true
; This is a comment as well
# so we need to track all of them
; and many could be between things
[NEW SECTION]
# Another comment
multiLine =
value01
value02
value03
closing = 0
# Trailing comment
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file commented_configparser-3.0.0.tar.gz.
File metadata
- Download URL: commented_configparser-3.0.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dabdfc94f1166200ad3df3ddfc6d17a2902a554b773bc6f81101202dbf0ff457
|
|
| MD5 |
acacc52744306c5beb17fe0a327fef94
|
|
| BLAKE2b-256 |
403594a7f1ea8fe228c703460ed6726919f31dded615729670fb807fc843fa3c
|
Provenance
The following attestation bundles were made for commented_configparser-3.0.0.tar.gz:
Publisher:
pypi-publish.yml on Preocts/commented-configparser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
commented_configparser-3.0.0.tar.gz -
Subject digest:
dabdfc94f1166200ad3df3ddfc6d17a2902a554b773bc6f81101202dbf0ff457 - Sigstore transparency entry: 246024658
- Sigstore integration time:
-
Permalink:
Preocts/commented-configparser@c459d02a9dd4d1185517f5d9b0e46216eb57254a -
Branch / Tag:
refs/tags/3.0.0 - Owner: https://github.com/Preocts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@c459d02a9dd4d1185517f5d9b0e46216eb57254a -
Trigger Event:
release
-
Statement type:
File details
Details for the file commented_configparser-3.0.0-py3-none-any.whl.
File metadata
- Download URL: commented_configparser-3.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b8a9cac3e6fe0f9301ec8bc54f6d7ddb83da6e3f4d18dbd15459364f5166ab6
|
|
| MD5 |
0950f310afb317f973f04bf1724b0d88
|
|
| BLAKE2b-256 |
d981dfc2b8a565a7a3178e696e94ec444d98bf75ad2a2a717c7c00688e327359
|
Provenance
The following attestation bundles were made for commented_configparser-3.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on Preocts/commented-configparser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
commented_configparser-3.0.0-py3-none-any.whl -
Subject digest:
3b8a9cac3e6fe0f9301ec8bc54f6d7ddb83da6e3f4d18dbd15459364f5166ab6 - Sigstore transparency entry: 246024660
- Sigstore integration time:
-
Permalink:
Preocts/commented-configparser@c459d02a9dd4d1185517f5d9b0e46216eb57254a -
Branch / Tag:
refs/tags/3.0.0 - Owner: https://github.com/Preocts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@c459d02a9dd4d1185517f5d9b0e46216eb57254a -
Trigger Event:
release
-
Statement type: