Skip to content

Commit

Permalink
feat: html output directory gets a .gitignore file. #1244
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 27, 2021
1 parent 7fd1ea3 commit ea6906b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
run: |
set -xe
python -m igor combine_html
rm htmlcov/.gitignore
python -m coverage json
echo "::set-output name=total::$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")"
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Unreleased
a ``-q/--quiet`` option to suppress the messages they write to stdout about
what they are doing (`issue 1254`_).

- Feature: The ``html`` command writes a ``.gitignore`` file into the HTML
output directory, to prevent the report from being committed to git. If you
want to commit it, you will need to delete that file. Closes `issue 1244`_.

- Feature: Added support for PyPy 3.8.

- Fix: more generated code is now excluded from measurement. Code such as
Expand All @@ -58,6 +62,7 @@ Unreleased
.. _issue 553: https://github.com/nedbat/coveragepy/issues/553
.. _issue 840: https://github.com/nedbat/coveragepy/issues/840
.. _issue 1160: https://github.com/nedbat/coveragepy/issues/1160
.. _issue 1244: https://github.com/nedbat/coveragepy/issues/1244
.. _issue 1254: https://github.com/nedbat/coveragepy/issues/1254
.. _attrs: https://www.attrs.org/

Expand Down
5 changes: 5 additions & 0 deletions coverage/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ def make_local_static_report_files(self):
for static in self.STATIC_FILES:
shutil.copyfile(data_filename(static), os.path.join(self.directory, static))

# .gitignore can't be copied from the source tree because it would
# prevent the static files from being checked in.
with open(os.path.join(self.directory, ".gitignore"), "w") as fgi:
fgi.write("# Created by coverage.py\n*\n")

# The user may have extra CSS they want copied.
if self.extra_css:
shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css))
Expand Down
2 changes: 2 additions & 0 deletions howto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
- IF PRE-RELEASE:
$ rm -f ~/coverage/trunk/doc/sample_html_beta/*.*
$ cp -r htmlcov/ ~/coverage/trunk/doc/sample_html_beta/
$ rm ~/coverage/trunk/doc/sample_html_beta/.gitignore
- IF NOT PRE-RELEASE:
$ rm -f ~/coverage/trunk/doc/sample_html/*.*
$ cp -r htmlcov/ ~/coverage/trunk/doc/sample_html/
$ rm ~/coverage/trunk/doc/sample_html/.gitignore
$ cd ~/coverage/trunk
- IF NOT PRE-RELEASE:
check in the new sample html
Expand Down
1 change: 1 addition & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def assert_htmlcov_files_exist(self):
self.assert_exists("htmlcov/helper2_py.html")
self.assert_exists("htmlcov/style.css")
self.assert_exists("htmlcov/coverage_html.js")
self.assert_exists("htmlcov/.gitignore")

def test_html_created(self):
# Test basic HTML generation: files should be created.
Expand Down

0 comments on commit ea6906b

Please sign in to comment.