I would like to change how I'm telling pants how t...
# development
p
I would like to change how I'm telling pants how to disambiguate some dependencies. Instead of:
Copy code
python_tests(
    dependencies=["st2common/tests/unit/base.py"],
)
or even a more specific version
Copy code
python_tests(
    overrides={
        ("test_db_auth.py", "test_db_pack.py", "test_db_rbac.py", ...etc): {
            dependencies=["st2common/tests/unit/base.py"],
        },
    },
)
I wish I could do this instead:
Copy code
python_tests(
    module_dependencies_map={
        # specify the whole import
        "tests.unit.base": "st2common/tests/unit/base.py",
        # or just the top level module:
        "tests": "st2common/tests",
    },
)
ie - tell the inference layer which file to use when it encounters a given uninferrable import (probably because it is ambiguous across the monorepo). Thoughts? Does anyone else like this UX? How feasible is something like this?
h
Are you sure source roots are set up correctly? Fwict, this is only adding the st2common prefix in front, right?
p
It is ambiguous because there is a tests module in several places in the repo.
So, st2common, st2actions, contrib/runners/orquesta_runner, and several others are all source roots that include a
tests
directory/module.
In particular, several of them have a
*/tests/unit/base.py
file.
The ambiguity also results in a lot of infer warnings with 2.14 even though I explicitly added the appropriate file in dependencies. So I'm trying to find a cleaner way to manage this without adding the
# pants: no-infer-dep
to a couple dozen test files all over the place. (I'm going to switch back to
ignore
until there's an alternative).
c
So perhaps an option to ignore certain source roots in various places.. I wonder if the visibility feature I’m working on would work to exclude unwanted stuff in this case.. 🤔
@proud-dentist-22844 would you mind describing this case briefly as a comment to https://github.com/pantsbuild/pants/discussions/17389
p
Wow. Yeah. Visibility could probably resolve this. 🤔 I'll add a note.
🙏 1
c
@proud-dentist-22844 yes, thanks. I’ll write some tests for those see how it fits 🙏
💯 2
❤️ 2