libb.expandabspath

expandabspath(p)[source]

Expand environment variables and ~, then make the path absolute.

Parameters:

p (str) – Path string to expand.

Returns:

The expanded path, resolved against the working directory.

Return type:

Path

Notes

  • A rooted path carrying no drive (‘/foo’) is not absolute on Windows, so resolving it attaches the current drive and returns ‘D:/foo’. Compare against os.path.abspath rather than a literal to state an expectation that holds on either platform.

Examples

>>> import os
>>> os.environ['SPAM'] = 'eggs'
>>> assert expandabspath('~/$SPAM') == Path(os.path.expanduser('~/eggs'))
>>> assert expandabspath('/foo') == Path(os.path.abspath('/foo'))
>>> assert expandabspath('foo').is_absolute()