Skip to content

Commit db352ed

Browse files
committed
Add style-doc checks (Makefile & Action) #8
1 parent 37b946e commit db352ed

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.github/workflows/static_checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ jobs:
3535

3636
- name: Check with mdformat
3737
run: mdformat --check *.md
38+
39+
- name: Check with style-doc
40+
run: style-doc --max_len 119 --check_only --py_only ${{ env.src }}

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ src := style_doc setup.py
44

55
# format the code
66
format:
7+
style-doc --max_len 119 --py_only $(src)
78
black $(src)
89
isort $(src)
910
mdformat *.md
1011

1112
# check the code
1213
check:
14+
style-doc --max_len 119 --check_only --py_only $(src)
1315
black $(src) --check --diff
1416
flake8 $(src)
1517
isort $(src) --check --diff

style_doc/style_doc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Special blocks where the inside should be formatted.
2828
TEXTUAL_BLOCKS = ["note", "warning"]
2929
# List of acceptable characters for titles and sections underline.
30-
TITLE_SPECIAL_CHARS = """= - ` : ' " ~ ^ _ * + # < >""".split(" ")
30+
TITLE_SPECIAL_CHARS = ["=", "-", "`", ":", "'", '"', "~", "^", "_", "*", "+", "#", "<", ">"]
3131
# Special words for docstrings (s? means the s is optional)
3232
DOC_SPECIAL_WORD = [
3333
"Args?",
@@ -492,12 +492,16 @@ def style_file_docstrings(code_file, max_len=119, check_only=False):
492492
"""Style all docstrings in `code_file` to `max_len`."""
493493
with open(code_file, "r", encoding="utf-8", newline="\n") as f:
494494
code = f.read()
495-
splits = code.split('"""')
495+
# fmt: off
496+
splits = code.split("\"\"\"")
497+
# fmt: on
496498
splits = [
497499
(s if i % 2 == 0 or _re_doc_ignore.search(splits[i - 1]) is not None else style_docstring(s, max_len=max_len))
498500
for i, s in enumerate(splits)
499501
]
500-
clean_code = '"""'.join(splits)
502+
# fmt: off
503+
clean_code = "\"\"\"".join(splits)
504+
# fmt: on
501505

502506
diff = clean_code != code
503507
if not check_only and diff:

0 commit comments

Comments
 (0)