Hi Team: Is it possible to disable dependency infe...
# general
Hi Team: Is it possible to disable dependency inference per build target?
Hello! Not per target, only a global option. What's the motivation?
We have code that uses dynamic loading of Python modules. I want to take advantage of dependency inference except few places in the code.
Ah I mispoke, the way you would disable dep inference is using
ignores. See the tooltip at https://www.pantsbuild.org/docs/targets#dependencies-and-dependency-inference
It's not as elegant as having a boolean option on the target, but should get the same effect. Use
./pants dependencies
to get the deps that were inferred and should be put in the BUILD file, then run
./pants dependencies
again to double check the exclude worked
Thanks for your answer.
❤️ 1
@fresh-architect-74417 is dep inference causing harm for those targets? Or is it just missing the dynamically loaded deps? Because you can always leave dep inference on and just manually add the deps it can't figure out from
Or are there deps it's inferring that are wrong and need to be removed?
I still going through pants v2 for a major upgrade. This is one of the issues we have. We have a code that imports a Python module called dev_constants. That file is used in some code like this:
Copy code
if env == 'dev':
    import dev_constants
We don't include it in the BUILD file so it doesn't go to our production code. We also have code that uses importlib to dynamically import some of the libraries on the fly. I want to have the ability to disable or enable imports in the build file. I will try to exclude them and see if they are going to work better.
👍 1
Ah, makes sense. So you do need to exclude it explicitly.
If that becomes a hassle it might not be hard to plug your own logic into dep inference, with a custom plugin.
If they all follow a consistent naming pattern, (e.g.
) that could help too (for a generic exclude thingy…)