Skip to content
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

Allow using Cobertura XML report in incremental mode #9041

Open
The-Compiler opened this issue Jun 24, 2020 · 2 comments
Open

Allow using Cobertura XML report in incremental mode #9041

The-Compiler opened this issue Jun 24, 2020 · 2 comments

Comments

@The-Compiler
Copy link
Contributor

I'm trying to use diff-cover with mypy to enforce any new code to have type annotations. Here's what I use (via tox):

mypy --cobertura-xml-report {envtmpdir} qutebrowser tests {posargs}
diff-cover --fail-under=100 --compare-branch={env:DIFF_BRANCH:origin/{env:GITHUB_BASE_REF:master}} {envtmpdir}/cobertura.xml

That does seem to work fine - however, due to #6076 (cc @mthuurne), it disables incremental mode (causing the runtime of mypy to go up from <1s to ~15s). Note that in my case I don't care about the XML report only containing changed files, because those are the only ones actually relevant for the annotation coverage diff - thus, I think it would be fine to enable the cache for this use-case.

I understand if this is a too specific case, though - I wonder if it'd make sense to have some "enforce annotations for any new code" functionality in mypy itself (perhaps via the incremental mode)?

The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Jun 24, 2020
Not done by default with "tox -e mypy" because it disables mypy's caching,
causing its runtime to go from <1s to ~15s:
python/mypy#9041

See #1456
@mthuurne
Copy link
Contributor

Disabling the cache entirely when generating reports, like #6076 does, is a rather blunt instrument. I don't know exactly why reports are incomplete when running in incremental mode, but ideally it would be possible to produce a correct coverage report in incremental mode, perhaps by storing more information in the cache.

An alternative would be to let mypy use cached data only for files that are not in the file set it is generating a report for. That way, you could generate a list of changed files and tell mypy to produce a coverage report for only those files.

I do think that mypy should always create a correct report: having an option to force incremental mode when that might lead to an incorrect report is unlikely to be a good long term solution.

@mthuurne
Copy link
Contributor

Actually, passing only the changed files to mypy on the command line may already improve performance. Not sure how much it would help, that depends on how many other modules are pulled in via imports. But it would be worth a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants