Hi all. I'm trying out the (experimental) ruff bac...
# general
a
Hi all. I'm trying out the (experimental) ruff backend, but pants gives an error when I invoke the lint goal. I think it's due to the fact that my ruff configuration is targeted at a different version then what pants uses. How can I (a) debug this to verify my suspicion (i.e. check which version of ruff is used by plants)?; (b) specify a specific version of ruff to use? I suspect this is covered in the documentation somewhere but I'm having trouble finding it. Many thanks for any hints!
s
Hi! You can change ruff version with a separate resolve for ruff. In `pants.toml`:
Copy code
[python]
enable_resolves = true
default_resolve = "default"

[python.resolves]
default = "3rdparty/python/default.lock"
ruff = "3rdparty/python/ruff.lock"

[ruff]
install_from_resolve = "ruff"
Then in `BUILD`:
Copy code
python_requirement(
    name="ruff",
    requirements=["ruff==0.2.0"],
    resolve="ruff",
)
Then execute
Copy code
pants generate-lockfiles --resolve=ruff
That's it, then you can try
pants lint
more on resolves here
a
Ah brilliant, thanks @square-psychiatrist-19087! I'll give that a try. Are you aware of an easy way to check which version of ruff (or other backends) is used in a given pants run?
(choose the tag that corresponds to your pants version)
a
Regarding the concept of "resolves", I have seen it mentioned in several places in the documentation, but to be honest found it difficult to find an exact definition and wrap my head around deciding in which situations it is applicable/needed. The only sentence I found that comes close to defining resolves is buried deep down in the section about Python Lockfiles that you linked to. Would it make sense to dedicate a section in "Key concepts" to explaining what "resolves" are and when they should be used? It clearly seems to be something that's more general than Python Lockfiles.
s
resolve is just a fancy name for a collection of sources that uses a specific lockfile
for example, you can have py2.7 code and py3.12 code in the same repo. And py2.7 code depends on
six
package, and py3.12 depends on
pydantic>=2
, so they are unrelated and they can't exist in a single resolve. To make it work you put them in 2 resolves and generate a lockfile per resolve
so your py2.7 code is in one "universe" and py3.12 code is in another one, and you can't import stuff from a different universe
a
@square-psychiatrist-19087 Just to report back - I tried your code and it works like a charm. I don’t think I could have come up with this on my own given my current limited experience with pants, so thanks a lot for the help and the explanations. Much appreciated.
s
You're welcome!