I am getting many warnings about missing python de...
# general
s
I am getting many warnings about missing python dependencies even though those dependencies is set in pyproject.toml, I'll put the warning and more info in thread.
The warning itself:
Copy code
$ pants --no-pantsd dependencies lib/py/email/_sender.py
13:47:34.44 [WARN] Pants cannot infer owners for the following imports in the target lib/py/email/_sender.py:

  * aiosmtplib (line: 8)

If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/2.21/docs/using-pants/troubleshooting-common-issues#import-errors-and-missing-dependencies> for common problems.
lib/py/dns/__init__.py
lib/py/email/__init__.py
lib/py/email/pyproject.toml:reqs
lib/py/email:reqs#aiosmtplib
lib/py/email:reqs#email-validator
pyproject.toml
:
Copy code
[project]
name = "lib.py.email"
version = "0"
dependencies = [
    "aiosmtplib",
    "email_validator",
]
`BUILD`:
Copy code
python_requirements(
    name="reqs",
    source="pyproject.toml",
)

python_sources(
    dependencies=[
        ":reqs",
        "lib/py/dns:dns",
    ]
)
Copy code
$ ls -lah dist/export/python/virtualenvs/python-default/3.11.9/lib/python3.11/site-packages | grep aiosmtplib
drwxr-xr-x     - ph    2 Jul 23:37  aiosmtplib
drwxr-xr-x     - ph    2 Jul 23:37  aiosmtplib-3.0.1.dist-info
Copy code
$ cat 3rdparty/python/default.lock | grep aiosmtplib
//     "aiosmtplib",
              "url": "<https://files.pythonhosted.org/packages/3b/2a/31fbf4dcfb7ad018e9148b94d5280f2fdb3b6657e9db562a58da7ef31a9f/aiosmtplib-3.0.1-py3-none-any.whl>"
              "url": "<https://files.pythonhosted.org/packages/4f/b4/f91e0715e81bfa56e17850357b7d603861ebb1fdd92481d68c8fedf6bf5a/aiosmtplib-3.0.1.tar.gz>"
          "project_name": "aiosmtplib",
    "aiosmtplib",
c
Using a minimal setup with the information you provided works for me, so there must be something else that trips this up.
Copy code
❯ pants dependencies lib/py/email/_sender.py
lib/py/email/pyproject.toml:reqs
lib/py/email:reqs#aiosmtplib
lib/py/email:reqs#email-validator
Copy code
❯ tree
.
├── default.lock
├── lib
│   └── py
│       └── email
│           ├── BUILD
│           ├── _sender.py
│           └── pyproject.toml
└── pants.toml

4 directories, 7 files
do you use any
__defaults__
? also, you don't need to depend on the entire resolve (the
:reqs
dependency you have in there) as that will unconditionally pull in all thirdparty deps, even unused ones.
s
I don't use
__defaults__
, I created a copy of monorepo and found how to reproduce it without all the code. When you add those two files the warning starts to appear:
lib/py/mailgen/BUILD
:
Copy code
python_requirements(
    name="reqs",
    source="pyproject.toml",
)
`lib/py/mailgen/pyproject.toml`:
Copy code
[project]
name = "lib.py.mailgen"
version = "0"
dependencies = ["aiosmtplib", "backoff"]
c
Ah, yes. You have two targets for
aiosmtplib
in the same resolve, Pants doesn't know which one of them it should infer a dependency to. If those two projects doesn't share code, but you want to continue using separate requirements for them, put them in dedicated resolves to fix the issue.