Hey, y'all! I wanted to try to clarify something t...
# general
s
Hey, y'all! I wanted to try to clarify something that I haven't been able to wrap my head around yet. I'm pretty new to pants. For tools that I might want to use during development (black, ruff, mypy, etc.), I can invoke them with
pants fmt
or
pants lint
, but is there a way to use those tools directly without adding them explicitly to my 3rd-party dependencies? I tested adding them to my requirements, using
pants export
to get a venv, and then calling them inside of that, but wouldn't that mean two different versions to keep up with? Is there some way to just call whatever version of, say, black is installed when I add black to
backend_packages
?
s
I think so, although I'm having a hard time making that more tangible. What does that export command look like? Is there a specific argument to
--resolves
for tools? Or something else?
w
So, something like this: https://www.pantsbuild.org/2.22/docs/python/overview/lockfiles#sharing-lockfiles-between-tools-and-code You have your requirements which
generate-lockfiles
puts into a
python-default
resolve (for example), and then in the
black
or whatever subsystem, you
install_from_resolve
requirements
Copy code
black
fastapi
pants.toml
Copy code
[python]
enable_resolves = true
interpreter_constraints = ["==3.9.*"]

[python.resolves]
python-default = "build-support/lockfiles/python-default.lock"

[black]
install_from_resolve = "python-default"
Copy code
pants generate-lockfiles --resolve=python-default
pants fmt ::
pants export --resolve=python-default

source dist/export/python/virtualenvs/python-default/3.9.19/bin/activate      
python -c "import black"
s
Thank you, I really appreciate it! Just to make sure, there's no way to export the version of black that's already used by the subsystem without going the install_from_resolve route?
w
I don't want to claim that - as I thought that was possible, but not sure off the top of my head
Whelp...
https://www.pantsbuild.org/2.21/docs/python/overview/lockfiles#lockfiles-for-tools The idea is, you'll be doing "something" extra in your repo - but whether you want them all in the same resolve, or multiple resolves, etc..
šŸ‘ 1
h
What does "use those tools directly" mean, as opposed to calling them via
pants fmt
?
s
Some editors (neovim, helix) like to invoke formatting through a CLI command's stdin/stdout. I'm not sure, but I'm assuming
pants fmt
doesn't provide that as an option? Not that I would really expect a general-purpose (and context-dependent) formatting command to do that.
h
I see, so you want the editor to invoke via
python -m mylinter
or similar, but use the same version of mylinter that Pants uses?
s
Exactly! But a custom lockfile wasn't very much trouble after all, so no big deal either way.
I was mostly just surprised that that wasn't possible.
h
@careful-address-89803 made the default tool lockfiles exportable, so you don't need to create a custom one
šŸ‘ 1
This should be available in Pants 2.21.0
s
Awesome, thanks for the heads-up!
w
Should then our docs be updated? • If you want Pants to use your custom versions, use this • If you want to export Pant's default versions, use this ?