Optimize Node.path_from

This commit is contained in:
Thomas Nagy 2016-12-21 19:50:29 +01:00
parent 09713f49e4
commit 900d6b891c
2 changed files with 7 additions and 9 deletions

View File

@ -56,7 +56,8 @@ def test(ctx):
tt('path_from', dd.path_from(pp), os.path.split(os.getcwd())[1])
tt('path_from (reverse)', pp.path_from(dd), '..')
tt('same path', pp.path_from(pp), '.')
tt('same_root', bld.root.path_from(bld.root), '.')
tt('path from root is abspath()', pp.path_from(bld.root), pp.abspath())
tt('root from root', bld.root.path_from(bld.root), bld.root.abspath())
tt('root height', bld.root.height(), 0)
tt('self height', dd.height(), len(absdir))

View File

@ -430,10 +430,9 @@ class Node(object):
:param node: path to use as a reference
:type node: :py:class:`waflib.Node.Node`
:returns: the relative path
:returns: a relative path or an absolute one if that is better
:rtype: string
"""
c1 = self
c2 = node
@ -461,13 +460,11 @@ class Node(object):
c2 = c2.parent
if c1.parent:
for i in range(up):
lst.append('..')
lst.extend(['..'] * up)
lst.reverse()
return os.sep.join(lst) or '.'
else:
if lst and not Utils.is_win32:
lst.append('')
lst.reverse()
return os.sep.join(lst) or '.'
return self.abspath()
def abspath(self):
"""