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

Do not interpret passthrough args. (cherrypick of #11656) #11661

Merged
merged 1 commit into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/python/pants/option/options_test.py
Expand Up @@ -1046,6 +1046,27 @@ def test_at_most_one_goal_with_passthru_args(self):
"(args after `--`) is ambiguous."
) in str(exc.value)

def test_passthru_args_not_interpreted(self):
# Test that passthrough args are not interpreted.
options = Options.create(
env={},
config=self._create_config(),
known_scope_infos=[global_scope(), task("test"), subsystem("consumer")],
args=["./pants", "--consumer-shlexed=a", "--consumer-string=b", "test", "--", "[bar]"],
)
options.register(
"consumer", "--shlexed", passthrough=True, type=list, member_type=shell_str
)
options.register("consumer", "--string", passthrough=True, type=list, member_type=str)
self.assertEqual(
["a", "[bar]"],
options.for_scope("consumer").shlexed,
)
self.assertEqual(
["b", "[bar]"],
options.for_scope("consumer").string,
)

def test_global_scope_env_vars(self):
def check_pants_foo(expected_val, env):
val = self._parse(env=env).for_global_scope().pants_foo
Expand Down
8 changes: 7 additions & 1 deletion src/python/pants/option/parser.py
Expand Up @@ -669,7 +669,13 @@ def expand(val_or_str):
# Get value from cmd-line flags.
flag_vals = [to_value_type(expand(x)) for x in flag_val_strs]
if kwargs.get("passthrough"):
flag_vals.extend(to_value_type(x) for x in passthru_arg_strs)
# NB: Passthrough arguments are either of type `str` or `shell_str`
# (see self._validate): the former never need interpretation, and the latter do not
# need interpretation when they have been provided directly via `sys.argv` as the
# passthrough args have been.
flag_vals.append(
ListValueComponent(ListValueComponent.MODIFY, [*passthru_arg_strs], [])
)

if is_list_option(kwargs):
# Note: It's important to set flag_val to None if no flags were specified, so we can
Expand Down