beetbox / beetbox/confuse

Dumping changes to a config.yaml file places changed lines at the beginning

Open
#100 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
424
Forks
57
PR merge metrics
No merged PRs in 30d

Description

As the title says, when I make a change to some of the config variables and dump it to the config.yaml file, the edited variables are now inserted at the very top of the file rather than the position they used to be in. This is especially frustrating when the config file is "supposed" to start with a few lines of comments indicating authorship and explanations for new users.

## OS and versions
OS: Ubuntu 18.04
Python: 3.8.2 64-bit
confuse: 1.1.0

## Steps to reproduce

1. Create a config.yaml with some leading comments and some parameters on the following lines
2. load a config.yaml file
3. read a parameter from the file
4. change the parameter
5. dump the edited configuration to config.yaml
6. open config.yaml in a text editor

## Example config.yaml

```yaml
############################################
# AAA_image_segmentation #
# Config file #
# Author: Bjarne Thorsted #
# e-mail: bt*******@************* #
############################################

appName: AAAml
# Usage instructions:
...
active_labels: [2, 3, 4, 5]
```
## Example python script
```python
import os
import confuse

os.environ['AAAMLDIR'] = os.curdir

config = confuse.Configuration("AAAml")
config.sources[0].default = True

active_labels = config["active_labels"].get()
config["active_labels"].set([2, 3])

with open("config copy.yaml", mode="w") as cfg_file:
cfg_file.write(config.dump())

with open("config copy.yaml", mode="r") as cfg_file:
print(cfg_file.read())

```
### console output:
```yaml
active_labels: [2, 3]
############################################
# AAA_image_segmentation #
# Config file #
# Author: Bjarne Thorsted #
# e-mail: bt*******@************* #
############################################

appName: AAAml
# Usage instructions:
...
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.