Discuss: How to avoid rewriting the full config file
See original GitHub issueI’m not a fan of rewriting config files.
Feedback we had in various issues shows it’s
- ugly (it moves sections around, can affect newlines and whitespace)
- inconvenient (it introduces source control changes in places where it should not)
- dangerous (it drops comments!)
- probably unnecessary
See for example #62, #83, #87, #90, #94, #161, #163, #169, #201, #207, #217, #228. How are we going to solve this? Various things we can do:
- Update the version in the config file, but don’t rewrite the whole file.
- Rely on setup.cfg
version
. - Rely on the version found in the first
bumpversion:file:
section. - Don’t update the config file unless the user configures bump2version to do it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to Write a Configuration file in Python | by Xiaoxu Gao
A good configuration file should meet at least these 3 criteria: Easy to read and edit: It should be text-based and structured in...
Read more >What is a config file? - Opensource.com
Use Python to parse configuration files The first step is choosing a configuration format: INI, JSON, YAML, or TOML.
Read more >Config Files and Logging - Medium
One of the ways to ensure that there is minimal hard-coding is to use config files. Config files are used to save the...
Read more >Keeping comments after reading, changing and writing config ...
I'm very new in Python and I need to modify a configuration file. I'm able to do so using configparser but the problem...
Read more >Techniques for reading and writing application configuration ...
A configuration file is a (usually small) file that contains information about a number of options that control the appearance or behavior of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Proposal:
version
is present, use it and replace it like you would a regular file. Don’t rewrite the full config file.metadata.version
is present insetup.cfg
, use it and replace it similarly.file
section defined contains the full version number.`Whether to modify
metadata.version
should be configurable. The default may be either ofsetup.cfg
file.The latter is most compatible with current behavior, but the middle option seems more intuitive.
This takes care of whitespace issues, newline issues, dropped comments, double version definitions in
setup.cfg
, and redundant version definition in any config file.I solved this issue by switching to bumpver. Nice package which is not listed in RELATED.md alternatives. It supports
setup.cfg
and does not rewrites it, no whitespace issues.