Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve Yaml structure #3

Closed
TenKenZero opened this issue May 23, 2023 · 4 comments
Closed

Preserve Yaml structure #3

TenKenZero opened this issue May 23, 2023 · 4 comments

Comments

@TenKenZero
Copy link
Contributor

Currently, the application is changing the order of the YAML file's content when it introduces the description block.

This is the original YAML file:
issue3-1

This is the modified YAML with the documentation generated by the app:
issue3-2

We need to add the description section after the name one and keep the other sections in the same order they had before running the app.

@munish7771
Copy link
Contributor

Looks like an issue with yaml.safe_load() call to read yaml file into python dict.

There are two possible resolutions here -

  1. use yaml.load(), which preserves the order in yaml file. But should not be used with untrusted data.
  2. creating own implementation of yaml.safe_load to preserve the order of yaml file.

Going with the 2nd approach as it looks safe.

@munish7771
Copy link
Contributor

So, the issue was while writing to yaml file. Introduced a new dependency ruamel.yaml just for write.

ruamel.yaml - to write to yaml file, preserves the order of keys.
PyYaml - to read the yaml file (existing flow). Wanted to remove this and use ruamel.yaml but don't feel confident since there are no test cases to validate.

@munish7771
Copy link
Contributor

@TenKenZero can we close this as well? since its fixed now.

@TenKenZero
Copy link
Contributor Author

Yes!
I'll do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants