- import os
- def path(*segs):
- """
- CWD and `~` aware path construction. Start a segment with `/` for absolute paths.
- *(Example, on my machine)*
- >>> path('sub', 'dir')
- /Users/jacob/src/tmp/sub/dir
- >>> path('~', 'src', 'project', 'pkg')
- /Users/jacob/src/project/pkg
- """
- cand = os.path.expanduser(os.path.join(*segs))
- if cand[0] != '/':
- cand = os.path.abspath(cand)
- return cand