No way to unset an option via CLI and env var
We have several options that are optional, like str | None. If the option is set via a config file, the only way to unset it is to modify the config file - there is no CLI or env var override. --opt='' sets to the empty string. --opt=None sets to the string "None".
It's not clear how this should be modeled? Should we special case None to be None instead of the empty string? How, then, would you get the string value?
How about a prefix - that works consistently for env var and flag, say unset. So PANTS_UNSET_CONFIG_FILES or --unset-pants-config-files.
Gr, this is blocking the fix for https://github.com/pantsbuild/pants/issues/12457#issuecomment-893749711.
Unless I have misinterpreted the issue, this is now possible with the --no-* syntax, see https://www.pantsbuild.org/docs/options#boolean-values:
$ rg tailor_pex_binary_targets pants.toml
29:tailor_pex_binary_targets = true
$ ./pants tailor --check ::
Would update cheeseshop/cli/BUILD:
- Add pex_binary target cli0
To fix `tailor` failures, run `./pants tailor`.
$ ./pants tailor --no-python-tailor-pex-binary-targets --check ::
<no-output>
$ export PANTS_PYTHON_TAILOR_PEX_BINARY_TARGETS=false; ./pants tailor --check ::
<no-output>
@AlexTereshenkov you have misread. The OP is not about bools, it's about optionals.
Ah @jsirois, I am very sorry, thanks for reopening.
I see now what this ticket is about:
[tailor]
build_file_name = "BUILD.pants"
You can override:
$ ./pants tailor --build-file-name='BUILD.mine' --check ::
Would create cheeseshop/cli/BUILD.mine:
- Add python_sources target cli
To fix `tailor` failures, run `./pants tailor`.
but you cannot "unset" whatever is set to pants.toml to switch to the defaults:
./pants tailor --build-file-name='' --check ::
04:17:08.11 [ERROR] 1 Exception encountered:
ValueError: The option `[tailor].build_file_name` is set to ``, which is not compatible with
`[GLOBAL].build_patterns`: ['BUILD', 'BUILD.*']. This means that generated BUILD files would be ignored.
To fix, please update the options so that they are compatible.
This issue has been open for over one year without activity and is not labeled as a bug. It has been labeled as stale to invite any further updates. If you can confirm whether the issue is still applicable to the latest version of Pants, appears in other contexts, or its priority has changed, please let us know. Please feel free to close this issue if it is no longer relevant.