Skip to content

fix: some windows versions don't make this directory? #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f217d0d
refactor: remove unneeded pydoc weirdness
nedbat Feb 25, 2023
c3a3421
fix: export our public names for type checking. #1564
nedbat Feb 24, 2023
fe807db
docs: build steps need to make a release-prep branch sooner
nedbat Feb 26, 2023
795a56a
docs: prep for 7.2.1
nedbat Feb 26, 2023
9fcf1d6
docs: sample html for 7.2.1
nedbat Feb 26, 2023
499f4f5
build: bump version
nedbat Feb 26, 2023
4895797
chore: make upgrade
nedbat Mar 7, 2023
d76daad
build: run mypy by default, and fix "unused" errors from updated mypy
nedbat Mar 7, 2023
d276fa4
debug: label the assert messages
nedbat Mar 12, 2023
8eb95b5
fix: recent pypy3.9 now omits lines after jumps
nedbat Mar 12, 2023
28aa7be
build: make the coverage workflow more similar to the testsuite workflow
nedbat Mar 12, 2023
f0a8b6f
Fix lcov coverage
imoore76 Mar 13, 2023
44cb89f
docs: changelog for #1583
nedbat Mar 14, 2023
1de3469
docs: never run pip directly
nedbat Mar 14, 2023
9620278
chore: make upgrade
nedbat Mar 14, 2023
9e94ddb
build: use .in from .in
nedbat Mar 14, 2023
dc83ac5
build: run dependency check on pushes, for more action uniformity
nedbat Mar 14, 2023
e47f354
build: will this work on fork pr's?
nedbat Mar 14, 2023
45d76fa
fix: generate xml report packages correctly on windows (#1574)
bparzella Mar 14, 2023
f95ce97
docs: #1573 is fixed, thanks Benjamin Parzella
nedbat Mar 15, 2023
dd7959d
docs: wrap long lines
nedbat Mar 15, 2023
4574ecf
fix: don't measure all third-party packages if source is in third-par…
manueljacob Feb 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ concurrency:

jobs:
coverage:
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
name: "${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: "${{ matrix.os }}-latest"

strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
- ubuntu
- macos
- windows
python-version:
# When changing this list, be sure to check the [gh] list in
# tox.ini so that tox will run properly. PYVERSIONS
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement

name: 'Dependency Review'
on: [pull_request]
on:
push:
branches:
- master
- nedbat/*
pull_request:
workflow_dispatch:

permissions:
contents: read
Expand All @@ -18,3 +25,6 @@ jobs:
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
with:
base-ref: ${{ github.event.pull_request.base.sha || 'master' }}
head-ref: ${{ github.event.pull_request.head.sha || github.ref }}
2 changes: 1 addition & 1 deletion .github/workflows/python-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ concurrency:

jobs:
tests:
name: "Python ${{ matrix.python-version }}"
name: "${{ matrix.python-version }}"
# Choose a recent Ubuntu that deadsnakes still builds all the versions for.
# For example, deadsnakes doesn't provide 3.10 nightly for 22.04 (jammy)
# because jammy ships 3.10, and deadsnakes doesn't want to clobber it.
Expand Down
33 changes: 31 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,42 @@ development at the same time, such as 4.5.x and 5.0.
Unreleased
----------

- Fix: if a virtualenv was created inside a source directory, and a sourced
package was installed inside the virtualenv, then all of the third-party
packages inside the virtualenv would be measured. This was incorrect, but
has now been fixed: only the specified packages will be measured, thanks to
`Manuel Jacob <pull 1560_>`_.

- Fix: the ``coverage lcov`` command could create a .lcov file with incorrect
LF (lines found) and LH (lines hit) totals. This is now fixed, thanks to
`Ian Moore <pull 1583_>`_.

- Fix: the ``coverage xml`` command on Windows could create a .xml file with
duplicate ``<package>`` elements. This is now fixed, thanks to `Benjamin
Parzella <pull 1574_>`_, closing `issue 1573`_.

.. _pull 1560: https://github.com/nedbat/coveragepy/pull/1560
.. _issue 1573: https://github.com/nedbat/coveragepy/issues/1573
.. _pull 1574: https://github.com/nedbat/coveragepy/pull/1574
.. _pull 1583: https://github.com/nedbat/coveragepy/pull/1583


.. scriv-start-here

.. _changes_7-2-1:

Version 7.2.1 — 2023-02-26
--------------------------

- Fix: the PyPI page had broken links to documentation pages, but no longer
does, closing `issue 1566`_.

.. _issue 1566: https://github.com/nedbat/coveragepy/issues/1566
- Fix: public members of the coverage module are now properly indicated so that
mypy will find them, fixing `issue 1564`_.

.. _issue 1564: https://github.com/nedbat/coveragepy/issues/1564
.. _issue 1566: https://github.com/nedbat/coveragepy/issues/1566

.. scriv-start-here

.. _changes_7-2-0:

Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Arthur Deygin
Arthur Rio
Ben Carlsson
Ben Finney
Benjamin Parzella
Benjamin Schubert
Bernát Gábor
Bill Hart
Expand Down Expand Up @@ -79,6 +80,7 @@ Greg Rogers
Guido van Rossum
Guillaume Chazarain
Hugo van Kemenade
Ian Moore
Ilia Meerovich
Imri Goldberg
Ionel Cristian Mărieș
Expand All @@ -105,6 +107,7 @@ Leonardo Pistone
Lex Berezhny
Loïc Dachary
Lorenzo Micò
Manuel Jacob
Marc Abramowitz
Marc Legendre
Marcelo Trylesinski
Expand Down
42 changes: 24 additions & 18 deletions coverage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt

"""Code coverage measurement for Python.
"""
Code coverage measurement for Python.

Ned Batchelder
https://nedbatchelder.com/code/coverage
https://coverage.readthedocs.io

"""

import sys
# mypy's convention is that "import as" names are public from the module.
# We import names as themselves to indicate that. Pylint sees it as pointless,
# so disable its warning.
# pylint: disable=useless-import-alias

from coverage.version import __version__, __url__, version_info
import sys

from coverage.control import Coverage, process_startup
from coverage.data import CoverageData
from coverage.exceptions import CoverageException
from coverage.plugin import CoveragePlugin, FileTracer, FileReporter
from coverage.pytracer import PyTracer
from coverage.version import (
__version__ as __version__,
version_info as version_info,
)

from coverage.control import (
Coverage as Coverage,
process_startup as process_startup,
)
from coverage.data import CoverageData as CoverageData
from coverage.exceptions import CoverageException as CoverageException
from coverage.plugin import (
CoveragePlugin as CoveragePlugin,
FileReporter as FileReporter,
FileTracer as FileTracer,
)

# Backward compatibility.
coverage = Coverage
Expand All @@ -25,12 +40,3 @@
# the encodings.utf_8 module is loaded and then unloaded, I don't know why.
# Adding a reference here prevents it from being unloaded. Yuk.
import encodings.utf_8 # pylint: disable=wrong-import-position, wrong-import-order

# Because of the "from coverage.control import fooey" lines at the top of the
# file, there's an entry for coverage.coverage in sys.modules, mapped to None.
# This makes some inspection tools (like pydoc) unable to find the class
# coverage.coverage. So remove that entry.
try:
del sys.modules['coverage.coverage']
except KeyError:
pass
2 changes: 2 additions & 0 deletions coverage/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from coverage.exceptions import _BaseCoverageException, _ExceptionDuringRun, NoSource
from coverage.execfile import PyRunner
from coverage.results import Numbers, should_fail_under
from coverage.version import __url__

# When adding to this file, alphabetization is important. Look for
# "alphabetize" comments throughout.
Expand Down Expand Up @@ -574,6 +575,7 @@ def show_help(
program_name = program_name[:-len(auto_suffix)]

help_params = dict(coverage.__dict__)
help_params["__url__"] = __url__
help_params['program_name'] = program_name
if HAS_CTRACER:
help_params['extension_modifier'] = 'with C extension'
Expand Down
8 changes: 7 additions & 1 deletion coverage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,17 @@ class PYBEHAVIOR:

# Lines after break/continue/return/raise are no longer compiled into the
# bytecode. They used to be marked as missing, now they aren't executable.
omit_after_jump = pep626
omit_after_jump = (
pep626
or (PYPY and PYVERSION >= (3, 9) and PYPYVERSION >= (7, 3, 12))
)

# PyPy has always omitted statements after return.
omit_after_return = omit_after_jump or PYPY

# Optimize away unreachable try-else clauses.
optimize_unreachable_try_else = pep626

# Modules used to have firstlineno equal to the line number of the first
# real line of code. Now they always start at 1.
module_firstline_1 = pep626
Expand Down
2 changes: 1 addition & 1 deletion coverage/execfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def make_code_from_py(filename: str) -> CodeType:
except (OSError, NoSource) as exc:
raise NoSource(f"No file to run: '{filename}'") from exc

return compile(source, filename, "exec", dont_inherit=True) # type: ignore[no-any-return]
return compile(source, filename, "exec", dont_inherit=True)


def make_code_from_pyc(filename: str) -> CodeType:
Expand Down
3 changes: 2 additions & 1 deletion coverage/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from coverage.results import Analysis, Numbers
from coverage.templite import Templite
from coverage.types import TLineNo, TMorf
from coverage.version import __url__


if TYPE_CHECKING:
Expand Down Expand Up @@ -238,7 +239,7 @@ def __init__(self, cov: Coverage) -> None:
'len': len,

# Constants for this report.
'__url__': coverage.__url__,
'__url__': __url__,
'__version__': coverage.__version__,
'title': title,
'time_stamp': format_local_datetime(datetime.datetime.now()),
Expand Down
25 changes: 13 additions & 12 deletions coverage/inorout.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _debug(msg: str) -> None:
# Check if the source we want to measure has been installed as a
# third-party package.
# Is the source inside a third-party area?
self.source_in_third = False
self.source_in_third_paths = set()
with sys_modules_saved():
for pkg in self.source_pkgs:
try:
Expand All @@ -274,22 +274,23 @@ def _debug(msg: str) -> None:
if modfile:
if self.third_match.match(modfile):
_debug(
f"Source is in third-party because of source_pkg {pkg!r} at {modfile!r}"
f"Source in third-party: source_pkg {pkg!r} at {modfile!r}"
)
self.source_in_third = True
self.source_in_third_paths.add(canonical_path(source_for_file(modfile)))
else:
for pathdir in path:
if self.third_match.match(pathdir):
_debug(
f"Source is in third-party because of {pkg!r} path directory " +
f"at {pathdir!r}"
f"Source in third-party: {pkg!r} path directory at {pathdir!r}"
)
self.source_in_third = True
self.source_in_third_paths.add(pathdir)

for src in self.source:
if self.third_match.match(src):
_debug(f"Source is in third-party because of source directory {src!r}")
self.source_in_third = True
_debug(f"Source in third-party: source directory {src!r}")
self.source_in_third_paths.add(src)
self.source_in_third_match = TreeMatcher(self.source_in_third_paths, "source_in_third")
_debug(f"Source in third-party matching: {self.source_in_third_match}")

self.plugins: Plugins
self.disp_class: Type[TFileDisposition] = FileDisposition
Expand Down Expand Up @@ -419,9 +420,8 @@ def check_include_omit_etc(self, filename: str, frame: Optional[FrameType]) -> O
ok = True
if not ok:
return extra + "falls outside the --source spec"
if not self.source_in_third:
if self.third_match.match(filename):
return "inside --source, but is third-party"
if self.third_match.match(filename) and not self.source_in_third_match.match(filename):
return "inside --source, but is third-party"
elif self.include_match:
if not self.include_match.match(filename):
return "falls outside the --include trees"
Expand Down Expand Up @@ -576,12 +576,13 @@ def sys_info(self) -> Iterable[Tuple[str, Any]]:
("coverage_paths", self.cover_paths),
("stdlib_paths", self.pylib_paths),
("third_party_paths", self.third_paths),
("source_in_third_party_paths", self.source_in_third_paths),
]

matcher_names = [
'source_match', 'source_pkgs_match',
'include_match', 'omit_match',
'cover_match', 'pylib_match', 'third_match',
'cover_match', 'pylib_match', 'third_match', 'source_in_third_match',
]

for matcher_name in matcher_names:
Expand Down
4 changes: 2 additions & 2 deletions coverage/lcovreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def get_lcov(self, fr: FileReporter, analysis: Analysis, outfile: IO[str]) -> No
hashed = base64.b64encode(md5(line).digest()).decode().rstrip("=")
outfile.write(f"DA:{missed},0,{hashed}\n")

outfile.write(f"LF:{len(analysis.statements)}\n")
outfile.write(f"LH:{len(analysis.executed)}\n")
outfile.write(f"LF:{analysis.numbers.n_statements}\n")
outfile.write(f"LH:{analysis.numbers.n_executed}\n")

# More information dense branch coverage data.
missing_arcs = analysis.missing_branch_arcs()
Expand Down
2 changes: 1 addition & 1 deletion coverage/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# version_info: same semantics as sys.version_info.
# _dev: the .devN suffix if any.
version_info = (7, 2, 1, "alpha", 0)
version_info = (7, 2, 2, "alpha", 0)
_dev = 1


Expand Down
5 changes: 3 additions & 2 deletions coverage/xmlreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
from dataclasses import dataclass
from typing import Any, Dict, IO, Iterable, Optional, TYPE_CHECKING, cast

from coverage import __url__, __version__, files
from coverage import __version__, files
from coverage.misc import isolate_module, human_sorted, human_sorted_items
from coverage.plugin import FileReporter
from coverage.report import get_analysis_to_report
from coverage.results import Analysis
from coverage.types import TMorf
from coverage.version import __url__

if TYPE_CHECKING:
from coverage import Coverage
Expand Down Expand Up @@ -181,7 +182,7 @@ def xml_file(self, fr: FileReporter, analysis: Analysis, has_arcs: bool) -> None
rel_name = filename[len(source_path)+1:]
break
else:
rel_name = fr.relative_filename()
rel_name = fr.relative_filename().replace("\\", "/")
self.source_paths.add(fr.filename[:-len(rel_name)].rstrip(r"\/"))

dirname = os.path.dirname(rel_name) or "."
Expand Down
7 changes: 4 additions & 3 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2234,9 +2234,10 @@ Version 3.4 — 2010-09-19
Version 3.4b2 — 2010-09-06
--------------------------

- Completely un-executed files can now be included in coverage results, reported
as 0% covered. This only happens if the --source option is specified, since
coverage.py needs guidance about where to look for source files.
- Completely un-executed files can now be included in coverage results,
reported as 0% covered. This only happens if the --source option is
specified, since coverage.py needs guidance about where to look for source
files.

- The XML report output now properly includes a percentage for branch coverage,
fixing `issue 65`_ and `issue 81`_.
Expand Down
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
# @@@ editable
copyright = "2009–2023, Ned Batchelder" # pylint: disable=redefined-builtin
# The short X.Y.Z version.
version = "7.2.0"
version = "7.2.1"
# The full version, including alpha/beta/rc tags.
release = "7.2.0"
release = "7.2.1"
# The date of release, in "monthname day, year" format.
release_date = "February 22, 2023"
release_date = "February 26, 2023"
# @@@ end

rst_epilog = """
Expand Down
7 changes: 6 additions & 1 deletion doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ these steps:

#. Install the requirements::

$ pip install -r requirements/dev.pip
$ python3 -m pip install -r requirements/dev.pip

If this fails due to incorrect or missing hashes, use
``dev.in`` instead::

$ python3 -m pip install -r requirements/dev.in

#. Install a number of versions of Python. Coverage.py supports a range
of Python versions. The more you can test with, the more easily your code
Expand Down
Loading