Hi, I'm trying to setup pants for a python reposit...
# general
r
Hi, I'm trying to setup pants for a python repository but getting an import error when importing python module for the google-cloud-sql-connector dependency when running `pants test ::`:
ModuleNotFoundError: No module named 'google'
. Does anyone know anything about that? I've setup a simple project demonstrating the issue:
Copy code
> tree
.
├── BUILD  # only contains `python_requirements(name="root")`
├── pants.toml  # only backend enabled is `pants.backend.python`
├── requirements.txt  # only contains `cloud-sql-python-connector`
└── src
    ├── BUILD  # only contains `python_tests(name = "tests")`
    └── some_test.py  # only contains `from google.cloud.sql.connector import Connector, IPTypes`

1 directory, 5 files
The python_requirement target seems to have been setup:
Copy code
> pants --filter-target-type=python_requirement list ::
//:root#cloud-sql-python-connector
I've sifted through the sandbox (obtained from
pants --keep-sandboxes=on_failure test ::
) and don't see anything related to the google sql python connector anywhere, requirements.pex/.deps doesn't exist. I'm using pants version 2.17.1.
1
r
Ahh that's it, setting "cloud-sql-python-connector" to ["google.cloud.sql.connector"] fixed it. Thank you!
r
Even mapping it to just google should work. This way you can use something import like
import google.<not-cloud>.<not-sql>
👍 1
b
I believe pants 2.19 handles the mapping for more/all of these GCP modules in a built-in way, so another option might be upgrading pants.
r
2.19.1 doesn't seem to fix it
b
Ah, well. Now that I look more closely, the library name doesn’t follow the usual
Google-…
pattern, sorry about that. If you felt like it, a pull request to https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/dependency_inference/default_module_mapping.py to add the PyPI name -> import name mapping to
DEFAULT_MODULE_MAPPING
would be nice