Skip to content

Tilde paths are treated as relative paths instead of absolute by cd() #898

@drcraig

Description

@drcraig

Running:

with cd('~/somewhere'):
    with cd('~/somewhere'):
        run('pwd')

will cause an error because of:

Executed: /bin/bash -l -c "cd /somewhere//somewhere && pwd"

but running:

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions