Hi, do you know of a way to have one lockfile for ...
# general
p
Hi, do you know of a way to have one lockfile for the whole repository, including the tools? It so happens that we import some of the tools from our code, which means we have to add them to our requirements anyway, so I wanted to ensure that their versions (and if possible also those of their transitive dependencies) match between the code test and execution environment. I set up
pants.toml
so that e.g.
pytest
uses the
python-default.lock
file and I get an error because the lockfile includes more packages, although there are no conflicts. Setting
--python-invalid-lockfile-behavior=ignore
does work, but it would miss any conflicts or missing packages. Any good/elegant ideas getting around this? PS. Here is the error:
Copy code
16:21:43.92 [ERROR] 1 Exception encountered:

  InvalidLockfileError: You are using the lockfile at pants.lock to install the tool `pytest`, but it is not compatible with your configuration:

- You have set different requirements than those used to generate the lockfile. You can fix this by updating `[pytest].version` and/or `[pytest].extra_requirements`, or by using a new custom lockfile.
In the lockfile, but not in the input requirements: [...lots of unrelated dependencies...]

To regenerate your lockfile based on your current configuration, run `./pants generate-lockfiles --resolve=pytest`.
1
c
You could try to have a global constraints file and share that across all your resolves (tools are their own resolve, so are included in this concept) and then use
dep >= x.y
or so in your requirements. https://www.pantsbuild.org/docs/reference-python#resolves_to_constraints_file
Copy code
# pants.toml
[python.resolves_to_constraints_file]
__default__ = "some/constraints.txt"
p
Wow, that looks very good, I think it would work. I'll try it out, thanks a lot!
👍 1
h
Yeah, good instinct Andreas 🙂 That option only works if you use Pex lockfiles though, so you'll still need to set up some things like running
./pants generate_lockfiles
p
We already use pex lockfiles, so it's not a problem. I just tried it and it works (of course!). Now the versions are aligned between the lockfiles. Thanks again! 👍
🙌 3