limited-balloon-79828
03/12/2024, 10:26 AM|lib-
| |
| |-libA # no pytorch dep
| |-libB # has pytorch dep
| |-libC # no pytorch dep
|
|projects
|-project1 # uses libA and libB
|-project2 # uses libA and libC
I have created 2 resolves on the requirements: resolve-pytorch
and resolve-default
• Since project1 uses libB that uses Pytorch, I put resolve=resolve-pytorch on the python_source
and pex_binary
in project1's BUILD file
• Since project2 doesn't use libB that uses Pytorch, I put resolve=resolve-default on the python_source
and pex_binary
in project2's BUILD file
The problem is that libA which is dependent by Project1 and project2 will have 2 different resolves so I put resolve=parametrize(resolve-pytorch, resolve-default)
on libA's BUILD file.
It works when I build the PEX files for both projects with pants package
, but it fails on the Mypy check.
>pants check projects/project1
---omitted----
17:53:13.38 [ERROR] Completed: Typecheck using MyPy - mypy - mypy failed (exit code 1).
Partition #1 - resolve-default, ['CPython==3.10.*']:
Found 6 errors
Partition #2 - resolve-torch, ['CPython==3.10.*']:
Success: no issues found in 2 source files
mypy failed
Am I approaching this wrong? Is there other ways to achieve the pex separation?
I've been looking at this Optimizing Python Docker page as well but probably I will need to see in depth about PEX_TOOLS
The team that uses project2 complains that the docker image is large because it contains pytorch even though they don't use it.gorgeous-winter-99296
03/12/2024, 2:25 PMgorgeous-winter-99296
03/12/2024, 2:30 PMpants dependencies --transitive projects/project2/entrypoint.py
and pants paths --from=projects/project2/entrypoint.py --to=//:requirements#pytorch
, substituting the proper names and targets as applicable. The first one will show if project2 actually depends on torch, while the latter one will show howlimited-balloon-79828
03/13/2024, 1:24 AMpython_requirements
Thank you very much for your answer!gentle-flower-25372
03/13/2024, 1:45 AMlimited-balloon-79828
03/13/2024, 2:05 AMpants package projects/project2::
, it builds everything from that requirement file and the pex file for everything is huge.gentle-flower-25372
03/13/2024, 2:48 AMgentle-flower-25372
03/13/2024, 2:50 AMgentle-flower-25372
03/13/2024, 2:51 AMgentle-flower-25372
03/13/2024, 2:51 AMlimited-balloon-79828
03/13/2024, 3:04 AMpants paths --from=projects/project2/entrypoint.py --to=//third-party:requirements#torch
Without separation, it shows something like this
[
[
"projects/project2/entrypoint.py:../project2",
"third_party:requirements#torch"
]
]
While with project1 it shows:
[
[
"projects/project1/entrypoint.py:../project1",
"third_party:requirements#torch"
],
[
"projects/project1/entrypoint.py:../project1",
"lib/libB/torch_endpoint.py:../libB",
"third_party:requirements#torch"
],
]
With separation, project 2 only prints empty list when running the similar command
pants paths --from=projects/project2/entrypoint.py --to=//third-party:torch-requirements#torch
While project 1 shows nice dependency paths
[
[
"projects/project1/entrypoint.py:../project1",
"lib/libB/torch_endpoint.py:../libB",
"third_party:torch-requirements#torch"
],
]
Notice that the first list from project 1 has disappeared.
I'm not sure if it's a bug or anything. I'm on Pants 2.17white-twilight-61019
08/29/2024, 9:43 AM