Hello! I recently started to use pants in a Python...
# general
m
Hello! I recently started to use pants in a Python monorepo at work and I’m struggling with the lock files... As some people in the team work on Windows, we only run pants in the CI and as we’re using poetry, I would like to make sure the dependencies bundled in the pex files are the same as those in
poetry.lock
. First, I tried to add the following section in the config file (seen here in the doc):
Copy code
[python.resolves_to_constraints_file]
__default__ = "constraints.txt"
It did not seem to have an effect (i.e. the resolved dependencies versions in the pex file were not the correct ones)... After exploring the docs a bit more, I added the following lines in the python section of the
pants.toml
:
Copy code
enable_resolves = true
resolves_generate_lockfiles = false
resolves = { python-default = "contraints.txt" }
I create the contraints file in the CI, running
poetry export
before pants. It works (i.e. it correctly uses the versions defined in the contraints file) but it first generates a big pex files with all the dependencies before the selecting the one used in the subproject I’m building. It makes the build quite slow as it’s a big monorepo with lots of dependencies, is there a way to only install the needed dependencies and still use the versions defined in the
poetry.lock
? PS: I’m using v2.15
b
Our approach to this (dependencies managed by poetry and imported into pants) is to export them to a requirements.txt and have pants load from that, rather than loading the poetry requirements from pyproject.toml. That is, pants is generating a lock file from a complete set of pinned dependencies (rather than having loose requirements + constraints). We have a
shunit2_test
test (in pants) that the requirements.txt file on disk matches the output of
poetry export
(or similar, I’m on my phone at the moment, so can’t check exactly what we do). It’s not great but it’s been working for us
m
@broad-processor-92400 Thanks, we could try that indeed 🙂
But I would still like to understand why I’m not able to make the constraints file work as intended...
👍 1
b
It is a good question, and one someone else will need to answer, because I do not know! 😄
(One debugging question: does replacing
__default__
with your actual resolve name(s) work any better? As in, eliminate that special key as a source of bugs)