Skip to content

Support multiple -o/--outfile flags in a single invocation - #423

Open
ryan-crabbe wants to merge 2 commits into
joerick:mainfrom
ryan-crabbe:multiple-outfiles
Open

Support multiple -o/--outfile flags in a single invocation#423
ryan-crabbe wants to merge 2 commits into
joerick:mainfrom
ryan-crabbe:multiple-outfiles

Conversation

@ryan-crabbe

Copy link
Copy Markdown

Summary

  • Change -o/--outfile to accept multiple values via action="append", so users can write multiple output formats in one invocation
  • Each outfile infers its renderer from the file extension (unless -r is explicitly set, which applies to all)
  • No -o or single -o behavior is unchanged
  • Adds tests for multiple outfiles, single outfile, explicit renderer with multiple outfiles, and unrecognized extension error

Closes #422

Allow users to specify -o multiple times to generate multiple output
formats in one run, e.g.:

    pyinstrument -o output.txt -o output.html script.py

Each outfile infers its renderer from the file extension unless -r is
explicitly set. Single -o and no -o behavior is unchanged.

Closes joerick#422
@joerick

joerick commented Jul 29, 2026

Copy link
Copy Markdown
Owner

I like the idea, but I don't like the change to existing behaviour - previously the -r option took precidence over the file extension to determine format.

Perhaps one way to fix this would be to also allow multiple -r commands, so that,

  • if there's one, we use the current behaviour (all outfiles use that renderer)
  • if there's more than one, each -r affects the following -o outfile arguments.
  • when no -r is passed, we use the file extension.

The other (maybe more punative way) would be to just disallow -r when using multiple outfiles. This might be preferable if the code complexity to acheive the above is too high.

It would also be good to make sure we're documenting the outfile extension inferring behaviour in the --help output - as we increasingly use file extension to determine format, we need to make sure the docs and helptext explain this (and make the various formats discoverable).

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.

Support multiple -o/--outfile flags in a single invocation

2 participants