lemon-oxygen-72498
11/08/2022, 9:30 AMpants
developers π, I would like to get rid of the following WARN messsages when I run tests:
The target libs/image_processing/kaiko/image_processing/mask/statistics.py:../../../kaiko-image-processing imports `numpy`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['libs/geometry:kaiko-geometry-poetry-reqs#numpy', 'libs/geometry:kaiko-geometry-reqs#numpy', 'libs/image_processing:kaiko-image-processing-reqs#numpy'].
My project structure is as follows:
βββ BUILD
βββ libs
β βββ geometry
β β βββ BUILD
β β βββ pyproject.toml
β β βββ requirements.txt
β βββ image_processing
β βββ BUILD
β βββ pyproject.toml
β βββ requirements.txt
βββ pants.toml
And my root
pattern is:
[source] # <https://www.pantsbuild.org/docs/source-roots>
marker_filenames = ["pyproject.toml"]
My libs/image_processing/BUILD
file is as follows:
python_requirements(name="kaiko-image-processing-reqs")
python_sources(
name="kaiko-image-processing",
sources=["kaiko/image_processing/**/*.py"],
dependencies=[
":kaiko-image-processing-reqs#opencv-python",
"libs/geometry:kaiko-geometry",
],
)
I could list in dependencies
all external dependencies, like I did for opencv-python
but my developers push back quite hard on boilerplate, and this will make my life to integrate pants
harder. Is there a workaround so that pants
doesn't go looking for dependencies higher up than the enclosing root? I would like it picks up 'libs/image_processing:kaiko-image-processing-reqs#numpy'
without further ado here. (edited)gifted-agency-25998
11/08/2022, 9:33 AMpyproject.toml
AND a requirements.txt
. I removed the requirements.txt
file to fix it. Would that work for you?lemon-oxygen-72498
11/08/2022, 9:34 AMrequirements.txt
for provisioning local development sandboxes, but pyproject.toml
for deployment πlemon-oxygen-72498
11/08/2022, 9:34 AMgifted-agency-25998
11/08/2022, 9:36 AMreqs
lines in the BUILD file, which would fix it at least until you tailor
again.
There is probably a better solution - as my experience with pants (the build system) is limited to the last few dayscurved-television-6568
11/08/2022, 1:36 PMparametrize
). See:
https://www.pantsbuild.org/docs/python-third-party-dependencies#warning-multiple-versions-of-the-same-dependency
https://www.pantsbuild.org/docs/targets#parametrizing-targets
https://www.pantsbuild.org/docs/targets#field-default-values <- is useful if you need to set the resolve for a whole subtree in your project.
https://www.pantsbuild.org/docs/reference-python#enable_resolvescurved-television-6568
11/08/2022, 1:40 PMfiles
or resources
targets in most cases. If a third party is not inferred properly, it may need a module_mapping
configuration on the python_requirements
target to help guide Pants from the import name to the distribution name when it is not 1 to 1.lemon-oxygen-72498
11/08/2022, 2:10 PMpants
could decide which dependencies to pick up (between requirements.txt
or pyproject.toml
.
We want to use the requirements.txt
when running tests for example, but not when packaging (requirements.txt
is for sandboxes, but not for distribution).curved-television-6568
11/08/2022, 2:14 PMpython_tests
targets, matching the resolve for your python_requirements
target you want to use, then for your python_distribution
you include your python_sources
with the parametrized version that uses the resolve you want to use for packaging, which will need to be parameterized on resolve like: python_sources(β¦, resolve=parametrize("a", "b"), β¦)
where βaβ and βbβ are your resolve names.
https://www.pantsbuild.org/docs/reference-python_tests#coderesolvecodelemon-oxygen-72498
11/08/2022, 2:16 PMhappy-kitchen-89482
11/08/2022, 3:37 PMhappy-kitchen-89482
11/08/2022, 3:38 PMhappy-kitchen-89482
11/08/2022, 3:38 PMlemon-oxygen-72498
11/08/2022, 3:38 PMhappy-kitchen-89482
11/08/2022, 3:39 PMhappy-kitchen-89482
11/08/2022, 3:39 PMhappy-kitchen-89482
11/08/2022, 3:39 PMimports
and other deps in the codelemon-oxygen-72498
11/08/2022, 3:39 PMhappy-kitchen-89482
11/08/2022, 3:39 PMhappy-kitchen-89482
11/08/2022, 3:40 PMhappy-kitchen-89482
11/08/2022, 3:41 PMhappy-kitchen-89482
11/08/2022, 3:41 PM