helpful-rocket-63313
12/07/2023, 12:21 AMai-cpu
and ai-gpu
). my resolves looks like:
python_requirements(
name="reqs",
resolve=parametrize("python-default", "ai-gpu", "ai-cpu"),
)
python_requirements(
name="ai-gpu",
source="ai-gpu-requirements.txt",
resolve="ai-gpu",
)
python_requirements(
name="ai-cpu",
source="ai-cpu-requirements.txt",
resolve="ai-cpu",
)
Based on docs, If a first-party target is compatible with multiple resolves, e.g., shared utility code, you can use the parametrize mechanism with the resolve= field.
i should use `python_sources(resolve=parametrize('ai-gpu', 'ai-cpu', 'python-default'). Given my shared code is spread across multiple directories, it will get unmaintainable to always set these resolves for all the targets. So i am thinking to set the defaults at root of python source code, like:
__defaults__(
{(python_sources, python_source): dict(resolve=parametrize(python-default", "ai-gpu", "ai-cpu) )}
)
and for the 2 main files(pex_binary targets) that i am interested it, i will set the resolve ai-cpu
, ai-gpu
. Do you think this is a good idea? Should __defaults__
be used/exploited like this, does it form a good practice, or is there a better way of doing this?curved-television-6568
12/08/2023, 1:17 PMcurved-television-6568
12/08/2023, 1:17 PMhelpful-rocket-63313
12/08/2023, 1:27 PMpex_binary
as below
# ai/inference/BUILD
pex_binary(name="app-cpu", entry_point="main_inference.py", resolve="ai-cpu")
pex_binary(name="app-gpu", entry_point="main_inference.py", resolve="ai-gpu")
# webserver/BUILD
# non-ai-related code which doesn't care about cpu/gpu
pex_binary(name="app", entry_point="main.py") -> this can take default resovle
if i don't provide all 3 resolves to all shared python_sources, i will not be able to provide different resolves to each pex_binarieshelpful-rocket-63313
12/08/2023, 1:35 PMwebserver/script.py
, because of 3 resolves in default, it generated 3 target for this script file. so now i cannot do pants run webserver/script.py
, i'll have to do pants run webserver/script.py@python-default
, ie explicitly provide the resolvecurved-television-6568
12/08/2023, 3:05 PMcurved-television-6568
12/08/2023, 3:07 PMpython_sources(overrides={"script.py": dict(resolve=None)})
helpful-rocket-63313
12/08/2023, 3:48 PM