diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-03-21 18:51:40 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-03-21 18:51:40 -0400 |
commit | 489872c0d84aeff03d164eda5201b495a73e129d (patch) | |
tree | 69e7d5b8609c38f1381f7ef67e79911b741ffca6 /coverage/files.py | |
parent | 506acd0e2c542032a6ff2017b7074296d2f65214 (diff) | |
download | python-coveragepy-git-489872c0d84aeff03d164eda5201b495a73e129d.tar.gz |
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).
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/coverage/files.py b/coverage/files.py index 28331a18..5690679f 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`. |