Skip to content

Commit

Permalink
Correct handling of arguments that take values.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Oct 14, 2024
1 parent c11a391 commit ac7f5d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/2026.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 3.12.7 introduced an incompatibility with the handling of ``-C``, ``-d`` and other flags that accept values. This incompatibility has been corrected.
16 changes: 15 additions & 1 deletion src/briefcase/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,23 @@ def normalize(name):
return {n.lower(): n for n in platforms.keys()}.get(name.lower(), name)

# argparse handles `--` specially, so make the passthrough args bypass the parser.
# Also remove from partial processing any flag that is followed by a non-flag
# argument. This is required because we are partially processing arguments *before*
# declaring those arguments; that means we need to be able to parse `-X foobar` as a
# 2-part argument before actually defining the existence of `-X`. See
# beeware/briefcase#2026.
def parse_known_args(args):
args, passthrough = split_passthrough(args)
options, extra = parser.parse_known_args(args)
simple_args = []
complex_args = []
while args:
arg = args.pop(0)
if arg.startswith("-") and args and not args[0].startswith("-"):
complex_args.extend([arg, args.pop(0)])
else:
simple_args.append(arg)
options, extra = parser.parse_known_args(simple_args)
extra += complex_args
if passthrough:
extra += ["--"] + passthrough
return options, extra
Expand Down
2 changes: 1 addition & 1 deletion src/briefcase/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def split_passthrough(args):
try:
pos = args.index("--")
except ValueError:
return args, []
return args[:], []
else:
return args[:pos], args[pos + 1 :]

Expand Down

0 comments on commit ac7f5d6

Please sign in to comment.