Package: commented-configparser
commented-configparserA custom ConfigParser class that preserves comments when writing loaded config out.This library gives you a custom class of the standard library'sconfigparser.ConfigPargerwhich will preserve the comments of a loaded config file when writing that file back out.Install via pipFrom pypi:python-mpipinstallcommented-configparserFrom github:python-mpipinstallcommented-configparser@git+https://github.com/Preocts/commented-configparser@mainNote:Replacemainwith the desired tag or branch.  This can be placed in arequirements.txtfile as well.Example usefromcommentedconfigparserimportCommentedConfigParser# Load the config like normalconfig=CommentedConfigParser()config.read("myconfig.ini")# Use the config like normal...# Update the config like normal...# Save the config back to the filewithopen("myconfig.ini","w")assavefile:config.write(savefile)ResultsWe favor the line spacing choices of theConfigParserclass so the input format may not be preserved completely. However, the comments will be preserved.Before# Welcome to our config[DEFAULT]# This value has some meaning to someonefoo=bar# Make sure to add this when you need ittrace=falselogging=true; This is a comment as well# so we need to track all of them; and many could be between things[NEW SECTION]# Another commentmulti-line=value01value02value03closing=0# Trailing commentAfter# Welcome to our config[DEFAULT]# This value has some meaning to someonefoo=bar# Make sure to add this when you need ittrace=falselogging=true; This is a comment as well# so we need to track all of them; and many could be between things[NEW SECTION]# Another commentmulti-line=value01value02value03closing=0# Trailing commentLocal developer installationIt isstronglyrecommended to use a virtual environment
(venv) when working with python
projects. Leveraging avenvwill ensure the installed dependency files will
not impact other python projects or any system dependencies.The following steps outline how to install this repo for local development. See
theCONTRIBUTING.mdfile in the repo root for information on
contributing to the repo.Windows users: Depending on your python install you will usepyin place
ofpythonto create thevenv.Linux/Mac users: Replacepython, if needed, with the appropriate call to
the desired version while creating thevenv. (e.g.python3orpython3.8)All users: Once inside an activevenvall systems should allow the use ofpythonfor command line instructions. This will ensure you are using thevenv's python and not the system level python.Installation stepsClone this repo and enter root directory of repo:$gitclonehttps://github.com/Preocts/commented-configparser$cdcommented-configparserCreate thevenv:$python-mvenvvenvActivate thevenv:#Linux/Mac$.venv/bin/activate#Windows$venv\Scripts\activateThe command prompt should now have a(venv)prefix on it.pythonwill now
call the version of the interpreter used to create thevenvInstall editable library and development requirements:#Updatepipandtools$python-mpipinstall--upgradepip#Installeditableversionoflibrary$python-mpipinstall--editable.[dev]Install pre-commit(see below for details):$pre-commitinstallMisc StepsRun pre-commit on all files:$pre-commitrun--all-filesRun tests:$tox[-r][-epy3x]Build dist:$python-mpipinstall--upgradebuild$python-mbuildTo deactivate (exit) thevenv:$deactivateNote on flake8:flake8is included in therequirements-dev.txtof the project. However it
disagrees withblack, the formatter of choice, on max-line-length and two
general linting errors..pre-commit-config.yamlis already configured to
ignore these.flake8doesn't supportpyproject.tomlso be sure to add the
following to the editor of choice as needed.--ignore=W503,E203--max-line-length=88pre-commitA framework for managing and maintaining multi-language pre-commit hooks.This repo is setup with a.pre-commit-config.yamlwith the expectation that
any code submitted for review already passes all selected pre-commit checks.pre-commitis installed with the development requirements and runs seemlessly
withgithooks.MakefileThis repo has a Makefile with some quality of life scripts if the system
supportsmake.  Please note there are no checks for an activevenvin the
Makefile.PHONYDescriptioninitUpdate pip to newest versioninstallinstall the projectinstall-devinstall development/test requirements and project as editable installupgrade-devupdate all dependencies, regenerate requirements.txt (disabled by default)build-distBuild source distribution and wheel distributioncleanDeletes build, tox, coverage, pytest, mypy, cache, and pyc artifacts