How to deal with recurring 3rd party dependency resolution issues #17273
-
Partly copied from this Slack thread. I'm having a lot of recurring issues with 3rd party dependencies. So before proceeding with a question for each issue, I want to start by clarifying what the "proper" way to use BackgroundHow Things are Currently SetupWe have various Python projects in a monorepo. Each one has its own requirements file with inexact specifiers. We also have project groupings that each define a virtual environment covering a bundle of projects. These groupings have requirements files with exact specifiers. In principle, the specifiers for a project grouping and its transitive project dependencies should be compatible. The project grouping has a similar function to Pants lockfiles. How I'm Migrating To PantsFor now I'm working on a single project grouping and the transitive deps of a single project. This corresponds to a single lockfile. I'm taking all projects and tailoring a Relevant Problems I'm Running Into
It seems like Pants is upset that I have multiple Main Clarifying Questions
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Thanks for writing this up! These are good questions, and I will attempt to answer them below. And, for general context, when stuff like this isn't clear, the fault is in our documentation, so this is really great input for improving those... |
Beta Was this translation helpful? Give feedback.
-
To your question 1: "Is it wrong to have multiple requirement files using the same resolve and with overlapping deps?" That is not typically how a resolve is defined or used, so I'm not surprised it's causing problems... First, to clarify the target types: A python requirement is represented by a
That creates a target that Pants knows provides the Now, since typing out those explicit So you can see where the trouble happens: if you have multiple requirements.txt with an entry for Django, then there will be multiple generated You can work around this, as you did, by adding an explicit dependency. But that is not great, obviously, and not how Pants was designed to be used. The idiomatic way to do all this is to have a single requirements.txt1 that provides all requirements once. With Pants, the requirements.txt is a list of "allowed" os "possible" requirements. Pants will create the relevant subset of that automatically in each situation where requirements are needed. So you don't need multiple requirements.txt files at all! But, of course, since you're coming to this with an existing situation of multiple requirements.txt files, and presumably So the solution is to create a single requirements.txt for each project grouping (or even for the entire repo, if that level of compatibility is possible2). Then you should be able to get rid of all the manually added dependencies, and let Pants infer them. Now, where to resolves/lockfiles fit in to all this? You can have multiple, possibly incompatible,
|
Beta Was this translation helpful? Give feedback.
-
I think that also answered your question 2? And as for question 3 - I think improving our docs is going to be important (and hopefully this discussion helps future readers), as well as improving the functionality itself. But the best way to debug is to fully understand the - not always intuitive - thing that is going on, which hopefully this has helped with. |
Beta Was this translation helpful? Give feedback.
-
Thanks, that helps clarify things. My understanding of the way our current setup works is that each project specifies a "guard" on what kinds of dependencies it requires / supports and then the project-group compiles all these guards together into a pseudo-lockfile requirements.txt. It seems like in Pants the For now, we'll keep our pseudo-lockfile requirements.txt generation as-is and have Tailor ignore every other requirements file. I agree it would be useful to clarify in the documents that the current intended usage is to only have a single |
Beta Was this translation helpful? Give feedback.
To your question 1: "Is it wrong to have multiple requirement files using the same resolve and with overlapping deps?"
That is not typically how a resolve is defined or used, so I'm not surprised it's causing problems...
First, to clarify the target types: A python requirement is represented by a
python_requirement()
stanza in a BUILD file, say3rdparty/python/BUILD
:That creates a target that Pants knows provides the
django
package. When Pants sees, say,from django.conf import settings
in one of your source files, it infers a dependency from that file onto3rdparty/python:django
.Now, since typing out those exp…