10 import shutil |
10 import shutil |
11 import types |
11 import types |
12 |
12 |
13 import coverage |
13 import coverage |
14 from coverage.data import add_data_to_hash |
14 from coverage.data import add_data_to_hash |
15 from coverage.exceptions import CoverageException |
15 from coverage.exceptions import NoDataError |
16 from coverage.files import flat_rootname |
16 from coverage.files import flat_rootname |
17 from coverage.misc import ensure_dir, file_be_gone, Hasher, isolate_module, format_local_datetime |
17 from coverage.misc import ensure_dir, file_be_gone, Hasher, isolate_module, format_local_datetime |
18 from coverage.misc import human_sorted |
18 from coverage.misc import human_sorted, plural |
19 from coverage.report import get_analysis_to_report |
19 from coverage.report import get_analysis_to_report |
20 from coverage.results import Numbers |
20 from coverage.results import Numbers |
21 from coverage.templite import Templite |
21 from coverage.templite import Templite |
22 |
22 |
23 os = isolate_module(os) |
23 os = isolate_module(os) |
206 # Process all the files. |
206 # Process all the files. |
207 for fr, analysis in get_analysis_to_report(self.coverage, morfs): |
207 for fr, analysis in get_analysis_to_report(self.coverage, morfs): |
208 self.html_file(fr, analysis) |
208 self.html_file(fr, analysis) |
209 |
209 |
210 if not self.all_files_nums: |
210 if not self.all_files_nums: |
211 raise CoverageException("No data to report.") |
211 raise NoDataError("No data to report.") |
212 |
212 |
213 self.totals = sum(self.all_files_nums) |
213 self.totals = sum(self.all_files_nums) |
214 |
214 |
215 # Write the index file. |
215 # Write the index file. |
216 self.index_file() |
216 self.index_file() |
224 for static in self.STATIC_FILES: |
224 for static in self.STATIC_FILES: |
225 shutil.copyfile(data_filename(static), os.path.join(self.directory, static)) |
225 shutil.copyfile(data_filename(static), os.path.join(self.directory, static)) |
226 |
226 |
227 # .gitignore can't be copied from the source tree because it would |
227 # .gitignore can't be copied from the source tree because it would |
228 # prevent the static files from being checked in. |
228 # prevent the static files from being checked in. |
229 with open(os.path.join(self.directory, ".gitignore"), "w") as fgi: |
229 gitigore_path = os.path.join(self.directory, ".gitignore") |
230 fgi.write("# Created by coverage.py\n*\n") |
230 if not os.path.exists(gitigore_path): |
|
231 with open(gitigore_path, "w") as fgi: |
|
232 fgi.write("# Created by coverage.py\n*\n") |
231 |
233 |
232 # The user may have extra CSS they want copied. |
234 # The user may have extra CSS they want copied. |
233 if self.extra_css: |
235 if self.extra_css: |
234 shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css)) |
236 shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css)) |
235 |
237 |
327 """Write the index.html file for this report.""" |
329 """Write the index.html file for this report.""" |
328 index_tmpl = Templite(read_data("index.html"), self.template_globals) |
330 index_tmpl = Templite(read_data("index.html"), self.template_globals) |
329 |
331 |
330 skipped_covered_msg = skipped_empty_msg = "" |
332 skipped_covered_msg = skipped_empty_msg = "" |
331 if self.skipped_covered_count: |
333 if self.skipped_covered_count: |
332 msg = "{} {} skipped due to complete coverage." |
334 n = self.skipped_covered_count |
333 skipped_covered_msg = msg.format( |
335 skipped_covered_msg = f"{n} file{plural(n)} skipped due to complete coverage." |
334 self.skipped_covered_count, |
|
335 "file" if self.skipped_covered_count == 1 else "files", |
|
336 ) |
|
337 if self.skipped_empty_count: |
336 if self.skipped_empty_count: |
338 msg = "{} empty {} skipped." |
337 n = self.skipped_empty_count |
339 skipped_empty_msg = msg.format( |
338 skipped_empty_msg = f"{n} empty file{plural(n)} skipped." |
340 self.skipped_empty_count, |
|
341 "file" if self.skipped_empty_count == 1 else "files", |
|
342 ) |
|
343 |
339 |
344 html = index_tmpl.render({ |
340 html = index_tmpl.render({ |
345 'files': self.file_summaries, |
341 'files': self.file_summaries, |
346 'totals': self.totals, |
342 'totals': self.totals, |
347 'skipped_covered_msg': skipped_covered_msg, |
343 'skipped_covered_msg': skipped_covered_msg, |