Conversation
-t is declared with nargs="+", so it takes a space-separated list and argparse stores it with the default "store" action. A second occurrence replaces the first rather than appending, so `-t pre_process -t simulation` parses to just [simulation] and the generated batch script runs simulation against an empty restart_data/ -- with nothing in the output saying a target was dropped. Warn when a list-valued flag appears more than once. The check walks the CLI schema for every argument declared nargs="+"/"*" (including those inherited through include_common), so --gpus and --only are covered too, not just -t. Parsing behaviour is deliberately unchanged: the warning is advisory.
Member
|
doesn't use pr template |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
-tis declared withnargs="+", so argparse registers it with the defaultstoreaction. A second occurrence of the flag doesn't append to the first — it replaces it.-t pre_process -t simulationtherefore parses to['simulation'], and the generated batch script has one fewer step than the user wrote, with nothing printed to say so.Confirmed against the real generated parser (
cli/argparse_gen.generate_parseroverMFC_CLI_SCHEMA, which is whatargs.parseuses):targets-t simulation['simulation']-t pre_process simulation['pre_process', 'simulation']-t pre_process -t simulation['simulation']--targets pre_process --targets simulation['simulation']-t pre_process -t simulation -t post_process['post_process']On the two suggested fixes
The issue offered either a warning or
action="extend". I went with the warning, but only after testingextend— it turns out to be actively wrong here, becausetargetshas a non-empty list default:action="extend"-t simulation['simulation']['pre_process', 'simulation', 'post_process', 'simulation']-t pre_process simulation['pre_process', 'simulation']['pre_process', 'simulation', 'post_process', 'pre_process', 'simulation']extendappends to the default rather than replacing it, so-t simulationwould silently start running all three targets — it converts a quiet drop into a quiet addition, which is worse:-t simulationis the restart-from-existing-data invocation, and the whole point of passing it is not to re-runpre_process. Every-tcall site in the repo (test/case.py,test/convergence.py,bench.py) would be affected too. So: warning only, and parsing behaviour is left exactly as it is.What the fix does
_warn_on_repeated_multi_value_flagscounts occurrences of each list-valued flag incli_argvand prints a yellow note when one appears more than once. It's driven off the CLI schema rather than a hardcoded-t:_multi_value_flagswalks the command's ownargumentsplus everything it pulls in throughinclude_common, and yields any argument declarednargs="+"or"*". That means--gpusand--onlyare covered by the same check — they have the identical shape and the identical failure mode — and any futurenargs="+"option is covered automatically. Short/long/=spellings all count toward the same option.End to end, on the exact command from the report:
The banner underneath still reads
--targets simulation, which is the behaviour the warning is there to explain.Testing
toolchain/mfc/test_args_repeated_flags.py— 16 tests covering the repeated short form, the long form, mixed spellings, the=form, three repeats,targetsreachingbuildviainclude_common,--gpus, and the schema walk itself. The silent controls matter as much as the warnings:-t pre_process simulation,-t simulation, and no flag at all must all stay quiet, and one test assertsparse()still returns argparse's unmodified result.RED→GREEN was proved in a throwaway worktree with
args.pyrestored fromupstream/masterand the tests copied in — using a behavioural test that imports only names present on upstream, so it runs identically on both sides:The 2 that pass on both sides are the controls (intended form, single target) — they confirm the failure is the dropped-target case specifically and not a broken harness.
Both CI gates, re-run against the committed SHA with a clean tree:
./mfc.sh linttest-toolchain-compat.yml./mfc.sh precheck -j 4lint-toolchain.ymlFixes #1875