pants icon indicating copy to clipboard operation
pants copied to clipboard

No way to unset an option via CLI and env var

Open Eric-Arellano opened this issue 4 years ago • 6 comments

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?

Eric-Arellano avatar Mar 17 '21 18:03 Eric-Arellano

How about a prefix - that works consistently for env var and flag, say unset. So PANTS_UNSET_CONFIG_FILES or --unset-pants-config-files.

jsirois avatar Mar 17 '21 18:03 jsirois

Gr, this is blocking the fix for https://github.com/pantsbuild/pants/issues/12457#issuecomment-893749711.

Eric-Arellano avatar Aug 05 '21 20:08 Eric-Arellano

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 avatar Feb 06 '23 04:02 AlexTereshenkov

@AlexTereshenkov you have misread. The OP is not about bools, it's about optionals.

jsirois avatar Feb 06 '23 04:02 jsirois

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.

AlexTereshenkov avatar Feb 06 '23 04:02 AlexTereshenkov

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.

github-actions[bot] avatar Dec 02 '25 04:12 github-actions[bot]