https://pantsbuild.org/ logo
#general
Title
# general
f

fresh-cat-90827

12/05/2022, 5:00 PM
Is there a way to override the dependencies of a Python module in a target and discard the `import`s that take place in that particular file? ๐Ÿงต
โœ… 1
Using the example-python repo,
Copy code
$ ./pants dependencies helloworld/translator/translator_test.py
//:reqs#pytest
helloworld/translator/translator.py:lib
which is expected (
translator_test.py
imports
translator.py
and
pytest
). Now, what if I'd like to say that
translator_test.py
only depends on a particular target and doesn't depend on the imports that take place in that file? With the overrides, I can do:
Copy code
python_tests(
    name="tests",
    overrides={
        "translator_test.py":
            {
                "dependencies": ["helloworld/greet:translations"]
            }
    }
)
and get:
Copy code
$ ./pants dependencies helloworld/translator/translator_test.py
//:reqs#pytest
helloworld/greet:translations
helloworld/translator/translator.py:lib
However, would it be possible to discard the first party imports that take place in the
translator_test.py
? Or at least be able to distinguish between the inferred dependencies (via `import`s) and dependencies that come from the
overrieds
parameter? My ultimate goal is to get:
Copy code
$ ./pants dependencies helloworld/translator/translator_test.py
helloworld/greet:translations # comes from the `overrides`
p

polite-garden-50641

12/05/2022, 5:55 PM
๐Ÿ‘€ 1
there is also a directive you can use in the source file....
# pants: no-infer-dep
https://www.pantsbuild.org/docs/reference-python-infer#imports
โค๏ธ 1
f

fresh-cat-90827

12/05/2022, 9:40 PM
thanks, @polite-garden-50641!
there is also a directive you can use in the source file.... # pants: no-infer-dep
that's the one, I think!
Copy code
$ PANTS_PYTHON_INFER_IMPORTS=False ./pants dependencies helloworld/translator/translator_test.py
helloworld/greet:translations
ignoring the dependencies with negation would be cumbersome as I'd need to modify BUILD files which is something I'd like to avoid ๐Ÿ˜„
6 Views