question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discuss: How to avoid rewriting the full config file

See original GitHub issue

I’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:

  1. Update the version in the config file, but don’t rewrite the whole file.
  2. Rely on setup.cfg version.
  3. Rely on the version found in the first bumpversion:file: section.
  4. Don’t update the config file unless the user configures bump2version to do it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
florislacommented, Jan 25, 2021

Proposal:

  • If version is present, use it and replace it like you would a regular file. Don’t rewrite the full config file.
  • If metadata.version is present in setup.cfg, use it and replace it similarly.
  • If none of both is present, simply assume that the first file section defined contains the full version number.`

Whether to modify metadata.version should be configurable. The default may be either of

  • Modify if it’s present.
  • Modify if it’s present and bump2version is configured in the same setup.cfg file.
  • Only modify it if requested.

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.

0reactions
tandavcommented, Oct 8, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found