diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-10-10 21:14:04 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-10-10 21:14:04 -0400 |
commit | f828915df2b52095ea28fbc82e1219d55ae91998 (patch) | |
tree | b748b898b5bf74c6a6f1722866ccfef212bd74f0 /coverage/html.py | |
parent | 130ae623f9dba9c28ee321b6f6a1d0f0fe8f9a8a (diff) | |
download | python-coveragepy-git-f828915df2b52095ea28fbc82e1219d55ae91998.tar.gz |
Fix the mechanism for HTML to find OS-installed resources.
Diffstat (limited to 'coverage/html.py')
-rw-r--r-- | coverage/html.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/coverage/html.py b/coverage/html.py index b5cef11e..956f070e 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -20,19 +20,27 @@ STATIC_PATH = [ os.path.join(os.path.dirname(__file__), "htmlfiles"), ] -def data_filename(fname): +def data_filename(fname, pkgdir=""): """Return the path to a data file of ours. The file is searched for on `STATIC_PATH`, and the first place it's found, is returned. + Each directory in `STATIC_PATH` is searched as-is, and also, if `pkgdir` + is provided, at that subdirectory. + """ for static_dir in STATIC_PATH: static_filename = os.path.join(static_dir, fname) if os.path.exists(static_filename): return static_filename + if pkgdir: + static_filename = os.path.join(static_dir, pkgdir, fname) + if os.path.exists(static_filename): + return static_filename raise CoverageException("Couldn't find static file %r" % fname) + def data(fname): """Return the contents of a data file of ours.""" data_file = open(data_filename(fname)) @@ -47,14 +55,14 @@ class HtmlReporter(Reporter): # These files will be copied from the htmlfiles dir to the output dir. STATIC_FILES = [ - "style.css", - "jquery.min.js", - "jquery.hotkeys.js", - "jquery.isonscreen.js", - "jquery.tablesorter.min.js", - "coverage_html.js", - "keybd_closed.png", - "keybd_open.png", + ("style.css", ""), + ("jquery.min.js", "jquery"), + ("jquery.hotkeys.js", "jquery-hotkeys"), + ("jquery.isonscreen.js", "jquery-isonscreen"), + ("jquery.tablesorter.min.js", "jquery-tablesorter"), + ("coverage_html.js", ""), + ("keybd_closed.png", ""), + ("keybd_open.png", ""), ] def __init__(self, cov, config): @@ -117,9 +125,9 @@ class HtmlReporter(Reporter): def make_local_static_report_files(self): """Make local instances of static files for HTML report.""" # The files we provide must always be copied. - for static in self.STATIC_FILES: + for static, pkgdir in self.STATIC_FILES: shutil.copyfile( - data_filename(static), + data_filename(static, pkgdir), os.path.join(self.directory, static) ) |