question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

darglint performance on Google style docstrings may be too slow to be a pre-commit hook

See original GitHub issue

darglint’s performance on Google-style docstrings is pretty slow on my machine^1. 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

"""bar.py"""
def foo():
    """Summary

    Args:
        file (Any):
            A path to a Jupyter Notebook file.
        theme (str): The theme to use for syntax highlighting. May
            be ``'ansi_light'``, ``'ansi_dark'``, or any
            `Pygments theme`_. By default ``'ansi_dark'``.
        plain (bool): Only show plain style. No decorations such as
            boxes or execution counts. If set to pydata`None`
            will autodetect. By default pydata`None`.
        unicode (Optional[bool]): Whether to use unicode characters
            to render the notebook. If set to pydata`None` will
            autodetect. By default pydata`None`.
        hide_output (bool): Do not render the notebook outputs. By
            default pydata`False`.
        nerd_font (bool): Use nerd fonts when appropriate. By
            default pydata`False`.
        files (bool): Create files when needed to render HTML
            content. By default pydata`True`.
        negative_space (bool): Whether render character images in
            negative space. By default pydata`True`.
        hyperlinks (bool): Whether to use hyperlinks. If
            pydata`False` will explicitly print out path. If set
            to pydata`None` will autodetect. By default
            pydata`None`.
        hide_hyperlink_hints (bool): Hide text hints of when content
            is clickable. By default pydata`False`.
        images (Optional[str]): Whether to render images. If set to
            pydata`None` will autodetect. By default
            pydata`None`.
    """
    ...
% 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

  1. Switch the docstring styles to Sphinx Style
  2. Remove darglint as a pre-commit hook (but keep it as a CI linting session)
  3. Remove darglint as a default linter from the project

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
cjolowiczcommented, Feb 11, 2022

Yes, it seems this option was added for precisely our use case: https://github.com/terrencepreilly/darglint/pull/176

So I guess we could do the following:

  1. Exclude darglint from the flake8 hook using --darglint-ignore-regex (your code above)
  2. Add a dedicated darglint hook that runs only in the manual stage.
  3. Change the Nox session so the manual stage is included when CI is present in the environment.
0reactions
paw-lucommented, Feb 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance issues in google and numpy style parsers #186
darglint performance on Google style docstrings may be too slow to be a pre-commit hook cjolowicz/cookiecutter-hypermodern-python#1137.
Read more >
Darglint: A Python Documentation Linter Which Checks - Morioh
Darglint. A functional docstring linter which checks whether a docstring's description matches the actual function/method implementation.
Read more >
Analysing slowness pre-commit setup - Medium
The solution comes by understanding that we can focus our checks in the changes introduced on the commit maintaining the overall styles one ......
Read more >
pre-commit-hooks - Git at Google
Check for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT. check-docstring-first. Checks for a common...
Read more >
Document `darglint`'s performance issues #2287 - Issuehunt
Turned out that I usually set it to sphinx style which is why I've never ... On my machine with the affected file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found