nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
3.02k stars 434 forks source link

[low-prio] Possible bug: files without extensions misidentified as Python? #1488

Closed jayaddison closed 4 months ago

jayaddison commented 2 years ago

Describe the bug While running pytest with coverage (v6.5.0) for sphinx, I noticed an unusual warning in the output logs:

sphinx/venv/lib/python3.10/site-packages/coverage/report.py:81: CoverageWarning: Couldn't parse Python file '/home/jka/Documents/personal/sphinx/sphinx/templates/quickstart/Makefile_t' (couldnt-parse)
  coverage._warn(msg, slug="couldnt-parse")

Digging into the code to figure out where that's coming from, I found this conditional block:

https://github.com/nedbat/coveragepy/blob/0ac24533e7f167518b8653d423de5ff7d6229a42/coverage/python.py#L240-L242

To Reproduce How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:

  1. What version of Python are you using? 3.10
  2. What version of coverage.py shows the problem? 6.5.0
  3. What code shows the problem? https://github.com/sphinx-doc/sphinx/commit/cd3f2e435000835dd98a11497440bc16a79ec31c
  4. What commands did you run? pytest --cov=sphinx --cov-config=setup.cfg

Expected behavior No warning should appear.

Additional context I realize that perhaps there could be input types / environments where files don't have extensions that have been supported for historic reasons - and I've read some of the context in #82. Even so it seems like maybe the file shouldn't be considered Python-y.

nedbat commented 1 year ago

Interesting... Jinja is templating the files, and using the template name as the "Python" file name when running the resulting Python code.

You can run this with a simpler command and look at the data collected:

% coverage run -m pytest -k test_quickstart_defaults
====================================================================== test session starts =======================================================================
platform darwin -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0
libraries: Sphinx-6.0.0b3+/cd3f2e435, docutils-0.19
base tempdir: /private/var/folders/10/4sn2sk3j2mg5m116f08_367m0000gq/T/pytest-of-nedbatchelder/pytest-1103
rootdir: /System/Volumes/Data/root/src/bugs/bug1488/sphinx, configfile: pyproject.toml, testpaths: tests
plugins: cov-4.0.0
collected 1842 items / 1841 deselected / 1 selected

tests/test_quickstart.py .                                                                                                                                 [100%]

======================================================================== warnings summary ========================================================================
sphinx/ext/napoleon/iterators.py:9
  /System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/napoleon/iterators.py:9: RemovedInSphinx70Warning: sphinx.ext.napoleon.iterators is deprecated.
    warnings.warn('sphinx.ext.napoleon.iterators is deprecated.',

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================= 1 passed, 1841 deselected, 1 warning in 1.68s ==========================================================

% coverage combine
Combined data file .coverage.C02DR1CCMD6V.26744.812946

% coverage debug data
-- data ------------------------------------------------------
path: /System/Volumes/Data/root/src/bugs/bug1488/sphinx/.coverage
has_arcs: True
174 files:
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/__init__.py: 30 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/__main__.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/addnodes.py: 161 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/application.py: 130 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/__init__.py: 80 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/_epub_base.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/changes.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/dirhtml.py: 14 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/dummy.py: 17 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/epub3.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/gettext.py: 79 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/html/__init__.py: 179 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/html/transforms.py: 16 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/latex/__init__.py: 112 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/latex/constants.py: 108 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/latex/nodes.py: 23 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/latex/theming.py: 30 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/latex/transforms.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/latex/util.py: 10 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/linkcheck.py: 85 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/manpage.py: 32 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/singlehtml.py: 32 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/texinfo.py: 46 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/text.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/builders/xml.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/cmd/__init__.py: 1 line
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/cmd/build.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/cmd/make_mode.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/cmd/quickstart.py: 223 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/config.py: 128 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/deprecation.py: 36 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/directives/__init__.py: 57 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/directives/code.py: 107 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/directives/other.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/directives/patches.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/__init__.py: 73 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/c.py: 648 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/changeset.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/citation.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/cpp.py: 1330 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/index.py: 35 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/javascript.py: 119 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/math.py: 46 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/python.py: 287 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/rst.py: 81 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/domains/std.py: 205 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/__init__.py: 101 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/adapters/__init__.py: 1 line
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/adapters/asset.py: 5 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/adapters/indexentries.py: 17 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/adapters/toctree.py: 23 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/collectors/__init__.py: 17 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/collectors/asset.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/collectors/dependencies.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/collectors/metadata.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/collectors/title.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/environment/collectors/toctree.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/errors.py: 49 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/events.py: 40 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/__init__.py: 1 line
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/apidoc.py: 44 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/__init__.py: 356 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/directive.py: 35 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/importer.py: 25 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/mock.py: 52 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/preserve_defaults.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/type_comment.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autodoc/typehints.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autosectionlabel.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autosummary/__init__.py: 95 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/autosummary/generate.py: 71 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/coverage.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/doctest.py: 96 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/duration.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/extlinks.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/githubpages.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/graphviz.py: 89 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/ifconfig.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/imgconverter.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/imgmath.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/inheritance_diagram.py: 84 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/intersphinx.py: 99 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/linkcode.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/mathjax.py: 18 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/napoleon/__init__.py: 32 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/napoleon/docstring.py: 125 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/napoleon/iterators.py: 20 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/todo.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/ext/viewcode.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/extension.py: 13 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/highlighting.py: 40 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/io.py: 51 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/jinja2glue.py: 51 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/locale/__init__.py: 79 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/parsers.py: 24 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/project.py: 18 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/pycode/__init__.py: 34 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/pycode/ast.py: 54 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/pycode/parser.py: 72 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/pygments_styles.py: 60 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/registry.py: 105 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/roles.py: 93 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/__init__.py: 82 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/da.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/de.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/en.py: 14 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/es.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/fi.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/fr.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/hu.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/it.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/ja.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/nl.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/no.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/pt.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/ro.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/ru.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/sv.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/tr.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/search/zh.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/setup_command.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/templates/quickstart/Makefile_t: 18 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/templates/quickstart/make.bat_t: 18 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/templates/quickstart/root_doc.rst_t: 29 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/testing/__init__.py: 1 line
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/testing/comparer.py: 15 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/testing/fixtures.py: 49 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/testing/path.py: 46 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/testing/restructuredtext.py: 8 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/testing/util.py: 54 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/theming.py: 40 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/__init__.py: 108 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/compact_bullet_list.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/i18n.py: 38 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/post_transforms/__init__.py: 47 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/post_transforms/code.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/post_transforms/images.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/transforms/references.py: 13 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/__init__.py: 94 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/build_phase.py: 9 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/cfamily.py: 100 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/console.py: 50 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/docfields.py: 66 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/docstrings.py: 9 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/docutils.py: 141 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/fileutil.py: 14 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/i18n.py: 83 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/images.py: 23 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/inspect.py: 91 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/inventory.py: 27 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/jsdump.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/logging.py: 133 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/matching.py: 38 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/math.py: 6 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/nodes.py: 115 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/osutil.py: 42 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/parallel.py: 31 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/png.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/requests.py: 17 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/rst.py: 29 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/stemmer/__init__.py: 0 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/tags.py: 17 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/template.py: 50 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/texescape.py: 15 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/util/typing.py: 29 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/versioning.py: 24 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/__init__.py: 1 line
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/html5.py: 143 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/html.py: 153 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/latex.py: 326 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/manpage.py: 105 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/texinfo.py: 299 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/text.py: 272 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/writers/xml.py: 0 lines

Notice the lines:

/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/templates/quickstart/Makefile_t: 18 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/templates/quickstart/make.bat_t: 18 lines
/System/Volumes/Data/root/src/bugs/bug1488/sphinx/sphinx/templates/quickstart/root_doc.rst_t: 29 lines

These are not Python files, but Jinja is turning them into Python code and using the original file name. The second and third files are ignored because their file extension excludes them. The first is considered a possible Python file because coverage.py wants to allow extensionless files being used as scripts.

I'm not sure if there's a way to keep that behavior and also not pester you with warnings.

jayaddison commented 1 year ago

These are not Python files, but Jinja is turning them into Python code and using the original file name. The second and third files are ignored because their file extension excludes them.

That makes sense, thanks!

I briefly wondered whether it'd be possible to test those extensionless-script files for a first-line starting with #! that includes the string /python.. but I suppose it's not guaranteed that the files will even be text files (also, this warning doesn't seem hugely noisy).

jayaddison commented 1 year ago

I'm thinking about closing this issue, although also considering what changes would be required to reduce these warnings.

The best alternative to doing-nothing here (which would probably be fine) that I can think of would be:

One factor that I don't yet completely understand is: would coveragepy report correctly on the code coverage achieved within those templates? (it is totally valid to want to achieve code test coverage for templates; what's unclear to me is whether that already works)

Another relevant factor is that adding that new extension would affect not only the sphinx codebase, but also many other codebases that coveragepy is used for. Maybe that'd be positive, but any change has the potential for disruption, and if the value of the change isn't worth maintainer time, then it may not be worth doing in the first place.

jayaddison commented 1 year ago

@nedbat what do you think about adding .jinja as a file extension that should_be_python considers as potentially containing Python code for coverage reporting purposes?

jayaddison commented 4 months ago

Sphinx v7.4.0 introduces support for the .jinja suffix on template filenames - it may take some time before downstream Sphinx ecosystem themes/extensions, but as they do, I hope that the frequency of this warning will reduce.

Even so: re-reading the thread, the detail about other scripts without extensions stands out as something that would require continued support; so I think I will close this and the associated pull request that I had opened.