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

bitter-ability-32190

11/17/2022, 8:25 PM
How can I get the caller's CWD in rule code? Normally we assume project root, but I wanna handle
../../pants arg1 arg2
h

hundreds-father-404

11/17/2022, 8:26 PM
I don't think we have any current way to do this. And you have to be careful with memoization with the daemon that running
../../pants
and then
./pants
right after needs to invalidate the value
b

bitter-ability-32190

11/17/2022, 8:26 PM
Right now I'm assuming it is build root, which is likely true most of the time? But still I hate the assumption
h

hundreds-father-404

11/17/2022, 8:29 PM
Yeah, Pants only works from build root. Which is a huge UX issue. You should be able to run Pants from any directory
c

curved-television-6568

11/17/2022, 8:33 PM
In https://github.com/kaos/pants-shim/blob/main/src/pants.sh I’ve played with an idea to have a “pants” shim that you can invoke from where ever and it should pick up your build root for you and
cd
to it before actually invoking pants. but I guess a better more robust thing would be to have pants detect the build root itself and not touch CWD..
b

bitter-ability-32190

11/17/2022, 8:34 PM
Actually for my work (https://github.com/pantsbuild/pants/issues/17540) even CWD is likely wrong. So Build Root is the best we got until https://github.com/microsoft/debugpy/issues/1130 is fixed
w

witty-crayon-22786

11/17/2022, 8:49 PM
It's
BuildRoot
currently, always
b

bitter-ability-32190

11/17/2022, 8:52 PM
I actually figured out how to fix my issue CWD/build_root agnostic 🙂