pants icon indicating copy to clipboard operation
pants copied to clipboard

Expose `print` or some other debugging statement from macros

Open stuhood opened this issue 2 years ago • 2 comments

Similar to #16174, it would be useful to expose print. The worst case abuse of print is essentially to (accidentally?) spam your users, and so it is a known-safe side-effect.

stuhood avatar Aug 18 '22 23:08 stuhood

Can someone guide me on how can I work on this? Would be greatly appreciated

Kaushik-Iyer avatar Aug 24 '22 05:08 Kaushik-Iyer

@Kaushik-Iyer : Sorry for the delay!

This would look a lot like the issue I linked above: https://github.com/pantsbuild/pants/pull/16174/files

Essentially, when computing the globals to use when evaluating BUILD files, you would leave print exposed in the builtins.

stuhood avatar Sep 12 '22 17:09 stuhood

not sure if I should create a new issue for this - but I believe this is actually "done"? it seems to me that a bug was introduced by https://github.com/pantsbuild/pants/pull/16174 (relating to how Python implicitly populates builtins in the globals dictionary passed to exec) that makes all builtins automatically available in macros - if you add a print or breakpoint call to a macro at present, it will "just work" (not as intended)

marcuslimdw avatar May 20 '23 12:05 marcuslimdw

@marcuslimdw Thank you for raising this. I've verified it does indeed work. I suggest to leave this open until we have a test case in place ensuring this holds into the future.

kaos avatar May 23 '23 15:05 kaos