Hi, what’s the way to do module mapping for module...
# general
r
Hi, what’s the way to do module mapping for modules which are added under
extra_requirements
. My exact case is with mypy. I added some stub for boto3 called
boto3-stubs
but the package itself is
mypy_boto3_batch
when I need to use the import. e.g.
Copy code
from mypy_boto3_batch.client import BatchClient
Hence pants is generating warnings about not being able to infer the owner of such import. This is the relevant section of
pants.toml
Copy code
[mypy]
version = "mypy>=0.971"
extra_requirements.add = [
  "pydantic>=1.9.1",
  "pandas-stubs>=1.4.4.220919",
  "types-requests>=2.28.11",
  "boto3-stubs[s3,batch]>=1.24"
]
extra_type_stubs = ["pandas-stubs>=1.4.4.220919", "types-requests>=2.28.11", "boto3-stubs[s3,batch]>=1.24"]
lockfile = "build-support/mypy.lock"
h
r
Ah ok. Then either I define it as normal python_requirement or ignore the warning explicitly using
# pants: no-infer-dep
as you’ve mentioned in the ticket.
On a related note how would you define the module mapping in this case since the
boto3-stubs
can have multiple extras and based on that it can lead to different import name like
mypy_boto3_batch
,
mypy_boto3_s3
etc
h
Probably add all the mappings for all the extras you might care about? If you’re not importing from them, there’s no harm in listing them
👍 1
b
@refined-addition-53644 I had a similar use case recently and I simply listed the package I needed:
Copy code
python_requirement(
    name = "mypy-boto3-dynamodb",
    requirements = ["mypy-boto3-dynamodb"],
    type_stub_modules = ["boto3"],
)
So I had no issue when importing it.