Hey all :wave: Is there any way to specify custom ...
# plugins
a
Hey all 👋 Is there any way to specify custom plugins version in a different file other than pants.toml? Possibly a .txt file? We're implementing custom plugins as python packages and we'd want tools like dependabot to be able to open PR's upticking the plugin version when there are new releases of our plugins, but dependabot is not able to read the pants.toml file and search for new releases for the custom plugins.
I'm aware that we could not fix a version for the plugin, and it would always use the latest, but that would not be safe when major releases were out.
h
You can have the value of any option live in a file, and point to it in config via
@path/to/file
. I'm not sure if this will work for plugins though, as those are needed at bootstrap time and I'm not sure we process that early enough, but worth a try?
The format of the file is determined by its suffix, e.g.,
.json
, `.yml`/`.yaml`, or anything else is just used as-is
a
Thanks for the response. I've tried that and it works if I have just one dependency in the
.txt
file, when I have multiple, the pants setup fails because the dependencies are read as a single line, even tho each dependency are on different lines. e.g. if I have this
.txt
file:
Copy code
foo==0.0.1
bar==2.0.1
the pants setup reads the dependencies as
$'foo==0.0.1\nbar==2.0.1'
and fails with:
Copy code
ProcessExecutionFailure: Process 'Resolving plugins: foo==0.0.1
bar==2.0.1' failed with exit code 1.
stdout:

stderr:
<string> line 1:
foo==0.0.1
bar==2.0.1
Problem parsing 'foo==0.0.1\nbar==2.0.1' as a requirement: Parse error at "'bar==2.'": Expected stringEnd
When I use json or yaml files, it works as the dependencies are read as
$'foo==0.0.1' $'bar==2.0.1'
but dependabot doesn't read json or yaml files when looking for python requirements.
The same error occurs if I try to specify the plugins as env var with
PANTS_GLOBAL_PLUGINS="foo==0.0.1 bar==2.17.1"
h
This is because you're using a text file, so Pants interprets it as a single string to be added on to the list.
If the text file contains a literal Python list, like
Copy code
[
"foo",
"bar",
]
then it should work
but presumably that doesn't help dependabot
this would require augmenting that option to accept a requirements file
a
that doesn't help dependabot
Indeed, if I try to set the dependencies as a literal python list, dependabot fails with
dependency_file_not_evaluatable
.
this would require augmenting that option to accept a requirements file
Do you think this is something pants could support or this is out of scope?
h
I think it makes sense to support. One way is in the code that handles the @fromfile feature, to treat all .txt files as line-separated values (at least if the option is list-valued). The current behavior of treating it as a single string with embedded newlines is not intentional and it's unlikely anyone is relying on it. But it's not impossible either, so this is risky. An easier, less intrusive change would be to have the code that consumes the value for this specific option split it by newlines.
We'd welcome a PR for that second thing, it would be very easy to do
a
iiuc, this expand function is where the content is read from the files specified with the fromfile feature, but changing this to split the
.txt
file content by newlines would affect all options, right? I didn't find on the code where to change just the
plugins
option.
h
Yeah, I think the right place to do this is where we consume that option, which is in
src/python/pants/init/plugin_resolver.py
It might be as simple as splitting by newline here
With a comment explaining it
This is how you can run Pants from sources, to test this out: https://www.pantsbuild.org/docs/running-pants-from-sources