# HG changeset patch # User Martin von Zweigbergk # Date 2020-01-14 22:18:11 # Node ID 4e05272dd6819c165a6ca0775b8e57e7930f0ab6 # Parent 191a461d6be60867a8069cb2f0698f78409c1dc2 packaging: leverage os.path.relpath() in setup.py `os.path.relpath()` has existed since Python 2.6, so we can safely use it. This fixes a bug in the current code when the common prefix is "/" (in which case `uplevel` would be one less than it should). Differential Revision: https://phab.mercurial-scm.org/D7875 diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1064,11 +1064,7 @@ class hginstallscripts(install_scripts): # absolute path instead libdir = self.install_lib else: - common = os.path.commonprefix((self.install_dir, self.install_lib)) - rest = self.install_dir[len(common) :] - uplevel = len([n for n in os.path.split(rest) if n]) - - libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common) :] + libdir = os.path.relpath(self.install_lib, self.install_dir) for outfile in self.outfiles: with open(outfile, 'rb') as fp: