Add planemo format command#1617
Conversation
Uses the same lxml indent + pretty_print logic as the Galaxy Language Server formatter, but as a CLI command so it can be used outside VSCode. Supports --dry-run to preview changes and --recursive for subdirectories.
|
Do comments remain intact ? |
|
@mvdbeek I'll verify. Should be the same logic the language server uses (and down the road maybe we should consolidate that formatting to planemo, which it then in turn uses?). |
|
Comments do survive. I'll add test coverage here for the command as well -- I just needed to get this working first so I didn't have to open vscode to use the language server ;) |
Covers formatting, dry-run, idempotency, comment preservation, CDATA preservation, directory scanning, invalid XML handling, and formatting an existing test tool fixture.
|
Yes, we should probably move that function to |
|
If we want to move formatting into galaxy-tool-util, I've got a branch ready for that: https://github.com/dannon/galaxy/tree/feature/tool-util-format-xml — adds That said, I'm not totally sure tool XML formatting actually belongs in Galaxy proper. Happy to go either way though. Also, the CI failure here is unrelated — it's |
I also don't know for sure, but it is certainly a "utility to make Galaxy Tools consistent", so... at least the domain definitely matches |
|
@davelopez Works for me, I'll open the PR and we can see where it goes. I guess we probably want to merge this as-is and can easily swap it over once there's a published version of tool-util with the formatting. |
Summary
Adds a
planemo formatcommand that reformats Galaxy tool XML files with consistent indentation usinglxml.etree.indent+pretty_print— the same logic the Galaxy Language Server uses for format-on-save, but available as a CLI command.--recursiveand--dry-run(show diff without writing).xmlfile discovery (not limited to<tool>root elements, so it also handles macros files)--tab-sizeoption (default 4 spaces)Motivation
The Galaxy Language Server handles XML formatting nicely in VSCode, but there's no CLI equivalent for batch formatting or CI use. This came up on tools-iuc#7680 where consistent formatting was requested across a set of tool XMLs.
Test plan
planemo format --dry-run <tool_dir>shows unified diff of what would changeplanemo format <tool_dir>rewrites files, second run is a no-opplanemo lintstill passes after formatting