Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

The pre-commit hook fails silently when a pyproject.toml file exists and toml isn't installed #603

Open
vyasr opened this issue Aug 2, 2022 · 3 comments

Comments

@vyasr
Copy link

vyasr commented Aug 2, 2022

#534 enabled usage of pydocstyle with pyproject.toml for configuration. In that PR, it was discussed that toml shouldn't be a hard dependency for using pydocstyle (which I agree with), and that it should simply throw a warning if a pyproject.toml file is detected without the toml package present to read it. However, this is problematic when using pydocstyle as a pre-commit hook because pre-commit will silently consume stdout unless the hook returns a nonzero exit code.

I see a few potential solutions here, which I've placed in order of preference:

  1. Use the additional_dependencies feature of pre-commit to always require toml when installing the pydocstyle pre-commit hook. I see the argument for not wanting to error without toml in a general setting, but in the context of pre-commit where the dependencies can be tightly managed I think it's OK to have this dependency encoded.
  2. Change the warning to an error, but also add a grep (or equivalent) of a pyproject.toml file (if one exists) to see whether the string [tool.pydocstyle] is present in the file as a precondition of erroring. This is a bit more engineering effort, but if avoiding requiring toml is important enough even in a pre-commit hook then this would be a way to do a more cursory check of the file without parsing it.
  3. Set verbose: True in the pre-commit hook definition. This choice has the downside of always making pydocstyle noisier, but it at least ensures that the warning will be visible.
  4. The status quo. This solution puts the onus on the user to realize that pydocstyle fails silently in this case. I personally don't think this is a viable solution, but I listed it in case the project maintainers feel otherwise.

I am happy to make a PR if we could come to a consensus on the preferred solution.

@vyasr
Copy link
Author

vyasr commented Aug 2, 2022

For completeness, here's a MWE:

# pyproject.toml
[tool.pydocstyle]
select = D30
# .pre-commit-config.yaml
repos:
  - repo: https://github.com/PyCQA/pydocstyle
    rev: 6.1.1
    hooks:
      - id: pydocstyle
# test.py
"""Docstring."""                                                                
                                                                                
                                                                                
def myfunc():                                                                   
    """docstring."""                                                            
    pass   

And here's the output:

(main) vyasr-dt% pre-commit run --all-files
pydocstyle...............................................................Passed
(main) vyasr-dt% pre-commit run --all-files -v
pydocstyle...............................................................Passed
- hook id: pydocstyle
- duration: 0.05s

WARNING: The /home/vyasr/local/testing/pydocstyle_hook/pyproject.toml configuration file was ignored, because the `toml` package is not installed.

@choucavalier
Copy link

👍 Had the same issue, thanks for opening this issue because it helped!

ax3l added a commit to ax3l/lasy that referenced this issue Mar 31, 2023
Add [pydocstyle](https://github.com/PyCQA/pydocstyle) to
auto-format Function/Class docstrings according to numpy style.

Ref.:
- http://www.pydocstyle.org
- PyCQA/pydocstyle#603
ax3l added a commit to ax3l/lasy that referenced this issue Apr 17, 2023
Add [pydocstyle](https://github.com/PyCQA/pydocstyle) to
auto-format Function/Class docstrings according to numpy style.

Ref.:
- http://www.pydocstyle.org
- PyCQA/pydocstyle#603
ax3l added a commit to ax3l/lasy that referenced this issue Apr 17, 2023
Add [pydocstyle](https://github.com/PyCQA/pydocstyle) to
auto-format Function/Class docstrings according to numpy style.

Ref.:
- http://www.pydocstyle.org
- PyCQA/pydocstyle#603
ax3l added a commit to ax3l/lasy that referenced this issue Apr 17, 2023
Add [pydocstyle](https://github.com/PyCQA/pydocstyle) to
auto-format Function/Class docstrings according to numpy style.

Ref.:
- http://www.pydocstyle.org
- PyCQA/pydocstyle#603
ax3l added a commit to ax3l/lasy that referenced this issue Apr 17, 2023
Add [pydocstyle](https://github.com/PyCQA/pydocstyle) to
auto-format Function/Class docstrings according to numpy style.

Ref.:
- http://www.pydocstyle.org
- PyCQA/pydocstyle#603
ax3l added a commit to ax3l/lasy that referenced this issue Apr 27, 2023
Add [pydocstyle](https://github.com/PyCQA/pydocstyle) to
auto-format Function/Class docstrings according to numpy style.

Ref.:
- http://www.pydocstyle.org
- PyCQA/pydocstyle#603
@ivysochyn
Copy link

ivysochyn commented Aug 18, 2023

With pydocstyle 6.3.0 package tomli also required (version 6.2.0 works without adding this package as a hook dependency), otherwise pyproject.toml configuration will be ignored.

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

No branches or pull requests

3 participants