<#21013 module_mapping failing with pants &gt; 2.1...
# github-notifications
c
#21013 module_mapping failing with pants &gt; 2.19 for Cv2 Issue created by enriquemaffezzini The monorepo was using until now pants 2.18. When deciding to replace black and docformatter for ruff as formatters, I found out we needed to upgrade at least up to pants 2.20. When running pants tests, some of the passing tests with pants 2.18 started failing with pants 2.21 (same thing for pants 2.20). Apparently when upgrading pants, it stopped recognizing Cv2 from the python requirement's module_mapping:
/3rdparty/BUILD
Copy code
...
python_requirements(
    name="python-default",
    source="requirements/default_requirements.txt",
    module_mapping={
        "PyYAML": ["yaml"],
        "opencv-python": ["cv2"],
        "ruamel-yaml": ["ruamel.yaml"],
        "scikit-video": ["skvideo"],
        "torchvision": ["albumentations.pytorch", "torchvision"],
        "azure-monitor-opentelemetry": ["azure"],
        "google-auth": ["google.auth"],
        "google-auth-oauthlib": ["google.oauth2", "google_auth_oauthlib"],
        "google-api-python-client": ["googleapiclient"],
    },
    resolve="python-default",
    overrides={
        "docplex": {"dependencies": [":python-default#cplex"]},
        "fastapi": {
            "dependencies": [
                ":python-default#python-multipart",
                ":python-default#httpx",
            ]
        },
        "mongomock": {"dependencies": [":python-default#setuptools"]},
        "sqlalchemy": {"dependencies": [":python-default#pyodbc"]},
    },
)
...
By just changig the pants_version from the
/pants.toml
down to 2.18.0 or 2.19.0 makes the test pass smoothly. 2.20.0 and 2.21.0 would end with Cv2 import error for several tests:
ModuleNotFoundError: No module named 'cv2'
Commenting the lines related to other imports from the same module_mapping (for example
"ruamel-yaml": ["ruamel.yaml"],
) would result in import errors related to those modules. This points out to the problem been cv2 specific. Any ideas on why pants > 2.19 wouldn't pick up the
module_mapping={"opencv-python": ["cv2"]}
? Pants version 2.21.0 OS Linux pantsbuild/pants