I'm seeing a issue where pants can't infer a depen...
# general
p
I'm seeing a issue where pants can't infer a dependency for two libraries, urllib3 and certifi
Copy code
pants dependencies --transitive observatory_api/observatory_api/rest.py 
15:40:27.93 [WARN] The target observatory_api/observatory_api/rest.py imports `certifi`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['.build/requirements#certifi', 'observatory_api:reqs#certifi'].

Please explicitly include the dependency you want in the `dependencies` field of observatory_api/observatory_api/rest.py, or ignore the ones you do not want by prefixing with `!` or `!!` so that one or no targets are left.

Alternatively, you can remove the ambiguity by deleting/changing some of the targets so that only 1 target owns this module. Refer to <https://www.pantsbuild.org/v2.15/docs/troubleshooting#import-errors-and-missing-dependencies>.
15:40:27.93 [WARN] The target observatory_api/observatory_api/rest.py imports `urllib3`, but Pants cannot safely infer a dependency because more than one target owns this module, so it is ambiguous which to use: ['.build/requirements#urllib3', 'observatory_api:reqs#urllib3'].
I'm unsure where the observatory_api:reqs target is coming from.
b
The error message suggests there might be a
observatory_api/BUILD
file. What's in it?
p
Magic!
Fixed it 🙏
So it added this
Copy code
python_sources()

python_requirements(
    name="reqs",
)

python_requirements(
    name="reqs0",
    source="test-requirements.txt",
)
My directory structure is
Copy code
/
- observatory_api
  - observatory_api
     - api
     - apis
        ...
  - tests
I added the root source of
Copy code
/observatory_api
When I run
pants tailor ::
it drops a BUILD in /observatory_api
For what it's worth this is all openapi generated code
b
Our work repo has found success by making sure there's only one
python_requirements
in a single resolve, so that dependencies aren't imported twice. There's coincidentally a thread a few days ago about something similar: https://pantsbuild.slack.com/archives/C046T6T9U/p1677806156563409