-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new config option for documenting star arguments (#206)
- Loading branch information
Showing
10 changed files
with
240 additions
and
16 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
75 changes: 75 additions & 0 deletions
75
.pre_commit_helper_scripts/check_full_diff_in_changelog.py
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,75 @@ | ||
import sys | ||
|
||
from markdown_it import MarkdownIt | ||
|
||
|
||
def parseChangelog(filePath: str) -> tuple[bool, list[str]]: | ||
""" | ||
Parses the changelog file and ensures each version section has "Full diff". | ||
Parameters | ||
---------- | ||
filePath : str | ||
Path to the CHANGELOG.md file. | ||
Returns | ||
------- | ||
bool | ||
True if all sections include a "Full diff", False otherwise. | ||
list[str] | ||
A list of version headers missing the "Full diff" section. | ||
""" | ||
with open(filePath, 'r', encoding='utf-8') as file: | ||
content = file.read() | ||
|
||
# Parse the Markdown content | ||
md = MarkdownIt() | ||
tokens = md.parse(content) | ||
|
||
versionHeaders = [] | ||
missingFullDiff = [] | ||
|
||
# Iterate through parsed tokens to find version sections | ||
for i, token in enumerate(tokens): | ||
if token.type == 'heading_open' and token.tag == 'h2': | ||
# Extract version header text | ||
header = tokens[i + 1].content | ||
if header.startswith('[') and ' - ' in header: | ||
versionHeaders.append((header, i)) | ||
|
||
# Check each version section for "Full diff" | ||
for idx, (header, startIdx) in enumerate(versionHeaders): | ||
if header.startswith('[0.0.1]'): | ||
# The initial version shouldn't have a "Full diff" section. | ||
continue | ||
|
||
endIdx = ( | ||
versionHeaders[idx + 1][1] | ||
if idx + 1 < len(versionHeaders) | ||
else len(tokens) | ||
) | ||
sectionTokens = tokens[startIdx:endIdx] | ||
|
||
# Check for "Full diff" in section content | ||
if not any( | ||
token.type == 'inline' and 'Full diff' in token.content | ||
for token in sectionTokens | ||
): | ||
missingFullDiff.append(header) | ||
|
||
return len(missingFullDiff) == 0, missingFullDiff | ||
|
||
|
||
if __name__ == '__main__': | ||
filePath = 'CHANGELOG.md' | ||
isValid, missingSections = parseChangelog(filePath) | ||
|
||
if isValid: | ||
print("All sections include a 'Full diff' section.") | ||
sys.exit(0) | ||
|
||
print("The following sections are missing a 'Full diff':") | ||
for section in missingSections: | ||
print(section) | ||
|
||
sys.exit(1) |
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
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
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
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,42 @@ | ||
# From: https://github.com/jsh9/pydoclint/issues/121 | ||
|
||
def function_1(arg1: int, *args: Any, **kwargs: Any) -> None: | ||
""" | ||
Do something | ||
Parameters | ||
---------- | ||
arg1 : int | ||
Arg 1 | ||
""" | ||
pass | ||
|
||
|
||
def function_2(arg1: int, *args: Any, **kwargs: Any) -> None: | ||
""" | ||
Do something | ||
Parameters | ||
---------- | ||
arg1 : int | ||
Arg 1 | ||
*args : Any | ||
Args | ||
**kwargs : Any | ||
Kwargs | ||
""" | ||
pass | ||
|
||
|
||
def function_3(arg1: int, *args: Any, **kwargs: Any) -> None: | ||
""" | ||
Do something | ||
Parameters | ||
---------- | ||
arg1 : int | ||
Arg 1 | ||
**kwargs : Any | ||
Kwargs | ||
""" | ||
pass |
Oops, something went wrong.