https://pantsbuild.org/ logo
w

wide-zoo-86070

04/19/2022, 4:49 PM
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

hundreds-father-404

04/19/2022, 4:55 PM
w

wide-zoo-86070

04/19/2022, 5:01 PM
does it work for import_module(a) where a is a variable*?* or a has to be a plain str?
h

hundreds-father-404

04/19/2022, 5:03 PM
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

happy-kitchen-89482

04/19/2022, 5:12 PM
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

wide-zoo-86070

04/19/2022, 5:26 PM
em. does it work if the module name is loaded from a yaml, then using import_module to import it?
h

happy-kitchen-89482

04/19/2022, 5:26 PM
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

wide-zoo-86070

04/19/2022, 5:28 PM
ok. Do you mean the plugin? If yes, do you mind pointing me to the any doc? thanks
f

faint-twilight-16124

07/04/2022, 10:53 PM
Did you ever figure this out? I never managed to make a similar plugin.
2 Views