gorgeous-winter-99296
09/26/2023, 11:03 AMpyproject.toml
would be nice, and creating a python_requirements
for each downstream resolve would make sense. However, the downstream project also requires those projects.
Tool A dependencies:
- auth_utils
- grpcio
Tool B dependencies:
- auth_utils
- requests
auth_utils dependencies:
- grpcio
- requests
- google-auth
The problem is that the resolve for A
now has two grpcio
definitions, and B
has two requests
definitions! Does anyone have some nice patterns for this? It'd be nice to be able to compose resolves from multiple locations without risking overlap like this.broad-processor-92400
09/26/2023, 11:17 AMauth_utils
an explicit python_distribution
and so, I'm hoping, tool A/B depending on it uses the install_requires
requirement ranges as input into the lockfile generation process for each of those resolves, rather than creating their own dedicated `python_requirement`s. (I've never personally done this or used python_distribution
, so don't actually know if it does what you want š
I'm just tossing out made-up advice)
(For us, we only have multiple resolves for isolated tools, e.g. we install ariadne-codegen
for some codegen tasks, but that runs as its own PEX, effectively, and just outputs data. So it can be in a separate resolve to our main app code.)gorgeous-winter-99296
09/26/2023, 11:21 AMpython_requirements(..., resolve="a")
, tool B has python_requirements(..., resolve="b")
, and the auth_utils
has [python_requirements(..., resolve=r) for r in ("a", "b")]
. But in our case, that leads to ambiguity because we have
src/py/tool_a:requirements#grpcio==1.40
src/py/auth_utils:requirements#grpcio==1.40
both in resolve a
.gorgeous-winter-99296
09/26/2023, 11:26 AMtool_a
is also parametrized over three different resolves in practice (cpu
, gpu
, and base
).broad-processor-92400
09/26/2023, 11:30 AMauth_utils
and (b) pants' dependency inference to flag if there's a problem (e.g. drop dep on auth_utils
but still try to import grpcio
)?gorgeous-winter-99296
09/26/2023, 11:30 AMlate-advantage-75311
09/26/2023, 12:34 PMgrpcio==1.39
in its requirements.txt but auth_utils declared a dependency on grpcio==1.40
for whatever reason, then we expect that it shouldn't work to share a resolve.
But the issue is that they separately declare requirements that are compatible with each other, and for which the lock file should logically be able to be generated, (both depending on grpcio==1.40
), but lock file generation is failing anyway?gorgeous-winter-99296
09/26/2023, 12:46 PMtool_a/main.py
doesn't know which grpcio
in the resolve to use.late-advantage-75311
09/26/2023, 12:52 PMgorgeous-winter-99296
09/26/2023, 12:55 PM14:50:56.84 [WARN] Pants cannot infer owners for the following imports in the target tool_a.py@resolve=cpu:
* grpc (line: 21)
These imports are not in the resolve used by the target (`cpu`), but they were present in other resolves:
* grpc: 'base' from //:base#grpcio, 'gpu' from //:gpu#grpcio, 'base' from auth:requirements-base#grpcio, 'gpu' from auth:requirements-gpu#grpcio, 'uploader' from auth:requirements-uploader#grpcio
<snip>
14:50:56.84 [WARN] Pants cannot infer owners for the following imports in the target tool_a.py@resolve=gpu:
* grpc (line: 21)
These imports are not in the resolve used by the target (`gpu`), but they were present in other resolves:
* grpc: 'base' from //:base#grpcio, 'cpu' from //:cpu#grpcio, 'base' from auth:requirements-base#grpcio, 'cpu' from auth:requirements-cpu#grpcio, 'uploader' from auth:requirements-uploader#grpcio
You can see when looking at at the first on (@resolve=cpu
) it finds two grpcios
for gpu
, but none for cpu
. When it's looking for gpu
, it finds two for cpu
but none for GPU.gorgeous-winter-99296
09/26/2023, 12:56 PMAmbiguousPythonCodegenRuntimeLibrary: Multiple `python_requirement` targets were found with the module `grpc` in your project for the resolve 'base', so it is ambiguous which to use for the runtime library for the Python code generated from the the target src/proto/hive:hive_v1_base: ['//:base#grpcio', 'src/py/auth:requirements-base#grpcio']
gorgeous-winter-99296
09/26/2023, 12:57 PMlate-advantage-75311
09/26/2023, 1:08 PMsrc/projA/BUILD
and src/projA/some_module.py
(via dep inference) to declare that there is a dependency on a grpcio 3rd party dep. Pants itself will consult these sources to determine which 3rd party requirements need to be made available at runtime (or even at test time). At least I think that's true.
Thinking about it the second way, it becomes less strange to omit grpcio from a src/projA/additional_requirements.txt
if it were to exist, or to even just stick all of them into a single requirements.txt
at the root.gorgeous-winter-99296
09/26/2023, 1:17 PMtool_a
requires torch, but tool_b
doesn't, so I want to be able to iterate on tool_b
without resolving torch again if I can avoid it.late-advantage-75311
09/26/2023, 1:26 PMgorgeous-winter-99296
09/26/2023, 1:26 PMlate-advantage-75311
09/26/2023, 1:27 PMgorgeous-winter-99296
09/26/2023, 1:29 PMgorgeous-winter-99296
09/26/2023, 1:32 PMgorgeous-winter-99296
09/26/2023, 1:32 PMlate-advantage-75311
09/26/2023, 1:33 PMlate-advantage-75311
09/26/2023, 1:34 PMgorgeous-winter-99296
09/26/2023, 1:36 PMlate-advantage-75311
09/26/2023, 1:37 PMdependencies=[ref_to_the_requirement]
in the build file?gorgeous-winter-99296
09/26/2023, 1:38 PM14:50:56.62 [WARN] The target src/py/auth/auth/authentication.py@resolve=cpu imports `requests`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['//:cpu#requests', 'src/py/auth:requirements-cpu#requests'].
Please explicitly include the dependency you want in the `dependencies` field of src/py/auth/auth/authentication.py@resolve=cpu, or ignore the ones you do not want by prefixing with `!` or `!!` so that one or no targets are left.
late-advantage-75311
09/26/2023, 1:39 PMgorgeous-winter-99296
09/26/2023, 1:40 PMlate-advantage-75311
09/26/2023, 1:42 PMgorgeous-winter-99296
09/26/2023, 1:42 PMlate-advantage-75311
09/26/2023, 1:44 PMOh, right, that feature needs to be enabled.
Try adding this to your pants.toml:
```[python-infer]
ambiguity_resolution = "by_source_root"```
I tried this in a local clone of your repo and it seemed to make things work.But we should point users to the feature in the warning message. Would you like to take it? Else happy to try and make the pr/issue
gorgeous-winter-99296
09/26/2023, 1:45 PMhappy-kitchen-89482
10/03/2023, 4:36 PMhappy-kitchen-89482
10/03/2023, 4:36 PMgorgeous-winter-99296
10/03/2023, 4:44 PMtorch
, and tool B shouldn't ever have that because torch brings a 10-second pex to multiple minutes of build time.happy-kitchen-89482
10/03/2023, 4:47 PMhappy-kitchen-89482
10/03/2023, 4:47 PMhappy-kitchen-89482
10/03/2023, 4:48 PMgorgeous-winter-99296
10/03/2023, 4:50 PMhappy-kitchen-89482
10/03/2023, 4:52 PM!!
dependency on torch from the binary?gorgeous-winter-99296
10/03/2023, 6:18 PMB
would then still pay for generate-lockfiles
costs for torch, where it can now be regenerated much faster.