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

fresh-architect-74417

04/27/2021, 7:34 PM
Hi Team: Is it possible to disable dependency inference per build target?
h

hundreds-father-404

04/27/2021, 7:34 PM
Hello! Not per target, only a global option. What's the motivation?
f

fresh-architect-74417

04/27/2021, 7:36 PM
We have code that uses dynamic loading of Python modules. I want to take advantage of dependency inference except few places in the code.
h

hundreds-father-404

04/27/2021, 7:39 PM
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
f

fresh-architect-74417

04/27/2021, 7:48 PM
Thanks for your answer.
❤️ 1
h

happy-kitchen-89482

04/27/2021, 8:11 PM
@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
import
statements
1
Or are there deps it's inferring that are wrong and need to be removed?
f

fresh-architect-74417

04/27/2021, 8:26 PM
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
h

happy-kitchen-89482

04/27/2021, 11:54 PM
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.
c

curved-television-6568

04/28/2021, 8:11 AM
If they all follow a consistent naming pattern, (e.g.
dev_*
) that could help too (for a generic exclude thingy…)