From a325b7182896b714752091c01779a8bed6d943e4 Mon Sep 17 00:00:00 2001 From: Ben Finney Date: Wed, 3 Feb 2010 18:55:03 +1100 Subject: =?UTF-8?q?Use=20=E2=80=98os.path.commonprefix=E2=80=99=20to=20fin?= =?UTF-8?q?d=20the=20=E2=80=9Crelative=20directory=E2=80=9D=20at=20the=20s?= =?UTF-8?q?tart=20of=20a=20path.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coverage/files.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index ba228c2..fb59732 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -6,7 +6,7 @@ class FileLocator(object): """Understand how filenames work.""" def __init__(self): - self.relative_dir = self.abs_file(os.curdir) + os.sep + self.relative_dir = self.abs_file(os.curdir) # Cache of results of calling the canonical_filename() method, to # avoid duplicating work. @@ -23,7 +23,9 @@ class FileLocator(object): FileLocator was constructed. """ - return filename.replace(self.relative_dir, "") + common_prefix = os.path.commonprefix( + [filename, self.relative_dir + os.sep]) + return filename[len(common_prefix):] def canonical_filename(self, filename): """Return a canonical filename for `filename`. -- cgit v1.2.1