https://pantsbuild.org/ logo
n

nutritious-hair-72580

09/14/2021, 2:19 PM
Any idea why the dep on BitVector is not inferred?
Copy code
# bv.py
from BitVector import BitVector

bv = BitVector(size=0)

# test_bv.py
from .bv import bv


def test_it():
    assert bv == 2

# BUILD file
python_library(
# Works if added manually
#  dependencies=["//:BitVector"]
)

python_tests(
  name="tests"
)

# Error
E   ModuleNotFoundError: No module named 'BitVector'
e

enough-analyst-54434

09/14/2021, 2:35 PM
The camel case suggests the root dist module does not match the dist name. Does BitVector come from bit-vector?: https://pypi.org/project/bit-vector/ If so, you'll need a module mapping. If the requirement lives in a requirements.txt, you can do as it says here (search for `module_mapping`: https://www.pantsbuild.org/docs/python-third-party-dependencies#basic-setup If you want to contribute this mapping so you and other Pants users get it for free, then a PR editing here: https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/dependency_inference/default_module_mapping.py
n

nutritious-hair-72580

09/14/2021, 2:39 PM
Thanks. It comes from https://pypi.org/project/BitVector/ though, which should match?
h

hundreds-father-404

09/14/2021, 2:43 PM
We assume that the module is
bitvector
. It's not normal in Python for a module name to have capital letters, so we default to lower casing the dist name Setting module_mapping should fix this
👍 1
h

happy-kitchen-89482

09/14/2021, 3:18 PM
If you're feeling energetic, could you send a PR that makes the relevant change to the default mapping at https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/dependency_inference/default_module_mapping.py ? Then the next people to use BitVector won't get bitten by this (sort-of pun sort-of intended). We'd really appreciate it!
1
👍 1
4 Views