From 9b685f291dee3f23785a0ab3dff4e413ea98f0da Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 9 Aug 2015 09:48:51 -0400 Subject: Move flat_rootname from FileReporter to a utility function. --- coverage/files.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index e3ebd6c..d2742a3 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -67,6 +67,20 @@ def canonical_filename(filename): return CANONICAL_FILENAME_CACHE[filename] +def flat_rootname(filename): + """A base for a flat filename to correspond to this file. + + Useful for writing files about the code where you want all the files in + the same directory, but need to differentiate same-named files from + different directories. + + For example, the file a/b/c.py will return 'a_b_c_py' + + """ + name = os.path.splitdrive(filename)[1] + return re.sub(r"[\\/.:]", "_", name) + + if env.WINDOWS: _ACTUAL_PATH_CACHE = {} -- cgit v1.2.1