Skip to content

Add planemo format command#1617

Merged
dannon merged 3 commits intogalaxyproject:masterfrom
dannon:feature/format-command
Feb 27, 2026
Merged

Add planemo format command#1617
dannon merged 3 commits intogalaxyproject:masterfrom
dannon:feature/format-command

Conversation

@dannon
Copy link
Member

@dannon dannon commented Feb 20, 2026

Summary

Adds a planemo format command that reformats Galaxy tool XML files with consistent indentation using lxml.etree.indent + pretty_print — the same logic the Galaxy Language Server uses for format-on-save, but available as a CLI command.

  • Accepts tool paths, supports --recursive and --dry-run (show diff without writing)
  • Uses simple glob-based .xml file discovery (not limited to <tool> root elements, so it also handles macros files)
  • --tab-size option (default 4 spaces)
  • No new dependencies (lxml is already available via galaxy-tool-util)

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 change
  • planemo format <tool_dir> rewrites files, second run is a no-op
  • planemo lint still passes after formatting
  • CDATA sections (command, help) survive intact

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.
@mvdbeek
Copy link
Member

mvdbeek commented Feb 20, 2026

Do comments remain intact ?

@dannon
Copy link
Member Author

dannon commented Feb 20, 2026

@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?).

@dannon
Copy link
Member Author

dannon commented Feb 20, 2026

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 ;)

@dannon dannon marked this pull request as draft February 20, 2026 15:11
Covers formatting, dry-run, idempotency, comment preservation, CDATA
preservation, directory scanning, invalid XML handling, and formatting
an existing test tool fixture.
@davelopez
Copy link

Yes, we should probably move that function to tool_util package, then planemo and the language server can directly use it

@dannon dannon marked this pull request as ready for review February 20, 2026 15:56
@dannon
Copy link
Member Author

dannon commented Feb 20, 2026

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 format_xml to galaxy.tool_util.format with tests. Once that ships in a tool-util release, swapping the import here would be trivial.

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 test_autoupdate_workflow_from_multiple_tool_sheds failing on a tool shed version check. All format tests pass.

@davelopez
Copy link

That said, I'm not totally sure tool XML formatting actually belongs in Galaxy proper. Happy to go either way though.

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 tool-util 😅
I will consider it similar to the lint module, which is not directly used by Galaxy but by other tooling downstream.

@dannon
Copy link
Member Author

dannon commented Feb 23, 2026

@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.

@dannon dannon merged commit 7d421a0 into galaxyproject:master Feb 27, 2026
14 of 15 checks passed
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

Successfully merging this pull request may close these issues.

3 participants