Hi Pants team, can pants handle the libs imported ...
# general
w
Hi Pants team, can pants handle the libs imported programmatically (e,g, via import_module)? From my observation, pants does not seems automatically handle them? I can add those libs manually in BUILD files, but there are lots of them in my use case. I could also ‘consolidate’ those BUILD files by combining them and moving it to a parent folders. But, in that case, the dependencies feature will be ‘lost’ in some way as every thing in the parent folder will depend on all those libs manually added. Any suggestion to handle it better?
h
w
does it work for import_module(a) where a is a variable*?* or a has to be a plain str?
h
It looks at all strings in your code for things that look like modules, e.g.
path.to.module
. So it is fine to be a variable
related is the option right below
string_imports_min_dots
h
So it will work for
import_module(a)
where a is a variable, as long as somewhere there is a literal
path.to.module
somewhere
1
If that's not sufficient then you can write a plugin to do custom dep inference
w
em. does it work if the module name is loaded from a yaml, then using import_module to import it?
h
No, that won't work because there is no string literal in your code for dep inference to look at
There is no way that static analysis can know about dependencies that are only determined at runtime
👍 1
you'd have to write custom dep inference that knows how to look in that yaml file
w
ok. Do you mean the plugin? If yes, do you mind pointing me to the any doc? thanks
f
Did you ever figure this out? I never managed to make a similar plugin.