Skip to content

Commit

Permalink
feat(compat): add support for coverage v7.0 - v7.4.4
Browse files Browse the repository at this point in the history
Note that v7.5 changes this interface again, so will currently go
unsupported. Since I plan to make some breaking changes soon anyway
which will let me swap to the coverage public interface, this is good
enough for now!

Fixes #394, #377, and #373.
  • Loading branch information
TheKevJames committed Apr 26, 2024
1 parent be44628 commit 8fb3664
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 61 deletions.
17 changes: 13 additions & 4 deletions coveralls/reporter.py
@@ -1,9 +1,16 @@
import logging
import os

from coverage.files import FnmatchMatcher
from coverage.files import prep_patterns


try:
# coverage v7.x
from coverage.files import GlobMatcher
except ImportError:
# coverage v5.x and v6.x
from coverage.files import FnmatchMatcher as GlobMatcher

try:
# coverage v6.x
from coverage.exceptions import NoSource
Expand Down Expand Up @@ -35,7 +42,7 @@ def sanitize_dir(directory):

def report(self, cov):
# N.B. this method is 99% copied from the coverage source code;
# unfortunately, the coverage v5 style of `get_analysis_to_report`
# unfortunately, the coverage v5+ style of `get_analysis_to_report`
# errors out entirely if any source file has issues -- which would be a
# breaking change for us. In the interest of backwards compatibility,
# I've copied their code here so we can maintain the same `coveralls`
Expand Down Expand Up @@ -65,18 +72,20 @@ def report(self, cov):
# raise

# get_analysis_to_report starts here; changes marked with TODOs
# TODO: in v7.5, this returns list of tuples (fr->morf)
# https://github.com/nedbat/coveragepy/commit/4e5027338b93fc893c5e6e82c8a234c48f0b95e7
file_reporters = cov._get_file_reporters(None) # pylint: disable=W0212
config = cov.config

if config.report_include:
matcher = FnmatchMatcher(prep_patterns(config.report_include))
matcher = GlobMatcher(prep_patterns(config.report_include))
file_reporters = [
fr for fr in file_reporters
if matcher.match(fr.filename)
]

if config.report_omit:
matcher = FnmatchMatcher(prep_patterns(config.report_omit))
matcher = GlobMatcher(prep_patterns(config.report_omit))
file_reporters = [
fr for fr in file_reporters
if not matcher.match(fr.filename)
Expand Down
108 changes: 55 additions & 53 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "coveralls"
version = "3.3.2a0"
version = "3.4.0a0"
description = "Show coverage stats online via coveralls.io"
readme = "README.rst"

Expand Down Expand Up @@ -32,7 +32,7 @@ python-coveralls = "coveralls.cli:main"

[tool.poetry.dependencies]
python = ">=3.8,<3.13"
coverage = ">=5.0,<7.0,!=6.0.*,!=6.1,!=6.1.1"
coverage = ">=5.0,<7.5,!=6.0.*,!=6.1,!=6.1.1"
docopt = ">=0.6.1,<0.7.0"
requests = ">=1.0.0,<3.0.0"

Expand Down
5 changes: 3 additions & 2 deletions tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py{38,39,310,311,312,py3}-cov{5,6}-{default,pyyaml}
envlist = py{38,39,310,311,312,py3}-cov{5,6,7}-{default,pyyaml}

[gh-actions]
python =
Expand All @@ -18,12 +18,13 @@ deps =
pyyaml: PyYAML>=3.10,<7.0
cov5: coverage>=5.0,<6.0
cov6: coverage>=6.0,<7.0
cov7: coverage>=7.0,<7.5
commands =
coverage run --branch --source=coveralls -m pytest tests/
coverage report -m

[testenv:upload]
deps =
coverage>=6.0,<7.0
coverage>=7.0,<8.0
commands =
coveralls --verbose

0 comments on commit 8fb3664

Please sign in to comment.