From d569d9b292cf882ed8d2c87312b4f1af48d1180d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 21 Mar 2010 18:51:40 -0400 Subject: Undo Ben Finney's patch to use the os.path methods. os.path.commonprefix is both useless (beacause it's based on characters, not path components) and wrong (because to compute a relative path name, we need relative to a particular directory, or absolute, not some middle case). --- coverage/files.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index 28331a1..5690679 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -6,7 +6,8 @@ class FileLocator(object): """Understand how filenames work.""" def __init__(self): - self.relative_dir = self.abs_file(os.curdir) + # The absolute path to our current directory. + self.relative_dir = self.abs_file(os.curdir) + os.sep # Cache of results of calling the canonical_filename() method, to # avoid duplicating work. @@ -20,13 +21,12 @@ class FileLocator(object): """Return the relative form of `filename`. The filename will be relative to the current directory when the - FileLocator was constructed. + `FileLocator` was constructed. """ - common_prefix = os.path.commonprefix( - [filename, self.relative_dir + os.sep] - ) - return filename[len(common_prefix):] + if filename.startswith(self.relative_dir): + filename = filename.replace(self.relative_dir, "") + return filename def canonical_filename(self, filename): """Return a canonical filename for `filename`. -- cgit v1.2.1