https://pantsbuild.org/ logo
#development
Title
# development
p

proud-dentist-22844

11/02/2022, 4:19 AM
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

hundreds-father-404

11/02/2022, 1:14 PM
Are you sure source roots are set up correctly? Fwict, this is only adding the st2common prefix in front, right?
p

proud-dentist-22844

11/02/2022, 1:15 PM
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

curved-television-6568

11/02/2022, 1:53 PM
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

proud-dentist-22844

11/02/2022, 2:19 PM
Wow. Yeah. Visibility could probably resolve this. 🤔 I'll add a note.
🙏 1
c

curved-television-6568

11/02/2022, 5:27 PM
@proud-dentist-22844 yes, thanks. I’ll write some tests for those see how it fits 🙏
💯 2
❤️ 2