From 18629f1a3f4db4475c12e13c412a73b039acdc5a Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 13:34:27 +0200 Subject: [PATCH 1/8] add support for namespace packages --- coverage/cmdline.py | 16 ++++++++++++++++ coverage/control.py | 11 ++++++++++- coverage/files.py | 5 +++-- coverage/inorout.py | 8 ++++++-- tests/test_cmdline.py | 5 +++-- tests/test_files.py | 19 ++++++++++++++++++- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/coverage/cmdline.py b/coverage/cmdline.py index dbf66e0a8..046557862 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -111,6 +111,10 @@ class Opts: "Accepts shell-style wildcards, which must be quoted." ), ) + include_namespace_packages = optparse.make_option( + '', '--include_namespace_packages', action='store_true', + help="Include folders without and __init__.py in the Coverage.", + ) pylib = optparse.make_option( '-L', '--pylib', action='store_true', help=( @@ -223,6 +227,9 @@ class Opts: ) + + + class CoverageOptionParser(optparse.OptionParser): """Base OptionParser for coverage.py. @@ -248,6 +255,7 @@ def __init__(self, *args, **kwargs): help=None, ignore_errors=None, include=None, + include_namespace_packages=False, keep=None, module=None, omit=None, @@ -360,6 +368,7 @@ def get_prog_name(self): Opts.input_datafile, Opts.ignore_errors, Opts.include, + Opts.include_namespace_packages, Opts.omit, ] + GLOBAL_ARGS, usage="[options] [modules]", @@ -426,6 +435,7 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, + Opts.include_namespace_packages, Opts.omit, Opts.precision, Opts.quiet, @@ -451,6 +461,7 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, + Opts.include_namespace_packages, Opts.omit, Opts.output_json, Opts.json_pretty_print, @@ -468,6 +479,7 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, + Opts.include_namespace_packages, Opts.output_lcov, Opts.omit, Opts.quiet, @@ -484,6 +496,7 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, + Opts.include_namespace_packages, Opts.omit, Opts.precision, Opts.sort, @@ -505,6 +518,7 @@ def get_prog_name(self): Opts.context, Opts.output_datafile, Opts.include, + Opts.include_namespace_packages, Opts.module, Opts.omit, Opts.pylib, @@ -523,6 +537,7 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, + Opts.include_namespace_packages, Opts.omit, Opts.output_xml, Opts.quiet, @@ -641,6 +656,7 @@ def command_line(self, argv): source=source, omit=omit, include=include, + include_namespace_packages=options.include_namespace_packages, debug=debug, concurrency=concurrency, check_preimported=True, diff --git a/coverage/control.py b/coverage/control.py index a0571c976..585cf4f34 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -109,7 +109,7 @@ def __init__( auto_data=False, timid=None, branch=None, config_file=True, source=None, source_pkgs=None, omit=None, include=None, debug=None, concurrency=None, check_preimported=False, context=None, - messages=False, + messages=False, include_namespace_packages=False ): # pylint: disable=too-many-arguments """ Many of these arguments duplicate and override values that can be @@ -183,6 +183,10 @@ def __init__( If `messages` is true, some messages will be printed to stdout indicating what is happening. + If `include_namespace_packages` is true folders without an + __init__.py file will be included in the coverage + + .. versionadded:: 4.0 The `concurrency` parameter. @@ -198,6 +202,9 @@ def __init__( .. versionadded:: 6.0 The `messages` parameter. + .. versionadded:: 6.4 + The `include_namespace_packages` parameter. + """ # data_file=None means no disk file at all. data_file missing means # use the value from the config file. @@ -212,6 +219,7 @@ def __init__( self._auto_load = self._auto_save = auto_data self._data_suffix_specified = data_suffix + self._include_namespace_packages = include_namespace_packages # Is it ok for no data to be collected? self._warn_no_data = True @@ -526,6 +534,7 @@ def _init_for_start(self): self._inorout = InOrOut( warn=self._warn, debug=(self._debug if self._debug.should('trace') else None), + include_namespace_packages=self._include_namespace_packages ) self._inorout.configure(self.config) self._inorout.plugins = self._plugins diff --git a/coverage/files.py b/coverage/files.py index 09f09da79..ec1aaf56f 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -395,7 +395,7 @@ def map(self, path): return path -def find_python_files(dirname): +def find_python_files(dirname, include_namespace_packages): """Yield all of the importable Python files in `dirname`, recursively. To be importable, the files have to be in a directory with a __init__.py, @@ -406,7 +406,8 @@ def find_python_files(dirname): """ for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)): - if i > 0 and '__init__.py' not in filenames: + if (i > 0 and '__init__.py' not in filenames + and not include_namespace_packages): # If a directory doesn't have __init__.py, then it isn't # importable and neither are its files del dirnames[:] diff --git a/coverage/inorout.py b/coverage/inorout.py index ec89d1b49..ad7722578 100644 --- a/coverage/inorout.py +++ b/coverage/inorout.py @@ -189,9 +189,10 @@ def add_coverage_paths(paths): class InOrOut: """Machinery for determining what files to measure.""" - def __init__(self, warn, debug): + def __init__(self, warn, debug, include_namespace_packages): self.warn = warn self.debug = debug + self.include_namespace_packages = include_namespace_packages # The matchers for should_trace. self.source_match = None @@ -565,7 +566,10 @@ def _find_executable_files(self, src_dir): Yield the file path, and the plugin name that handles the file. """ - py_files = ((py_file, None) for py_file in find_python_files(src_dir)) + py_files = ( + (py_file, None) for py_file in + find_python_files(src_dir, self.include_namespace_packages) + ) plugin_files = self._find_plugin_files(src_dir) for file_path, plugin_name in itertools.chain(py_files, plugin_files): diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 305fbdbff..e52fec7ff 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -61,8 +61,9 @@ class BaseCmdLineTest(CoverageTest): _defaults.Coverage( data_file=DEFAULT_DATAFILE, cover_pylib=None, data_suffix=None, timid=None, branch=None, - config_file=True, source=None, include=None, omit=None, debug=None, - concurrency=None, check_preimported=True, context=None, messages=True, + config_file=True, source=None, include=None, include_namespace_packages=False, + omit=None, debug=None, concurrency=None, check_preimported=True, context=None, + messages=True, ) DEFAULT_KWARGS = {name: kw for name, _, kw in _defaults.mock_calls} diff --git a/tests/test_files.py b/tests/test_files.py index 5588c373d..b217389de 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -413,13 +413,30 @@ def test_find_python_files(self): self.make_file("sub/ssub/~s.py") # nope: editor effluvia self.make_file("sub/lab/exp.py") # nope: no __init__.py self.make_file("sub/windows.pyw") - py_files = set(find_python_files("sub")) + py_files = set(find_python_files("sub", False)) self.assert_same_files(py_files, [ "sub/a.py", "sub/b.py", "sub/ssub/__init__.py", "sub/ssub/s.py", "sub/windows.pyw", ]) + def test_find_python_files_include_namespace_packages(self): + self.make_file("sub/a.py") + self.make_file("sub/b.py") + self.make_file("sub/x.c") # nope: not .py + self.make_file("sub/ssub/__init__.py") + self.make_file("sub/ssub/s.py") + self.make_file("sub/ssub/~s.py") # nope: editor effluvia + self.make_file("sub/lab/exp.py") + self.make_file("sub/windows.pyw") + py_files = set(find_python_files("sub", True)) + self.assert_same_files(py_files, [ + "sub/a.py", "sub/b.py", + "sub/ssub/__init__.py", "sub/ssub/s.py", + "sub/lab/exp.py", + "sub/windows.pyw", + ]) + @pytest.mark.skipif(not env.WINDOWS, reason="Only need to run Windows tests on Windows.") class WindowsFileTest(CoverageTest): From 15692ec9b488dac790c148ebe0a1c66ef5a882d0 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 13:38:00 +0200 Subject: [PATCH 2/8] fixed typo --- coverage/cmdline.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 046557862..82fe58789 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -113,7 +113,7 @@ class Opts: ) include_namespace_packages = optparse.make_option( '', '--include_namespace_packages', action='store_true', - help="Include folders without and __init__.py in the Coverage.", + help="Include folders without an __init__.py in the Coverage.", ) pylib = optparse.make_option( '-L', '--pylib', action='store_true', @@ -227,9 +227,6 @@ class Opts: ) - - - class CoverageOptionParser(optparse.OptionParser): """Base OptionParser for coverage.py. From 73ec4fb7d18da249cad4a64d8755976ff44a4d3a Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 13:47:55 +0200 Subject: [PATCH 3/8] update documentation --- doc/cmd.rst | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/doc/cmd.rst b/doc/cmd.rst index e2a60fc20..e494d4053 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -140,6 +140,9 @@ There are many options: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. -m, --module is an importable Python module, not a script path, to be run as 'python -m' would run it. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. @@ -160,7 +163,7 @@ There are many options: --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 05d15818e42e6f989c42894fb2b3c753) +.. [[[end]]] (checksum: 2c92816941a91a9c2c0ae8e23dd02102) If you want :ref:`branch coverage ` measurement, use the ``--branch`` flag. Otherwise only statement coverage is measured. @@ -515,6 +518,9 @@ as a percentage. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --precision=N Number of digits after the decimal point to display @@ -532,7 +538,7 @@ as a percentage. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 2f8dde61bab2f44fbfe837aeae87dfd2) +.. [[[end]]] (checksum: a831cc0bdc5e14ec46e300f0cf8b5d27) The ``-m`` flag also shows the line numbers of missing statements:: @@ -634,6 +640,9 @@ Click the keyboard icon in the upper right to see the complete list. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --precision=N Number of digits after the decimal point to display @@ -650,7 +659,7 @@ Click the keyboard icon in the upper right to see the complete list. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: e3a1a6e24ad9b303ba06d42880ed0219) +.. [[[end]]] (checksum: 2fe1c0beaeb4fbdccbd1e69833233143) The title of the report can be set with the ``title`` setting in the ``[html]`` section of the configuration file, or the ``--title`` switch on @@ -715,6 +724,9 @@ compatible with `Cobertura`_. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -o OUTFILE Write the XML report to this file. Defaults to @@ -727,7 +739,7 @@ compatible with `Cobertura`_. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 8b239d89534be0b2c69489e10b1352a9) +.. [[[end]]] (checksum: 042eddbe0fc48894c1326645a936a39b) You can specify the name of the output file with the ``-o`` switch. @@ -803,6 +815,9 @@ The **json** command writes coverage data to a "coverage.json" file. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -o OUTFILE Write the JSON report to this file. Defaults to @@ -816,7 +831,7 @@ The **json** command writes coverage data to a "coverage.json" file. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: e53e60cb65d971c35d1db1c08324b72e) +.. [[[end]]] (checksum: a49de4d114bf990dc8422f2ae130d1fc) You can specify the name of the output file with the ``-o`` switch. The JSON can be nicely formatted by specifying the ``--pretty-print`` switch. @@ -851,6 +866,9 @@ The **lcov** command writes coverage data to a "coverage.lcov" file. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. -o OUTFILE Write the LCOV report to this file. Defaults to 'coverage.lcov' --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. @@ -862,7 +880,7 @@ The **lcov** command writes coverage data to a "coverage.lcov" file. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 16acfbae8011d2e3b620695c5fe13746) +.. [[[end]]] (checksum: 646ab6eca5ae5953a461ae3ac434470f) Common reporting options are described above in :ref:`cmd_reporting`. Also see :ref:`Configuration: [lcov] `. @@ -924,6 +942,9 @@ For example:: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. + --include_namespace_packages + Include folders without an __init__.py in the + Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --debug=OPTS Debug options, separated by commas. [env: @@ -932,7 +953,7 @@ For example:: --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: fd7d8fbd2dd6e24d37f868b389c2ad6d) +.. [[[end]]] (checksum: 5e7c1705047e4f289d8ba701ee2ae185) Other common reporting options are described above in :ref:`cmd_reporting`. From 92687ea9cb2658091413189635a852cf3781066e Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 13:59:44 +0200 Subject: [PATCH 4/8] fixed lint issues --- coverage/files.py | 2 +- coverage/inorout.py | 2 +- tests/test_cmdline.py | 4 ++-- tests/test_files.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/coverage/files.py b/coverage/files.py index ec1aaf56f..5cad254ee 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -406,7 +406,7 @@ def find_python_files(dirname, include_namespace_packages): """ for i, (dirpath, dirnames, filenames) in enumerate(os.walk(dirname)): - if (i > 0 and '__init__.py' not in filenames + if (i > 0 and '__init__.py' not in filenames and not include_namespace_packages): # If a directory doesn't have __init__.py, then it isn't # importable and neither are its files diff --git a/coverage/inorout.py b/coverage/inorout.py index ad7722578..780935282 100644 --- a/coverage/inorout.py +++ b/coverage/inorout.py @@ -567,7 +567,7 @@ def _find_executable_files(self, src_dir): """ py_files = ( - (py_file, None) for py_file in + (py_file, None) for py_file in find_python_files(src_dir, self.include_namespace_packages) ) plugin_files = self._find_plugin_files(src_dir) diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index e52fec7ff..624ae972f 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -61,8 +61,8 @@ class BaseCmdLineTest(CoverageTest): _defaults.Coverage( data_file=DEFAULT_DATAFILE, cover_pylib=None, data_suffix=None, timid=None, branch=None, - config_file=True, source=None, include=None, include_namespace_packages=False, - omit=None, debug=None, concurrency=None, check_preimported=True, context=None, + config_file=True, source=None, include=None, include_namespace_packages=False, + omit=None, debug=None, concurrency=None, check_preimported=True, context=None, messages=True, ) diff --git a/tests/test_files.py b/tests/test_files.py index b217389de..8ea6daf02 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -427,7 +427,7 @@ def test_find_python_files_include_namespace_packages(self): self.make_file("sub/ssub/__init__.py") self.make_file("sub/ssub/s.py") self.make_file("sub/ssub/~s.py") # nope: editor effluvia - self.make_file("sub/lab/exp.py") + self.make_file("sub/lab/exp.py") self.make_file("sub/windows.pyw") py_files = set(find_python_files("sub", True)) self.assert_same_files(py_files, [ From 117a07c06d74dfb6ce962babc3b11d06d6ce2442 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 14:31:13 +0200 Subject: [PATCH 5/8] changed versionadded --- coverage/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coverage/control.py b/coverage/control.py index 585cf4f34..a0e017ad4 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -202,7 +202,7 @@ def __init__( .. versionadded:: 6.0 The `messages` parameter. - .. versionadded:: 6.4 + .. versionadded:: 6.5 The `include_namespace_packages` parameter. """ From 8616f1b03a18d64b8556ef311660e69a43b9f554 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 17:48:58 +0200 Subject: [PATCH 6/8] convert to config setting --- coverage/cmdline.py | 13 ------------- coverage/config.py | 2 ++ coverage/control.py | 11 ++--------- doc/cmd.rst | 35 +++++++---------------------------- doc/config.rst | 8 ++++++++ tests/test_cmdline.py | 5 ++--- tests/test_config.py | 2 ++ 7 files changed, 23 insertions(+), 53 deletions(-) diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 82fe58789..dbf66e0a8 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -111,10 +111,6 @@ class Opts: "Accepts shell-style wildcards, which must be quoted." ), ) - include_namespace_packages = optparse.make_option( - '', '--include_namespace_packages', action='store_true', - help="Include folders without an __init__.py in the Coverage.", - ) pylib = optparse.make_option( '-L', '--pylib', action='store_true', help=( @@ -252,7 +248,6 @@ def __init__(self, *args, **kwargs): help=None, ignore_errors=None, include=None, - include_namespace_packages=False, keep=None, module=None, omit=None, @@ -365,7 +360,6 @@ def get_prog_name(self): Opts.input_datafile, Opts.ignore_errors, Opts.include, - Opts.include_namespace_packages, Opts.omit, ] + GLOBAL_ARGS, usage="[options] [modules]", @@ -432,7 +426,6 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, - Opts.include_namespace_packages, Opts.omit, Opts.precision, Opts.quiet, @@ -458,7 +451,6 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, - Opts.include_namespace_packages, Opts.omit, Opts.output_json, Opts.json_pretty_print, @@ -476,7 +468,6 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, - Opts.include_namespace_packages, Opts.output_lcov, Opts.omit, Opts.quiet, @@ -493,7 +484,6 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, - Opts.include_namespace_packages, Opts.omit, Opts.precision, Opts.sort, @@ -515,7 +505,6 @@ def get_prog_name(self): Opts.context, Opts.output_datafile, Opts.include, - Opts.include_namespace_packages, Opts.module, Opts.omit, Opts.pylib, @@ -534,7 +523,6 @@ def get_prog_name(self): Opts.fail_under, Opts.ignore_errors, Opts.include, - Opts.include_namespace_packages, Opts.omit, Opts.output_xml, Opts.quiet, @@ -653,7 +641,6 @@ def command_line(self, argv): source=source, omit=omit, include=include, - include_namespace_packages=options.include_namespace_packages, debug=debug, concurrency=concurrency, check_preimported=True, diff --git a/coverage/config.py b/coverage/config.py index 1ad46597c..40d9413ac 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -184,6 +184,7 @@ def __init__(self): self.debug = [] self.disable_warnings = [] self.dynamic_context = None + self.include_namespace_packages = False self.note = None self.parallel = False self.plugins = [] @@ -359,6 +360,7 @@ def copy(self): ('debug', 'run:debug', 'list'), ('disable_warnings', 'run:disable_warnings', 'list'), ('dynamic_context', 'run:dynamic_context'), + ('include_namespace_packages', 'run:include_namespace_packages', 'boolean'), ('note', 'run:note'), ('parallel', 'run:parallel', 'boolean'), ('plugins', 'run:plugins', 'list'), diff --git a/coverage/control.py b/coverage/control.py index a0e017ad4..d41f7b58c 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -109,7 +109,7 @@ def __init__( auto_data=False, timid=None, branch=None, config_file=True, source=None, source_pkgs=None, omit=None, include=None, debug=None, concurrency=None, check_preimported=False, context=None, - messages=False, include_namespace_packages=False + messages=False ): # pylint: disable=too-many-arguments """ Many of these arguments duplicate and override values that can be @@ -183,9 +183,6 @@ def __init__( If `messages` is true, some messages will be printed to stdout indicating what is happening. - If `include_namespace_packages` is true folders without an - __init__.py file will be included in the coverage - .. versionadded:: 4.0 The `concurrency` parameter. @@ -202,9 +199,6 @@ def __init__( .. versionadded:: 6.0 The `messages` parameter. - .. versionadded:: 6.5 - The `include_namespace_packages` parameter. - """ # data_file=None means no disk file at all. data_file missing means # use the value from the config file. @@ -219,7 +213,6 @@ def __init__( self._auto_load = self._auto_save = auto_data self._data_suffix_specified = data_suffix - self._include_namespace_packages = include_namespace_packages # Is it ok for no data to be collected? self._warn_no_data = True @@ -534,7 +527,7 @@ def _init_for_start(self): self._inorout = InOrOut( warn=self._warn, debug=(self._debug if self._debug.should('trace') else None), - include_namespace_packages=self._include_namespace_packages + include_namespace_packages=self.config.include_namespace_packages ) self._inorout.configure(self.config) self._inorout.plugins = self._plugins diff --git a/doc/cmd.rst b/doc/cmd.rst index e494d4053..e2a60fc20 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -140,9 +140,6 @@ There are many options: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. -m, --module is an importable Python module, not a script path, to be run as 'python -m' would run it. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. @@ -163,7 +160,7 @@ There are many options: --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 2c92816941a91a9c2c0ae8e23dd02102) +.. [[[end]]] (checksum: 05d15818e42e6f989c42894fb2b3c753) If you want :ref:`branch coverage ` measurement, use the ``--branch`` flag. Otherwise only statement coverage is measured. @@ -518,9 +515,6 @@ as a percentage. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --precision=N Number of digits after the decimal point to display @@ -538,7 +532,7 @@ as a percentage. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: a831cc0bdc5e14ec46e300f0cf8b5d27) +.. [[[end]]] (checksum: 2f8dde61bab2f44fbfe837aeae87dfd2) The ``-m`` flag also shows the line numbers of missing statements:: @@ -640,9 +634,6 @@ Click the keyboard icon in the upper right to see the complete list. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --precision=N Number of digits after the decimal point to display @@ -659,7 +650,7 @@ Click the keyboard icon in the upper right to see the complete list. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 2fe1c0beaeb4fbdccbd1e69833233143) +.. [[[end]]] (checksum: e3a1a6e24ad9b303ba06d42880ed0219) The title of the report can be set with the ``title`` setting in the ``[html]`` section of the configuration file, or the ``--title`` switch on @@ -724,9 +715,6 @@ compatible with `Cobertura`_. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -o OUTFILE Write the XML report to this file. Defaults to @@ -739,7 +727,7 @@ compatible with `Cobertura`_. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 042eddbe0fc48894c1326645a936a39b) +.. [[[end]]] (checksum: 8b239d89534be0b2c69489e10b1352a9) You can specify the name of the output file with the ``-o`` switch. @@ -815,9 +803,6 @@ The **json** command writes coverage data to a "coverage.json" file. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. -o OUTFILE Write the JSON report to this file. Defaults to @@ -831,7 +816,7 @@ The **json** command writes coverage data to a "coverage.json" file. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: a49de4d114bf990dc8422f2ae130d1fc) +.. [[[end]]] (checksum: e53e60cb65d971c35d1db1c08324b72e) You can specify the name of the output file with the ``-o`` switch. The JSON can be nicely formatted by specifying the ``--pretty-print`` switch. @@ -866,9 +851,6 @@ The **lcov** command writes coverage data to a "coverage.lcov" file. Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. -o OUTFILE Write the LCOV report to this file. Defaults to 'coverage.lcov' --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. @@ -880,7 +862,7 @@ The **lcov** command writes coverage data to a "coverage.lcov" file. --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 646ab6eca5ae5953a461ae3ac434470f) +.. [[[end]]] (checksum: 16acfbae8011d2e3b620695c5fe13746) Common reporting options are described above in :ref:`cmd_reporting`. Also see :ref:`Configuration: [lcov] `. @@ -942,9 +924,6 @@ For example:: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. - --include_namespace_packages - Include folders without an __init__.py in the - Coverage. --omit=PAT1,PAT2,... Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted. --debug=OPTS Debug options, separated by commas. [env: @@ -953,7 +932,7 @@ For example:: --rcfile=RCFILE Specify configuration file. By default '.coveragerc', 'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried. [env: COVERAGE_RCFILE] -.. [[[end]]] (checksum: 5e7c1705047e4f289d8ba701ee2ae185) +.. [[[end]]] (checksum: fd7d8fbd2dd6e24d37f868b389c2ad6d) Other common reporting options are described above in :ref:`cmd_reporting`. diff --git a/doc/config.rst b/doc/config.rst index 70f56c0e5..d595734ea 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -216,6 +216,14 @@ measurement or reporting. Ignored if ``source`` is set. See :ref:`source` for details. +.. _config_include_namespace_packages: + +[run] include_namespace_packages +................................ + +(boolean, default False) Include folders without an ``__init__.py`` in the +Coverage. + .. _config_run_note: [run] note diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 624ae972f..305fbdbff 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -61,9 +61,8 @@ class BaseCmdLineTest(CoverageTest): _defaults.Coverage( data_file=DEFAULT_DATAFILE, cover_pylib=None, data_suffix=None, timid=None, branch=None, - config_file=True, source=None, include=None, include_namespace_packages=False, - omit=None, debug=None, concurrency=None, check_preimported=True, context=None, - messages=True, + config_file=True, source=None, include=None, omit=None, debug=None, + concurrency=None, check_preimported=True, context=None, messages=True, ) DEFAULT_KWARGS = {name: kw for name, _, kw in _defaults.mock_calls} diff --git a/tests/test_config.py b/tests/test_config.py index 6aa435112..f9a683175 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -456,6 +456,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): plugins.another debug = callers, pids , dataio disable_warnings = abcd , efgh + include_namespace_packages = TRUE [{section}report] ; these settings affect reporting. @@ -577,6 +578,7 @@ def assert_config_settings_are_correct(self, cov): assert cov.config.get_plugin_options("plugins.another") == {} assert cov.config.json_show_contexts is True assert cov.config.json_pretty_print is True + assert cov.config.include_namespace_packages is True def test_config_file_settings(self): self.make_file(".coveragerc", self.LOTSA_SETTINGS.format(section="")) From c52bd84f09687580e16802450c7cef900075add4 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Mon, 30 May 2022 17:51:18 +0200 Subject: [PATCH 7/8] removed pure formatting changes --- coverage/control.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/coverage/control.py b/coverage/control.py index d41f7b58c..114660ae0 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -109,7 +109,7 @@ def __init__( auto_data=False, timid=None, branch=None, config_file=True, source=None, source_pkgs=None, omit=None, include=None, debug=None, concurrency=None, check_preimported=False, context=None, - messages=False + messages=False, ): # pylint: disable=too-many-arguments """ Many of these arguments duplicate and override values that can be @@ -183,7 +183,6 @@ def __init__( If `messages` is true, some messages will be printed to stdout indicating what is happening. - .. versionadded:: 4.0 The `concurrency` parameter. From 35e8942f8bf8ff49f6c9dbbdca00304c5085d64c Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Tue, 31 May 2022 15:16:29 +0200 Subject: [PATCH 8/8] code review changes --- coverage/config.py | 2 +- doc/config.rst | 16 ++++++++-------- tests/test_config.py | 3 ++- tests/test_files.py | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/coverage/config.py b/coverage/config.py index 40d9413ac..0601407b3 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -360,7 +360,6 @@ def copy(self): ('debug', 'run:debug', 'list'), ('disable_warnings', 'run:disable_warnings', 'list'), ('dynamic_context', 'run:dynamic_context'), - ('include_namespace_packages', 'run:include_namespace_packages', 'boolean'), ('note', 'run:note'), ('parallel', 'run:parallel', 'boolean'), ('plugins', 'run:plugins', 'list'), @@ -377,6 +376,7 @@ def copy(self): ('exclude_list', 'report:exclude_lines', 'regexlist'), ('fail_under', 'report:fail_under', 'float'), ('ignore_errors', 'report:ignore_errors', 'boolean'), + ('include_namespace_packages', 'report:include_namespace_packages', 'boolean'), ('partial_always_list', 'report:partial_branches_always', 'regexlist'), ('partial_list', 'report:partial_branches', 'regexlist'), ('precision', 'report:precision', 'int'), diff --git a/doc/config.rst b/doc/config.rst index d595734ea..33ea51d8b 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -216,14 +216,6 @@ measurement or reporting. Ignored if ``source`` is set. See :ref:`source` for details. -.. _config_include_namespace_packages: - -[run] include_namespace_packages -................................ - -(boolean, default False) Include folders without an ``__init__.py`` in the -Coverage. - .. _config_run_note: [run] note @@ -417,6 +409,14 @@ warning instead of an exception. See :ref:`source` for details. +.. _config_include_namespace_packages: + +[report] include_namespace_packages +................................... + +(boolean, default False) Include folders without an ``__init__.py`` in the +coverage. + .. _config_report_omit: [report] omit diff --git a/tests/test_config.py b/tests/test_config.py index f9a683175..5e52764ee 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -456,7 +456,6 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): plugins.another debug = callers, pids , dataio disable_warnings = abcd , efgh - include_namespace_packages = TRUE [{section}report] ; these settings affect reporting. @@ -483,6 +482,8 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): skip_covered = TruE skip_empty =TruE + include_namespace_packages = TRUE + [{section}html] directory = c:\\tricky\\dir.somewhere diff --git a/tests/test_files.py b/tests/test_files.py index 8ea6daf02..9a580feff 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -413,7 +413,7 @@ def test_find_python_files(self): self.make_file("sub/ssub/~s.py") # nope: editor effluvia self.make_file("sub/lab/exp.py") # nope: no __init__.py self.make_file("sub/windows.pyw") - py_files = set(find_python_files("sub", False)) + py_files = set(find_python_files("sub", include_namespace_packages=False)) self.assert_same_files(py_files, [ "sub/a.py", "sub/b.py", "sub/ssub/__init__.py", "sub/ssub/s.py", @@ -429,7 +429,7 @@ def test_find_python_files_include_namespace_packages(self): self.make_file("sub/ssub/~s.py") # nope: editor effluvia self.make_file("sub/lab/exp.py") self.make_file("sub/windows.pyw") - py_files = set(find_python_files("sub", True)) + py_files = set(find_python_files("sub", include_namespace_packages=True)) self.assert_same_files(py_files, [ "sub/a.py", "sub/b.py", "sub/ssub/__init__.py", "sub/ssub/s.py",