Hey everyone, I’m trying to reduce the warnings o...
# general
m
Hey everyone, I’m trying to reduce the warnings of my pants build on a Python project. I see two different warning types: a. Pants cannot infer owners for the following imports in the target
name/src/a/b/c/file.py:../../../sources
, where the BUILD file is under
name/src
and includes this content:
Copy code
python_sources(
    name="sources",
    sources=["**/*.py"],
)

python_requirement(
    name="requirements",
    requirements=[
        "click==8.1.7",
    ],
)

python_distribution(
    name="dist",
    dependencies=[":sources"],
    provides=python_artifact(
        name="name",
        version="1.0.0"
    ),
)
a. The target <like-above> imports
click
, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: [‘cli/src:requirements’, ‘library/src:requirements’]. I could use multiple resolves here, but that doesn’t make sense. Both the library and the CLI consume the package on their own (as opposed to two different CLIs, where multiple resolves do make sense). WDYT?
👀 1
c
regarding the second (a): seems like you have two different
python_requirement
targets, both offering
click
?
m
yeah, one in a library (a logger based on click) and another in a CLI (based on click) that consumes the library
c
so that's the issue, if they are both part of the same resolve, you have the same library twice and pants doesn't know which of them to use.
m
I understand, but that’s something I’d expect pants to overcome, because both are exactly in the same version (otherwise we would have a conflict) Also, having multiple resolves in this scenario feels artificial, because its a CLI that consumes a library (that can be consumed elsewhere by other apps that don’t use click directly)
g
I looked into this a while back, to silence these warnings when resolves are used because as you note, they cannot differ if both are usable. Then the resolve fails.
It's just a matter of few people having hit this because it's a bit non-Pantsy to begin with. Pants doesn't really have a concept of libraries or applications. Code uses other code and belongs to a resolve. The physical structure has no bearing on how this works apart from dependency inference.
m
I understand. I think it would be beneficial to reduce the number of warnings, otherwise developers just ignore them all 😅 About the resolves, haven’t those started because there were multiple “artifacts” handled by Pants? (e.g two web servers that require a different version of library X) If you think we can somehow adjust pants to drop this warning, I’d be happy to contribute. Also, any idea about the first issue?
c
not too sure about the first issue. can you provide a simplified example with source files w/ imports and the source roots in effect?
g
The documentation mentions that the owner is an ancestor. Can you try moving your distribution one step up maybe? So if it's currently in
name/src
, move it to
name
From looking at the code I also think you've cut out a chunk of the message, so sharing the whole error would be helpful.