Created
October 27, 2019 17:33
-
-
Save dmtucker/f3c32611c2aba44c16e4264e63922013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import py | |
def _relpath(path, *, relto): | |
# TODO py35+ commonpath = os.path.commonpath([path, relto]) | |
commonpath = str(py.path.local(path).common(py.path.local(relto))) | |
def _commonpath_to(_path): | |
return _path[len(commonpath):].strip(os.path.sep) | |
relto_to_commonpath = os.path.sep.join( | |
os.path.pardir | |
for component in _commonpath_to(relto).split(os.path.sep) | |
if component | |
) | |
return os.path.join(relto_to_commonpath, _commonpath_to(path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment