I am trying to read options from a `.json` file in...
# general
q
I am trying to read options from a
.json
file into my
pants.toml
file but it doesn't seem to be working. For example:
Copy code
# pants.toml
[python.resolves]
pants-plugins = "@?pantsbuild/pants-plugins-config.json"

[python.resolves_to_interpreter_constraints]
pants-plugins = "@?pantsbuild/pants-plugins-config.json"

# pants-plugins-config.json
{
    "resolves.pants-plugins": "SOME_PATH/pants-plugins.lock",
    "resolves_to_interpreter_constraints.pants-plugins": ["==3.9.*"]
}
This creates the
pants-plugins
resolve in
@?pantsbuild/...
meaning is it not parsing the file and it is just taking the string literally. Same issue with
resolves_to_interpreter_constraints.pants-plugins
Reference: https://www.pantsbuild.org/2.21/docs/using-pants/key-concepts/options#reading-individual-option-values-from-files
b
Hm, that's a bit peculiar. Can you create a reduced/standalone reproducer of the problem? In any case, even if we work out how to get it to read a file correctly... I think the file is expected to contain the option value itself, not some repeat of the
pants.toml
option structure. I think this means it would need to be something like: `pants.toml`:
Copy code
# pants.toml
[python.resolves]
pants-plugins = "@?pantsbuild/pants-plugins-resolves.txt"

[python.resolves_to_interpreter_constraints]
pants-plugins = "@?pantsbuild/pants-plugins-interpreter-constraints.json"
`pantsbuild/pants-plugins-resolves.txt`:
Copy code
SOME_PATH/pants-plugins.lock
pantsbuild/pants-plugins-interpreter-constraints.json
Copy code
["==3.9.*"]
However, it seems a bit strange to use files for such small options, instead of just putting them in
pants.toml
directly. Can you give more background on what you're trying to achieve?
q
Hi, my team wanted to move the pants-plugins config settings to a separate file and not keep it in the main pants.toml file. I will try the change you suggested and let you know if it works! thank you!
b
Do you have more background on why it's useful to have it in a separate file? I'm asking because maybe there's either (a) a better way to achieve the same goal, (b) some improvements we can make to pants to make it easier.