Hello! I'd like to figure out what are the best pr...
# general
w
Hello! I'd like to figure out what are the best practices about using a single resolve for several projects. As I understand from the docs single resolve is preferable if dependencies of different projects do not conflict with each other. What I don't like is getting warnings like
Pants cannot infer owners for the following imports
when some dependency is specified in several
python_requirement
targets. I have a small example to illustrate my problem. I would expect dependency to be: 1. If not specified explicitly for the target, then some merge of all other dependencies, or just take the exact version from lockfile 2. If specified, then use this dependency without any warnings
f
Which imports are they?
Possible solutions: 1. Have you set your source roots in
pants.toml
for all of your source code? https://www.pantsbuild.org/prerelease/reference/subsystems/source#root_patterns 2. Do the dependencies use top-level module names which are not the same as the name of the PyPI package? You might need to set
module_mapping
. https://www.pantsbuild.org/prerelease/reference/targets/python_requirements#module_mapping
e
Looking at your repo, it looks like you have defined numpy twice, with different (though potentially compatible) versions. I think this stems from a bit of a misunderstanding. If you are using "single resolve", then you don't still specify requirements for other projects. Not sure if this is the most recommended practice, but what I like to do is have a
3rdparty/python/requirements.txt
that defines all 3rd party dependencies used in our monorepo. (and a corresponding lockfile). Then, all my 1st party python lives in
src/python/A
,
src/python/B
, etc. Individual projects within the monorepo don't need to specify dependencies, they just expect the universal resolve to have what they need. They will get whichever version happens to be picked during lockfile generation (which will be the latest version that is compatible with all other packages and constraints)
In other words, from your 2 cases, (1) is exactly what happens, and (2) is impossible, because this is trying to use multi-resolves
w
Not sure if this is the most recommended practice, but what I like to do is have a
3rdparty/python/requirements.txt
that defines all 3rd party dependencies used in our monorepo.
thank you for the answer! I was thinking about it too. Although it leads to harder understanding what are the dependencies for the specific project. And in the future it will be harder to migrate some project to separate resolve or in separate repo if such need will arise
e
it leads to harder understanding what are the dependencies for the specific project.
pants dependencies --transitive ./path/to/project/entrypoint.py
will list every target that is needed by
entrypoint.py
. If you add
| grep 3rdparty
you can use grep to filter it down to only the targets that came from the 3rd party dir
🙏 1