Skip to content

Commit 709c744

Browse files
committed
refactor, docs: clean-up for #1387
1 parent 2644550 commit 709c744

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

CHANGES.rst

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ Unreleased
3434
time needed. For coverage.py's own test suite, combining was about 17%
3535
faster.
3636

37+
- When searching for completely unexecuted files, coverage.py uses the presence
38+
of ``__init__.py`` files to determine which directories have source that
39+
could have been imported. However, `implicit namespace packages`_ don't
40+
require ``__init__.py``. A new setting ``[report]
41+
include_namespace_packages`` tells coverage.py to consider these directories
42+
during reporting. Thanks to `Felix Horvat <pull 1387_>`_ for the
43+
contribution. Closes `issue 1383`_.
44+
3745
- An empty file has a coverage total of 100%, but used to fail with
3846
``--fail-under``. This has been fixed, closing `issue 1470`_.
3947

@@ -45,9 +53,12 @@ Unreleased
4553

4654
- The ``[run] note`` setting has been completely removed.
4755

56+
.. _implicit namespace packages: https://peps.python.org/pep-0420/
57+
.. _issue 1383: https://github.com/nedbat/coveragepy/issues/1383
4858
.. _issue 1418: https://github.com/nedbat/coveragepy/issues/1418
4959
.. _issue 1421: https://github.com/nedbat/coveragepy/issues/1421
5060
.. _issue 1470: https://github.com/nedbat/coveragepy/issues/1470
61+
.. _pull 1387: https://github.com/nedbat/coveragepy/pull/1387
5162
.. _pull 1479: https://github.com/nedbat/coveragepy/pull/1479
5263

5364

CONTRIBUTORS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Eli Skeggs
6868
Emil Madsen
6969
Éric Larivière
7070
Federico Bond
71+
Felix Horvat
7172
Frazer McLean
7273
Geoff Bache
7374
George Paci

coverage/control.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def _init_for_start(self):
530530
self._inorout = InOrOut(
531531
warn=self._warn,
532532
debug=(self._debug if self._debug.should('trace') else None),
533-
include_namespace_packages=self.config.include_namespace_packages
533+
include_namespace_packages=self.config.include_namespace_packages,
534534
)
535535
self._inorout.configure(self.config)
536536
self._inorout.plugins = self._plugins

coverage/files.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,20 @@ def find_python_files(dirname, include_namespace_packages):
470470
best, but sub-directories are checked for a __init__.py to be sure we only
471471
find the importable files.
472472
473+
If `include_namespace_packages` is True, then the check for __init__.py
474+
files is skipped.
475+
476+
Files with strange characters are skipped, since they couldn't have been
477+
imported, and are probably editor side-files.
478+
473479
"""
474480
for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)):
475-
if (i > 0 and '__init__.py' not in filenames
476-
and not include_namespace_packages):
477-
# If a directory doesn't have __init__.py, then it isn't
478-
# importable and neither are its files
479-
del dirnames[:]
480-
continue
481+
if not include_namespace_packages:
482+
if i > 0 and "__init__.py" not in filenames:
483+
# If a directory doesn't have __init__.py, then it isn't
484+
# importable and neither are its files
485+
del dirnames[:]
486+
continue
481487
for filename in filenames:
482488
# We're only interested in files that look like reasonable Python
483489
# files: Must end with .py or .pyw, and must not have certain funny

doc/config.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,14 @@ See :ref:`source` for details.
415415
[report] include_namespace_packages
416416
...................................
417417

418-
(boolean, default False) Include folders without an ``__init__.py`` in the
419-
coverage.
418+
(boolean, default False) When searching for completely unexecuted files,
419+
include directories without ``__init__.py`` files. These are `implicit
420+
namespace packages`_, and are ususally skipped.
421+
422+
.. _implicit namespace packages: https://peps.python.org/pep-0420/
423+
424+
.. versionadded:: 6.6
425+
420426

421427
.. _config_report_omit:
422428

0 commit comments

Comments
 (0)