-
Notifications
You must be signed in to change notification settings - Fork 237
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
darglint performance on Google style docstrings may be too slow to be a pre-commit hook #1137
darglint performance on Google style docstrings may be too slow to be a pre-commit hook #1137
Comments
Thanks! Ideally we'd get this fixed upstream (my first guess would be catastrophic regex backtracking). As a temporary workaround, option 2 could be done by marking the hook manual. As a sidenote: The MyST project is working on their own Markdown docstring support. But that may take a while, and whatever syntax they end up with may still be susceptible to this problem. |
Yeah, I like this approach the most. But the trouble I'm having with it is that even when So it seems that as long as darlint and flake8 are installed in the same environment (the nox pre-commit env) flake8's performance will be impacted. Maybe darlint can have its own nox session (like we do with mypy, typeguard, xdoctest)? What this approach does not solve is that the editor's linting process will still be impacted by the performance—since darglint will be in the general dev environment anyways. Footnotes |
So I guess we'd have to run darglint as a stand-alone pre-commit hook, separate from flake8 and outside of the Nox and Poetry environments, i.e. as a regular (non-system) hook managed by pre-commit. |
The thing about having a separate Nox session is that we'd also get an additional CI job then. And it would be surprising to have it in Nox but not Poetry. TBH I don't like any of the workarounds much... |
Yeah I'm 100% with you here. Still trying to think of an elegant solution. The best I can think of is what you already mentioned—a stand-alone hook. repos:
- repo: https://github.com/terrencepreilly/darglint
rev: master
hooks:
- id: darglint
stages: [manual] |
Maybe the best option (aside from fixing the performance issue upstream) is actually to step back and open a PR that makes darglint's flake8 integration off by default. |
Notes for myself on how to do this. |
Though unfortunatley this would now require projects to explictitly enable the integration by default, and would quietly disable darglint on current linting workflows. So I completely understand if the maintainer would not want to adopt this. |
Could darglint to be changed to let users opt out off flake8 integration, rather than changing its default? |
Guessed wrong. snip... moved the rest of this comment here snip... All in all, not a trivial fix. |
Yeah maybe this is the least disruptive change. There's a good spot for this here. We could just add something like a |
Yet another work around option is that darlgint adds a So the pre-commit hook can have something like - id: flake8
name: flake8
entry: flake8
language: system
types: [python]
require_serial: true
args: [--darglint-ignore-regex, .*] |
Yes, it seems this option was added for precisely our use case: terrencepreilly/darglint#176 So I guess we could do the following:
|
Implimentation attempted in cjolowicz/cookiecutter-hypermodern-python-instance#822. |
darglint's performance on Google-style docstrings is pretty slow on my machine1. It gets even slower when you try to integrate rst into the docstring.2 Slow enough that in some cases it's too much friction as a pre-commit hook (at least on my machine). Posting this both to document my issue and to see if others have ran into this.
Example
% darglint bar.py
This example takes 52 seconds on my machine. The example from the issue takes 2:02.2 This can evolve into a bigger issue—as heavily docstringed commits were timing out on my machine when darglint was ran as a pre-commit hook.
Possible solutions
Footnotes
https://github.com/terrencepreilly/darglint/issues/186 ↩
https://github.com/terrencepreilly/darglint/issues/198 ↩ ↩2
The text was updated successfully, but these errors were encountered: