How can I get current pants configuration in CLI? ...
# general
s
How can I get current pants configuration in CLI? including defaults
1
e.g. get every config option in
[ruff]
subsystem
w
pants help
or
pants help-all
I think define them
One of the help functions, anyways
https://www.pantsbuild.org/stable/docs/using-pants/command-line-help The example there has the default and current override specified for subsystems and options
s
no, I need the current values, not just help
something like
Copy code
[ruff]
default_version = "0.9.4"
default_known_versions = [
  '0.9.4|macos_arm64 |48927361be76a93dbded0555d374af3172fc4010b54d97347957f6ab509d7e33|11082208',
  '0.9.4|linux_arm64 |a9e880d819f290fc602768d25065c1316401229d04f0efaa7440017459968b11|11878008',
  '0.9.4|macos_x86_64|7abe5ec80ae556fcf445be65825a340df32a8404a28332a988cb97dc65fe60c4|11613907',
  '0.9.4|linux_x86_64|c49af645ed618e660c64cd253892039ff30645e1f1563bc7842918f7cd74d596|12500843',
]
version = "0.9.4"
known_versions = [
  '0.9.4|macos_arm64 |48927361be76a93dbded0555d374af3172fc4010b54d97347957f6ab509d7e33|11082208',
  '0.9.4|linux_arm64 |a9e880d819f290fc602768d25065c1316401229d04f0efaa7440017459968b11|11878008',
  '0.9.4|macos_x86_64|7abe5ec80ae556fcf445be65825a340df32a8404a28332a988cb97dc65fe60c4|11613907',
  '0.9.4|linux_x86_64|c49af645ed618e660c64cd253892039ff30645e1f1563bc7842918f7cd74d596|12500843',
]
I want to see the active values of all options
w
Something like
Copy code
--ruff-config=<file_option>
  PANTS_RUFF_CONFIG
  config
      default: None
      current value: None

  --ruff-url-template=<str>
  PANTS_RUFF_URL_TEMPLATE
  url_template
      default: <https://github.com/astral-sh/ruff/releases/download/{version}/ruff-{platform}.tar.gz>
      current value: <https://github.com/astral-sh/ruff/releases/download/{version}/ruff-{platform}.tar.gz>

  --ruff-version=<str>
  PANTS_RUFF_VERSION
  version
      default: 0.9.6
      current value: 0.9.6
etc?
s
yeah, but in machine readable format like json or smth
it would be nice to have it in toml, so that you could do
Copy code
pants export-current-config > pants.toml
and it would materialize the current config without actually changing anything
w
Like
pants help-all
?
You can get the state of everything there
s
I can't really execute it right now, because we have a bunch of plugins that don't define help, so it refuses to run
Copy code
14:42:54.23 [ERROR] type object 'CueExportPackagesField' has no attribute 'help'
w
Weird, thought that would be a typechecking error
help: ClassVar[str | Callable[[], str]]
s
classvar doesn't force you to define the var
and we have mypy disabled for plugins, because it breaks in py 3.9
w
Alright, well,
help-all
in JSON and piping that into something like
jq
or another tool is typically the way something like this could be done.
pants export-current-config > pants.toml
- pants gets its config from pants.toml, so piping it back in - i guess to dump all the defaults? SchemaStore might also have this information per pants-version - the defaults, anyways
s
ok, thanks. I'll try to fill in
help
and try again
w
👍 Any content would work - just needs to be specified. I think the bug here is that
help
is expected to be populated (I think it's mentioned in the docs, and in tutorials - e.g. https://www.pantsbuild.org/stable/docs/writing-plugins/the-rules-api/options-and-subsystems#defining-options) - but I also thought that pyright or mypy flag when it's not there... So, that's weird.
s
yep, it works! Thank you but I can't find the
current
value, should I use value_history?
h
Yeah, current value is the last in
ranked_values
👍 1
w
In a bit of funny timing, here's a video that just came out on typing abstract classvars

https://www.youtube.com/watch?v=4Ge1mgogwdw

TLDW: Using
Protocol
s
lol, I've just watched it too
Anthony saves the day
w
😆 I'm glad I watched it, because I probably would have gone with the first non-starter approach off the top of my head. I was surprised by the
@property
messing with the mypy check, but 🤷 - I'll take any amount of typing
s
in fact I've implemented a separate small descriptor to avoid
@property
messing up with the value, it's not obvious that Protocol works this way
👍 1