Simplify handling of command line arguments. #2028
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Python 3.12.7 modified the handling of command line arguments in a way that broke Briefcase's handling of arguments that take values (e.g.,
-C <config=value>
,-d <device>
, etc).Briefcase's command line handling pushes argparse to its limits, performing 2 partial parsing passes of arguments before all options have been registered, when the full parsing pass can be performed.
The second pass in particular is a problem, because it involves 2 optional positional arguments; and prior to formally registering options, there's no way to tell the difference between a positional argument, and an option that takes a value. We have been inadvertently relying on a behavior of argparse that stopped processing positional arguments once an option was discovered. That behavior has changed in 3.12.7 (which will also be in 3.13.1), but it's hard to argue that the way we were using argparse was "correct" behaviour.
Instead of trying to use a partial parser on an incomplete argument set, this PR interrogates the arguments for platform and output format directly. This requires that platform and format, if provided, are the first and second arguments after the command... but that was already a requirement -
briefcase run -d "iPhone 15 Pro" iOS
would be rejected using the old code.The only difference in behaviour is that the error raised by
briefcase run foobar
now raises a custom error, rather than an argparse error about the invalid platform. Invalid format names were already handled as custom errors.Fixes #2026
PR Checklist: