yamlpath icon indicating copy to clipboard operation
yamlpath copied to clipboard

Deleting keys deletes post-comment instead of pre-comment

Open wwkimball opened this issue 2 years ago • 2 comments

Operating System

  1. Name/Distribution: ANY
  2. Version: ANY

Version of Python and packages in use at the time of the issue.

  1. Distribution: ANY
  2. Python Version: ANY Supported
  3. Version of yamlpath installed: 3.6.4
  4. Version of ruamel.yaml installed: ANY Supported

Minimum sample of YAML (or compatible) data necessary to trigger the issue

---
# test.yaml
key1: value1

# Pre-comment
remove_this: key

# Post-comment
keep_this: other key

Complete steps to reproduce the issue when triggered via:

  1. yaml-set --delete --change=/remove_this test.yaml

Expected Outcome

---
# test.yaml
key1: value1

# Post-comment
keep_this: other key

Actual Outcome

---
# test.yaml
key1: value1

# Pre-comment
keep_this: other key

As you can see, the Pre-comment was preserved while both the post-comment and all whitespace after the target key was deleted.

Screenshot(s), if Available

wwkimball avatar Sep 02 '22 22:09 wwkimball

This is a known issue with how ruamel.yaml handles comments (ca objects). Having said that, yamlpath should be able to compensate for this unexpected behavior.

wwkimball avatar Sep 02 '22 22:09 wwkimball

The author of ruamel.yaml has indicated that I really should wait for the next release of his package before I tackle comment handling like this. Comments are complex, internal, and the API will be entirely unpredictable until he's done with his rewrite. So, for now, I'm shelving this.

wwkimball avatar Jan 16 '23 17:01 wwkimball