-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
STYLE, CI move validate_rst_title_capitalization check to pre-commit #39779
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
Merged
jreback
merged 1 commit into
pandas-dev:master
from
MarcoGorelli:validate-title-capitalization-pre-commit
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Validate that the titles in the rst files follow the proper capitalization convention. | ||
|
||
Print the titles that do not follow the convention. | ||
|
||
Usage:: | ||
./scripts/validate_rst_title_capitalization.py doc/source/development/contributing.rst | ||
./scripts/validate_rst_title_capitalization.py doc/source/ | ||
|
||
As pre-commit hook (recommended): | ||
pre-commit run title-capitalization --all-files | ||
|
||
From the command-line: | ||
python scripts/validate_rst_title_capitalization.py <rst file> | ||
""" | ||
import argparse | ||
import glob | ||
import os | ||
import re | ||
import sys | ||
from typing import Iterable, List, Tuple | ||
|
@@ -233,45 +233,14 @@ def find_titles(rst_file: str) -> Iterable[Tuple[str, int]]: | |
previous_line = line | ||
|
||
|
||
def find_rst_files(source_paths: List[str]) -> Iterable[str]: | ||
""" | ||
Given the command line arguments of directory paths, this method | ||
yields the strings of the .rst file directories that these paths contain. | ||
|
||
Parameters | ||
---------- | ||
source_paths : str | ||
List of directories to validate, provided through command line arguments. | ||
|
||
Yields | ||
------- | ||
str | ||
Directory address of a .rst files found in command line argument directories. | ||
""" | ||
|
||
for directory_address in source_paths: | ||
if not os.path.exists(directory_address): | ||
raise ValueError( | ||
"Please enter a valid path, pointing to a valid file/directory." | ||
) | ||
elif directory_address.endswith(".rst"): | ||
yield directory_address | ||
else: | ||
yield from glob.glob( | ||
pathname=f"{directory_address}/**/*.rst", recursive=True | ||
) | ||
|
||
|
||
def main(source_paths: List[str], output_format: str) -> int: | ||
def main(source_paths: List[str]) -> int: | ||
""" | ||
The main method to print all headings with incorrect capitalization. | ||
|
||
Parameters | ||
---------- | ||
source_paths : str | ||
List of directories to validate, provided through command line arguments. | ||
output_format : str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this was unused anyway |
||
Output format of the script. | ||
|
||
Returns | ||
------- | ||
|
@@ -281,7 +250,7 @@ def main(source_paths: List[str], output_format: str) -> int: | |
|
||
number_of_errors: int = 0 | ||
|
||
for filename in find_rst_files(source_paths): | ||
for filename in source_paths: | ||
for title, line_number in find_titles(filename): | ||
if title != correct_title_capitalization(title): | ||
print( | ||
|
@@ -297,16 +266,9 @@ def main(source_paths: List[str], output_format: str) -> int: | |
parser = argparse.ArgumentParser(description="Validate heading capitalization") | ||
|
||
parser.add_argument( | ||
"paths", nargs="+", default=".", help="Source paths of file/directory to check." | ||
) | ||
|
||
parser.add_argument( | ||
"--format", | ||
"-f", | ||
default="{source_path}:{line_number}:{msg}:{heading}:{correct_heading}", | ||
help="Output format of incorrectly capitalized titles", | ||
"paths", nargs="*", help="Source paths of file/directory to check." | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
sys.exit(main(args.paths, args.format)) | ||
sys.exit(main(args.paths)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why this was only run in two directories? I guess it could be expanded now