How does the Pants devs feel about pragmas? Specif...
# development
b
How does the Pants devs feel about pragmas? Specifically, I'm having an issue where an import should be ignored (but I very much like having
unowned-dependency-behavior
on). I'm thinking it'd be really convenient to do:
Copy code
import foo  # pants: ignore
Specifically I'm only using Pants for `lint`/`format`/`check`. And the import is of the flavor:
Copy code
try:
    import .modname
except ImportError:
    import modname
specifically to handle how the module is distributed vs tested
h
I'd be in favor, if the comment is available in the import parser we use for dep inference
๐Ÿ‘ 1
p
FYI, You may exclude dependencies by prefixing withย 
!
see https://www.pantsbuild.org/docs/reference-python_sources#codedependenciescode)
b
@polite-garden-50641 would that works for dependencies that don't resolve though? ๐Ÿค”
h
yeah I like the idea. We already have a Shellcheck pragma for dependency inference, see the toolbox at https://www.pantsbuild.org/docs/shell
๐Ÿ‘€ 1
b
FWIW I group the shellcheck pragma the same as Python type hint comments. They're in-tool. Whereas this would be out-of-tool (and in-Pants)
๐Ÿ‘ 1
I guess the difference is that for dep inference for Python is hand-rolled. In the shell check case it's another tool.
h
Yeah. I think we would maybe supersede the
shellcheck
pragma with a Pants one. Shellcheck would still work, but be underdocumented perhaps? It's weird to have a Shellcheck pragma to make Pants happy if you're not even using Shellcheck. (I guess you could just directly add the dep to the BUILD file instead)
c
Itโ€™s nice not having to provide both a pants pragma and a tool pragma for the same thing, but granted, the tool version ought to be a behind the scenes version only perhaps.. ๐Ÿ™‚
Iโ€™m in favour of pants pragmas, btw. ๐Ÿ˜‰
b
Same. Helps users control the magic when necessary