rich-london-74860
04/19/2023, 5:22 PMshared that’s a dependency for 2 projects called A and B. The downstream dependent projects A and B also have conflicting 3rd party dependencies (for the sake of this example, suppose A depends on pandas<2.0 , B depends on pandas>=2.0 and shared does not use pandas at all). This means that A and B must use different resolves (for the sake of this example, let’s say those are called resolve_A and resolve_B) and shared must use multiple resolves with resolve=parameterize('resolve_A', 'resolve_B')
The python_sources target should wind up looking something like:
python_sources(
name="lib",
sources=["**/*.py"],
resolve=parameterize("resolve_A", "resolve_B")
)
Now let’s say shared should also be distributed as a python_distribution. resolve is not a parameter for the python_distribution and the python_sources require a resolve value.
What should this be?
Should it look something like this?
python_distribution(
name="dist",
dependencies=[
":lib@resolve=resolve_A",
":lib@resolve=resolve_B"
]
)
That seems to work for our purposes, but it’s strange to duplicate the same item in dependencies for different resolves.curved-television-6568
04/19/2023, 5:26 PMresolve=parametrize() as you showed, it’s the dependency from the distribution that needs to depend on one of them, so you can do that explicitly (not sure if there is a better way)”rich-london-74860
04/19/2023, 5:26 PMcurved-television-6568
04/19/2023, 5:26 PMcurved-television-6568
04/19/2023, 5:27 PMcurved-television-6568
04/19/2023, 5:27 PMrich-london-74860
04/19/2023, 5:28 PMA and B also have python_distribution targets.curved-television-6568
04/19/2023, 5:29 PMrich-london-74860
04/19/2023, 5:30 PMshared has this BUILD file:
python_sources(
name="lib",
sources=["**/*.py"],
resolve=parameterize("resolve_A", "resolve_B")
)
python_distribution(
name="dist",
dependencies=[
":lib@resolve=resolve_B"
]
)
A has this BUILD file:
python_sources(
name="lib",
sources=["**/*.py"],
resolve="resolve_A"
)
python_distribution(
name="dist",
dependencies=[":lib"]
)
Building the package for A will get an error saying that there is no distribution that owns
shared/__init__.py@resolve=resolve_A
which is true, there is only one for resolve=resolve_Bcurved-television-6568
04/19/2023, 5:30 PMcurved-television-6568
04/19/2023, 5:31 PMrich-london-74860
04/19/2023, 5:31 PMcurved-television-6568
04/19/2023, 5:32 PMrich-london-74860
04/19/2023, 5:33 PMpython_distribution(
name="dist",
dependencies=[
":lib@resolve=resolve_A",
":lib@resolve=resolve_B"
]
)
but it seems weird and may lead to other problemscurved-television-6568
04/19/2023, 5:34 PMdist-A , dist-B ?rich-london-74860
04/19/2023, 5:36 PMprovides? Should each one get a different name?rich-london-74860
04/19/2023, 5:36 PM./pants publish , will that publish 1 package or many?curved-television-6568
04/19/2023, 5:37 PMcurved-television-6568
04/19/2023, 5:38 PMrich-london-74860
04/19/2023, 5:39 PMcurved-television-6568
04/19/2023, 5:41 PMcurved-television-6568
04/19/2023, 5:42 PMcurved-television-6568
04/19/2023, 5:43 PMrich-london-74860
04/19/2023, 5:47 PMA has a dependency on pandas<2.0 , B has a dependency on pandas>=2.0 and shared does not use pandas at all. If shared were a 3rd-party dependency, then this would not be a problem because A and B can independently have a dependency on shared.
… which I suppose is another workaround: treat shared like a 3rd-party dependency, but that would require deploying shared and regenerating a lockfile everytime it’s chagned.curved-television-6568
04/19/2023, 5:48 PMcurved-television-6568
04/19/2023, 5:49 PMrich-london-74860
04/19/2023, 5:49 PMcurved-television-6568
04/19/2023, 5:49 PMrich-london-74860
04/19/2023, 5:49 PMrich-london-74860
04/19/2023, 5:49 PMcurved-television-6568
04/19/2023, 5:56 PMhappy-kitchen-89482
04/19/2023, 9:47 PMhappy-kitchen-89482
04/19/2023, 9:47 PMpython_distribution be part of multiple resolves?rich-london-74860
04/19/2023, 11:07 PMswift-river-73520
04/19/2023, 11:12 PMrich-london-74860
04/20/2023, 3:55 AMsrc/a:lib is a python_sources target with:
◦ Dependency on python_requirement target src/a:pandas with requirements=["pandas<1.5"]
◦ Dependency on src/shared:lib
◦ Resolve resolve_a
• src/b:lib is a python_sources target with:
◦ Dependency on python_requirement target src/a:pandas with requirements=["pandas>=1.5"]
◦ Dependency on src/shared:lib
• src/shared:lib is a python_sources target with no dependencies
◦ Since src/a:lib and src/b:lib have conflicting pandas dependencies, this python_sources target uses resolve=parametrize("resolve_a", "resolve_b")
◦ src/shared:dist is a python_distribution target for src/shared:lib
1. At commit fe06c0b, the only python_distribution target is src/shared:dist and this is successfully built with ./pants package ::
2. At commit bef3bc1, the python_distribution target src/a:dist is added. Since src/shard:dist has a dependency on src/shared:lib@resolve=resolve_a and src/a:dist has a dependency on src/a:lib in the resolve resolve_a, this works. ./pants package :: will successfully build 2 distributions.
3. At commit 55df11f, the python_distribution target src/b:dist is added. Now ./pants package :: fails with the error: NoOwnerError: No python_distribution target found to own src/shared/__init__.py:lib@resolve=resolve_b.
4. At commit 6391a54, src/shared:dist has dependencies changes to [":lib@resolve=resolve_a", ":lib@resolve=resolve_b"] and now ./pants package :: successfully builds all 3 distributions.
For what it’s worth, duplicating the dependency with multiple resolves works to fit our needs, it’s just very bizarre.curved-television-6568
04/20/2023, 1:23 PMhappy-kitchen-89482
04/20/2023, 2:05 PMcurved-television-6568
04/20/2023, 2:12 PMhappy-kitchen-89482
04/20/2023, 2:20 PMrich-london-74860
04/20/2023, 2:43 PMI think a python_distribution could support multiple resolves, given that the subset of 3rdparty deps used from each resolve is identical.In this toy example, the 3rd-party dependencies is the same, but this is not the case in our actual use case. I’m surprised that this is considered an edge case. Doesn’t this happen all the time if you have a shared library of simple utilities (e.g. organization specific path construction logic)?
curved-television-6568
04/20/2023, 5:19 PMswift-river-73520
04/20/2023, 5:23 PM