-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-commit hook for running numpydoc validation (#454)
* Add numpydoc.hooks directory. * Add numpydoc.hooks to packages. * Add tabulate dependency for use in validate hook. * Add option to pass a Validator class to validate() function. * Add AST-based validation logic to review files. * Add entry point for validation hook. * Add pre-commit hook configuration. * Add SS05 match pattern for allowed verbs; add some type annotations. * Add config option to override GL08 by name. * Add option specify a path to a config file. * Add information on the hook to the docs. * Grab arg name off ast arg nodes for *args/**kwargs; don't alter filepath. * Update spacing in example. * Reduce maxcolwidths in report of findings by hook. * Show file in a separate column of the findings; item is from module onward. * Update example in docs for new column. * Update example in docs for new column. * Switch to a stack for visiting. * Add line to file column; show module lineno as 1. * Expand user on config file path. * Use Path operations. * Add support for using inline comments to ignore specific checks. * Add support for comments at the end of a multiline declaration. * Add a note on inline option to docs. * Simplify check for the declaration start. * Add support for reading hook config from pyproject.toml * Add some initial tests for the validate hook. * Tweak docstring. * Add tests for hook using config files. * Add finding of project root. * Update link in docstring. * Tweak code blocks in docs. * Shorten table to avoid scroll in docs.
- Loading branch information
Showing
12 changed files
with
844 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- id: numpydoc-validation | ||
name: numpydoc-validation | ||
description: This hook validates that docstrings in committed files adhere to numpydoc standards. | ||
entry: validate-docstrings | ||
require_serial: true | ||
language: python | ||
types: [python] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Pre-commit hooks using numpydoc.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Utility functions for pre-commit hooks.""" | ||
|
||
import itertools | ||
import os | ||
from pathlib import Path | ||
from typing import Sequence | ||
|
||
|
||
def find_project_root(srcs: Sequence[str]): | ||
""" | ||
Return a directory containing .git, .hg, pyproject.toml, or setup.cfg. | ||
That directory can be one of the directories passed in ``srcs`` or their | ||
common parent. If no directory in the tree contains a marker that would | ||
specify it's the project root, the root of the file system is returned. | ||
Parameters | ||
---------- | ||
srcs : Sequence[str] | ||
The filepaths to run the hook on. | ||
Returns | ||
------- | ||
str | ||
The project root directory. | ||
See Also | ||
-------- | ||
black.find_project_root : | ||
This function was adapted from | ||
`Black <https://github.com/psf/black/blob/main/src/black/files.py>`_. | ||
""" | ||
if not srcs: | ||
return Path(".").resolve(), "current directory" | ||
|
||
common_path = Path( | ||
os.path.commonpath([Path(src).expanduser().resolve() for src in srcs]) | ||
) | ||
|
||
for dir in itertools.chain([common_path], common_path.parents): | ||
if (dir / "pyproject.toml").is_file(): | ||
return dir, "pyproject.toml" | ||
if (dir / "setup.cfg").is_file(): | ||
return dir, "setup.cfg" | ||
if (dir / ".git").exists() or (dir / ".hg").is_dir(): | ||
return dir, "version control" | ||
|
||
return dir, "file system root" |
Oops, something went wrong.