diff --git a/CHANGELOG b/CHANGELOG index a3de136ee..439df61be 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -53,6 +53,8 @@ Bug fixes / Maintenance on all python versions - install plain py.test/py.which scripts also for Jython, this helps to get canonical script paths in virtualenv situations +- make path.bestrelpath(path) return ".", note that when calling + X.bestrelpath the assumption is that X is a directory. Changes between 1.3.0 and 1.3.1 ================================================== diff --git a/py/_path/common.py b/py/_path/common.py index 15aa80f3c..b8b620f02 100644 --- a/py/_path/common.py +++ b/py/_path/common.py @@ -194,10 +194,13 @@ newline will be removed from the end of each line. """ def bestrelpath(self, dest): """ return a string which is a relative path from self - to dest such that self.join(bestrelpath) == dest and - if not such path can be determined return dest. + (assumed to be a directory) to dest such that + self.join(bestrelpath) == dest and if not such + path can be determined return dest. """ try: + if self == dest: + return os.curdir base = self.common(dest) if not base: # can be the case on windows return str(dest) @@ -207,7 +210,7 @@ newline will be removed from the end of each line. """ n = self2base.count(self.sep) + 1 else: n = 0 - l = ['..'] * n + l = [os.pardir] * n if reldest: l.append(reldest) target = dest.sep.join(l) diff --git a/testing/path/common.py b/testing/path/common.py index 8e83e45f6..86e7a03e2 100644 --- a/testing/path/common.py +++ b/testing/path/common.py @@ -117,6 +117,8 @@ class CommonFSTests(object): def test_bestrelpath(self, path1): curdir = path1 sep = curdir.sep + s = curdir.bestrelpath(curdir) + assert s == "." s = curdir.bestrelpath(curdir.join("hello", "world")) assert s == "hello" + sep + "world"