https://pantsbuild.org/ logo
#development
Title
# development
b

bitter-ability-32190

01/03/2022, 4:28 PM
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

happy-kitchen-89482

01/03/2022, 4:32 PM
I'd be in favor, if the comment is available in the import parser we use for dep inference
๐Ÿ‘ 1
p

polite-garden-50641

01/03/2022, 4:36 PM
FYI, You may exclude dependencies by prefixing withย 
!
see https://www.pantsbuild.org/docs/reference-python_sources#codedependenciescode)
b

bitter-ability-32190

01/03/2022, 4:54 PM
@polite-garden-50641 would that works for dependencies that don't resolve though? ๐Ÿค”
h

hundreds-father-404

01/03/2022, 4:57 PM
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

bitter-ability-32190

01/03/2022, 5:10 PM
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

hundreds-father-404

01/03/2022, 7:11 PM
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

curved-television-6568

01/03/2022, 8:17 PM
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

bitter-ability-32190

01/04/2022, 12:39 AM
Same. Helps users control the magic when necessary