Hi :slightly_smiling_face: I'm super excited that ...
# general
a
Hi 🙂 I'm super excited that my company is moving to pants 🎉 i am looking for a way to run multiple versions of the black linter in my repo (i need an older version for parts that are written in python 2.7 and the new version for what's written in newer python versions). i can't seem to find a solution that's not "hacky". any ideas on how i can achieve this or if this has built in support can anyone point me to the relevant documentation?
👋 1
w
I've never needed to do something like that, but would something like multiple resolves work? https://www.pantsbuild.org/blog/2022/05/25/multiple-lockfiles-python#pantss-hybrid-approach-granular-resolves
a
I've read about multiple resolves. I don't understand how to use it with the
install_from_resolve
in
[black]
for example
h
Hi! Alas there is no way to run multiple different versions of black in the same Pants run (with the same config). What you can do is have a separate
pants.py27.toml
config file that overrides the relevant settings in the regular pants.toml, and then invoke Pants on just the Python 2.7 targets with
--pants-configfiles=pants.py27.toml
.
If you want to make this more ergonomic you can mark the python 2.7 targets with a tag and select them with
--tag=py27
And then you can make the whole thing more ergonomic with a cli alias
So that
pants py27 lint ::
expands to
pants --tag=py27 --pants-configfiles=pants.py27.toml lint ::
which will then only run on the python 2.7 targets, and with the right config
and then you can use
pants --tag=-py27 lint ::
(or a macro that expands to the same) to select everything but the python 2.7 code
w
🤦‍♂️ I forgot that black's versioning is handled by us in
pants.toml
😆
c
The difficulty is that install_from_resolve wants a single resolve, but essentially you need different versions of Black installed. I'm on mobile and can't test, but having a single resolve with 2 sets of requirements conditional on the python version (something like
black==1.2.3; python<3
) might work? I think that will cause both versions of black to be registered in the lockfile, and the right one will be picked by the interpreter constraints of the python files. Not sure though.
💡 1
🤯 1
c
@happy-kitchen-89482 have you tried aliasing the config files option?. I recall issues with aliasing certain bootstrap options and since the alias definition is in a config file it wouldn’t surprise me if there’s some rough edges there..
h
Ah, no, I didn't actually try this out
I guess the alias can directly set the relevant options, without a config file, though
--black-install-from-resolve=black-py27
or whatever
c
yea
a
@careful-address-89803, Although I am unfamiliar with the conditions syntax adding the condition as you suggested resulted in an error
Invalid requirement 'black==21.12b0;python<3' in foo/black-requirements.txt at line 1: Parse error at "';python<'": Expected string_end
As for the solution suggested by @happy-kitchen-89482, I want both versions to run at the same time (running the lint/build command one) if I understand correctly your solution requires me to have to run pants twice and that's not exactly what I'm looking for
c
It should be
python_version<3
.. not sure that'll do it though, as black still seems to require a Py 3.x also when working on Py 2.7 code..
also, I've not been able to capture two different versions of the same lib in the lockfile.. although it feels like this should be possible, in particular if using platform markers; I've only tried with python version markers so far.