Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify handling of command line arguments. #2028

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

freakboy3742
Copy link
Member

@freakboy3742 freakboy3742 commented Oct 14, 2024

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:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@mhsmith mhsmith merged commit 63f7260 into beeware:main Oct 14, 2024
52 checks passed
@freakboy3742 freakboy3742 deleted the cmdline-cleanup branch October 15, 2024 00:04
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.

Handling of options with values broken by Python 3.12.7
2 participants