This is probably a feature request. Looking at `[p...
# general
p
This is probably a feature request. Looking at
[python-infer].string_imports
and `[python-infer].assets`: https://www.pantsbuild.org/docs/reference-python-infer#string_imports These flags work one way, but I would like to invert the signals given to the python dep inference system. So, the flag enables checking all springs for possible imports or assets, and then you use code comments or a
!
(negative) dependency to exclude false positives. My code base has a lot of strings that look similar to an import but they aren't. So, turning string import inference on globally sounds very problematic to me. So, instead of excluding false positives, could I use comments to say
# pants: string_imports on
and
# pants: string_imports off
? In other words, I want to enable string import inference selectively with code comments. I think something similar would be great for assets too.
b
Anything is possible in a plugin. I take caution on tacking too much to the core dep inference.
FWIW have you actually tested how many strings ACTUALLY also match something importable AND it's incorrect? We have a large codebase and I can't think of 1 false positive
p
Well, I finally tested
string_imports
with the help of
grep -Ir '"[a-z_]\+\(\.[a-z_]*\)\+"'
and the
python-dump-source-analysis
goal in 2.16.0a0. I found only 1 false positive, so I added the
pants: no-infer-deps
comment on that and several other similar strings. I'm surprised there aren't a lot more. I also expected it to complain about a lot of strings that don't map to an actual module, but it works much better than that and ignores those strings. So, I was worried for nothing. I'll have to play with
[python-infer].assets
next. Thanks @bitter-ability-32190 for making that string inference stuff work so smoothly!