feat: order changelog tabs based on importance#1198
Conversation
SMoraisAnsys
left a comment
There was a problem hiding this comment.
Very great job @moe-ad Thanks for handling all those problems at once.
Regarding your comment "What this meant was that although changes would have been localized to the towncrier section, some style information is now lost. These are best demonstrated via examples:" I'm not sure to follow you. Do you mean that using your approach will lead to the pyproject.toml file always being rewritten or only for cases where the section content is missing ?
While the TOML content should be updated in a PR and therefore users could always add back the removed comments, I think moving to tomlkit makes sense. Also, the work around the tiny drawback related to the sort/reverse operation is not that hard to understand. Adding a reference to the problem might be wise for future maintenance though :)
I left some minor comments.
Thanks for the review @SMoraisAnsys. What I meant by my statement is that without the hack in c2880fd, there would have been slight differences between the style of what In summary, the implementation in this PR retains the style in the original pyproject.toml, even the comments. See the file changes in the test cases. |
|
Thanks @moe-ad I'll let other give their opinion but it seems fine to me. Great job ! |
Closes #705.
Context
As I began working on this, some connected problems were identified and I think it makes sense to outline those first.
Problem one
tomlformatting tools (usually https://github.com/tox-dev/pyproject-fmt pre-commit hook from my observation), there is now a style difference in the array of tables representing towncrier fragment types among projects. Examples:doc-changelogaction's current implementation only adds new types according to the first style. This means the addition of a new default fragment type (like "breaking") to the default configuration would result in modifications with style inconsistencies for projects likepyansys-geometrythat have diverged from the default style. In summary:Problem two
doc-changelogaction file edits are via direct file writes. While this has been sufficient before now (since we were only doing append operations), editing files in-place makes this approach infeasible. This means we need to do file writes much more programmatically.Problem three
tomli_wfor the file writing operations (since we already use its counterparttomlifor parsing).tomli_w:tomlidoes not preserve style information after parsing,tomli_woutput will have a style that is different from the original configuration file. This means limiting edits to the towncrier section is not possible (which is what thedoc-changelogaction should do when it needs to edit files).tomlialso doesn't preserve comments upon parsing, meaning the output oftomli_wwould have discarded all comment information that was initially present in the configuration file. See the image that follows to better understand the problem.Proposed solution
Caveats
tomlkitcontainer types in-place (by design, see Sorting an Array doesn't persist python-poetry/tomlkit#233 for example) due to the need to preserve style. So during the sort, I essentially needed to construct this container types from scratch (see the initial implementation ofsort_towncrier_typesin this diff).Final tests
banditsection after the towncrier section, which is a good edge case to test against)