Mercurial > hg
comparison setup.py @ 44080:4e05272dd681
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 14 Jan 2020 14:18:11 -0800 |
parents | bde1cd4c99d9 |
children | e1b8b4e4f496 |
comparison
equal
deleted
inserted
replaced
44079:191a461d6be6 | 44080:4e05272dd681 |
---|---|
1062 ): | 1062 ): |
1063 # can't make relative paths from one drive to another, so use an | 1063 # can't make relative paths from one drive to another, so use an |
1064 # absolute path instead | 1064 # absolute path instead |
1065 libdir = self.install_lib | 1065 libdir = self.install_lib |
1066 else: | 1066 else: |
1067 common = os.path.commonprefix((self.install_dir, self.install_lib)) | 1067 libdir = os.path.relpath(self.install_lib, self.install_dir) |
1068 rest = self.install_dir[len(common) :] | |
1069 uplevel = len([n for n in os.path.split(rest) if n]) | |
1070 | |
1071 libdir = uplevel * ('..' + os.sep) + self.install_lib[len(common) :] | |
1072 | 1068 |
1073 for outfile in self.outfiles: | 1069 for outfile in self.outfiles: |
1074 with open(outfile, 'rb') as fp: | 1070 with open(outfile, 'rb') as fp: |
1075 data = fp.read() | 1071 data = fp.read() |
1076 | 1072 |