few-arm-93065
07/02/2022, 7:45 PMsrc/common:lib
which depends on some 3rd-party python packages, and many other modules which each have their own additional 3rd party dependencies. These other modules follow a pattern of python_requirements
-> python_sources
-> pex_binary
-> docker_image
-> python_tests
. Their python_sources
all declare a dependency on src/common:lib
.
My intention is to have all the dependent modules inherit the python dependencies of src/common:lib
, but I can’t do that without multiple resolves. When I try that, I get errors trying to reference those targets. Example:
python_requirements(resolve="align")
python_sources(
name="lib",
sources=["src/*.py"],
dependencies=[
'src/common:lib',
'#pandas',
'#pysam'
],
resolve=parametrize("align", "common")
)
pex_binary(
name="exe",
entry_point="src/align.py",
dependencies=[':lib'],
shebang="/usr/bin/env python3",
platforms=[
"current",
"manylinux2014_x86_64-cp-39-cp39",
],
resolve=parametrize("align", "common")
)
docker_image(
name="docker",
image_tags=["{build_args.GIT_BRANCH}", "{build_args.GIT_COMMIT}", "{build_args.RELEASE_VERSION}"],
dependencies=[
"src/common/docker:python_base",
":exe",
]
)
python_tests(
name="tests",
sources=["tests/test_*.py"],
dependencies=[
":lib",
"src/test_framework:lib",
":test_data",
],
runtime_package_dependencies=[":docker_test"],
tags=["docker_required"],
resolve=parametrize("align", "common")
)
When I test this, I get:
ValueError: The address `src/stages/align:exe` was not generated by the target `src/stages/align:exe`, which only generated these addresses:
* src/stages/align:exe@resolve=align
* src/stages/align:exe@resolve=common
Did you mean to use one of those addresses?
Any idea how to work with this? I tried setting the :exe
targets to :exe@resolve=align
and :exe@resolve=common
, and even tried both at once - but each time they errored out because neither resolve has the full set of dependencies.enough-analyst-54434
07/02/2022, 8:57 PMfew-arm-93065
07/04/2022, 2:33 AMpex_binary(
name="exe",
entry_point="src/align.py",
dependencies=[
":lib",
],
shebang="/usr/bin/env python3",
platforms=[
"current",
"manylinux2014_x86_64-cp-39-cp39",
],
resolve=parametrize("align", "common")
)
./pants package src/stages/align:exe
19:33:09.61 [ERROR] 1 Exception encountered:
ValueError: The explicit dependency `src/stages/align:lib` of the target at `src/stages/align:exe@resolve=align` does not provide enough address parameters to identify which parametrization of the dependency target should be used.
Target `src/stages/align:lib` can be addressed as:
* src/stages/align:lib@resolve=align
* src/stages/align/src/__init__.py:../lib@resolve=align
* src/stages/align/src/align.py:../lib@resolve=align
* src/stages/align/src/bowtie2.py:../lib@resolve=align
* src/stages/align/src/fastp.py:../lib@resolve=align
* src/stages/align:lib@resolve=common
* src/stages/align/src/__init__.py:../lib@resolve=common
* src/stages/align/src/align.py:../lib@resolve=common
* src/stages/align/src/bowtie2.py:../lib@resolve=common
* src/stages/align/src/fastp.py:../lib@resolve=common
When I try adding the resolves:
pex_binary(
name="exe",
entry_point="src/align.py",
dependencies=[
':lib@resolve=align',
':lib@resolve=common'
],
shebang="/usr/bin/env python3",
platforms=[
"current",
"manylinux2014_x86_64-cp-39-cp39",
],
resolve=parametrize("align", "common")
)
./pants package src/stages/align:exe
19:30:08.59 [ERROR] 1 Exception encountered:
NoCompatibleResolveException: The target src/stages/align:exe@resolve=common uses the `resolve` `common`, but some of its dependencies are not compatible with that resolve:
* src/stages/align/src/__init__.py:../lib@resolve=align (align)
* src/stages/align/src/align.py:../lib@resolve=align (align)
* src/stages/align/src/bowtie2.py:../lib@resolve=align (align)
* src/stages/align/src/fastp.py:../lib@resolve=align (align)
* src/stages/align#pandas (align)
* src/stages/align#pysam (align)
All dependencies must work with the same `resolve`. To fix this, either change the `resolve=` field on those dependencies to `common`, or change the `resolve=` of the target src/stages/align:exe@resolve=common. If those dependencies should work with multiple resolves, use the `parametrize` mechanism with the `resolve=` field or manually create multiple targets for the same entity.
For more information, see <https://www.pantsbuild.org/v2.12/docs/python-third-party-dependencies#multiple-lockfiles>.
few-arm-93065
07/04/2022, 2:34 AMenough-analyst-54434
07/04/2022, 3:11 AMpex_binary
parametrized? Generally a root node like that will just have 1 resolve. It's things like shared libs (common) that will (need to) work with multiple different roots, each with potentially different single resolves, depending on them.few-arm-93065
07/04/2022, 3:12 AMfew-arm-93065
07/04/2022, 3:12 AMenough-analyst-54434
07/04/2022, 3:13 AMenough-analyst-54434
07/04/2022, 3:15 AMfew-arm-93065
07/04/2022, 3:16 AMresolve=None
, meaning “I don’t use resolves, but if another target depends on me and it does use resolves, include my dependencies in that resolve”?few-arm-93065
07/04/2022, 3:22 AMenough-analyst-54434
07/04/2022, 3:28 AMenough-analyst-54434
07/04/2022, 3:36 AMhappy-kitchen-89482
07/04/2022, 4:07 AMhappy-kitchen-89482
07/04/2022, 4:07 AMenough-analyst-54434
07/04/2022, 4:10 AMenough-analyst-54434
07/04/2022, 4:10 AMenough-analyst-54434
07/04/2022, 4:11 AMenough-analyst-54434
07/04/2022, 4:14 AMhundreds-father-404
07/05/2022, 3:04 PMWould you be open to a feature request along the lines of resolve=None, meaning “I don’t use resolves, but if another target depends on me and it does use resolves, include my dependencies in that resolve”?So the tricky thing is that normally the
python_source
target is only used as a dependency and not a "root". But MyPy and linting throw that off. See https://github.com/pantsbuild/pants/issues/12714 for the backstory on thatenough-analyst-54434
07/05/2022, 3:09 PMhundreds-father-404
07/05/2022, 3:11 PM[python].default_resolve
, and then Andreas recently added a flagship feature __defaults__()
that lets you set the default for a whole subtree etc https://github.com/pantsbuild/pants/pull/15836enough-analyst-54434
07/05/2022, 3:20 PMenough-analyst-54434
07/05/2022, 3:33 PM__defaults__
accommodates parameterize(...)
values? That would work if so.few-arm-93065
07/05/2022, 5:34 PMwitty-crayon-22786
07/05/2022, 5:51 PM__defaults__
+ parametrize
should allow you to say “all of the things in these subdirectories need to build with multiple resolves”. as mentioned, that’s not currently possible with the [python].default_resolve
option.witty-crayon-22786
07/05/2022, 5:51 PMmypy
are why even libraries need to know what they will eventually run withfew-arm-93065
07/05/2022, 7:49 PMwitty-crayon-22786
07/05/2022, 8:04 PMresolves
feature is disabled (that's maybe not the best name for the flag). And yes: dependency inference works the same way with one resolve (with or without multiple resolves enabled).witty-crayon-22786
07/05/2022, 8:06 PMwitty-crayon-22786
07/05/2022, 8:08 PM