diff options
author | Ben Finney <ben@benfinney.id.au> | 2010-02-03 18:55:03 +1100 |
---|---|---|
committer | Ben Finney <ben@benfinney.id.au> | 2010-02-03 18:55:03 +1100 |
commit | a325b7182896b714752091c01779a8bed6d943e4 (patch) | |
tree | 506d9288fdb44b9c21e08f683df988e0389adb4d /coverage/files.py | |
parent | 5e09c8140d43822815a96c0020c92f0d62090e0c (diff) | |
download | python-coveragepy-a325b7182896b714752091c01779a8bed6d943e4.tar.gz |
Use ‘os.path.commonprefix’ to find the “relative directory” at the start of a path.
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 6 |
1 files changed, 4 insertions, 2 deletions
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`. |