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 | 16409981082f4271d83f1c1e53aa019851450c12 (patch) | |
tree | 930e8435280dc87d1efdb10803b983848c2a71c2 /coverage/files.py | |
parent | 0182926a873072d7062b8db17c15d345e8054193 (diff) | |
download | python-coveragepy-git-16409981082f4271d83f1c1e53aa019851450c12.tar.gz |
Use ‘os.path.commonprefix’ to find the “relative directory” at the start of a path.
--HG--
branch : use-os-path-module
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 ba228c23..fb597329 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`. |