Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Tilde paths are treated as relative paths instead of absolute by cd() #898
with cd('~/somewhere'): with cd('~/somewhere'): run('pwd')
will cause an error because of:
Executed: /bin/bash -l -c "cd
with cd('/home/someuser/somewhere'): with cd('/home/someuser/somewhere'): run('pwd')
will work fine and return "/home/someuser/somewhere". I don't know how it works under the hood, but on the surface it seems like tilde path expressions should be treated as absolute paths instead of relative paths.
The example is somewhat silly, but came up when there are utility functions that are called by other functions, all of which need to cd into the same directory, like so:
def utility(): with cd('~/somewhere'): run('some cmd') def bigger_function(): with cd('~/somewhere'): run('some other cmd') utility()
I haven't poked at it in a while but IIRC the way 'cd' works is to build up a list/stack of paths and joins them together for a single 'cd' call prior to execution; which is what you see in the debug output.
If there is a solution to this it's probably to either turn it into a series of 'cd' expressions (