From patchwork Tue Jan 14 22:18:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7875: packaging: leverage os.path.relpath() in setup.py From: phabricator X-Patchwork-Id: 44342 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Tue, 14 Jan 2020 22:18:37 +0000 martinvonz created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY `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). REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D7875 AFFECTED FILES setup.py CHANGE DETAILS To: martinvonz, #hg-reviewers Cc: mercurial-devel diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1064,11 +1064,7 @@ # 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: