From db352ed72ae4473a805d485692df58ec4511a673 Mon Sep 17 00:00:00 2001 From: PhilipMay Date: Mon, 5 Jul 2021 15:46:51 +0200 Subject: [PATCH] Add style-doc checks (Makefile & Action) #8 --- .github/workflows/static_checks.yml | 3 +++ Makefile | 2 ++ style_doc/style_doc.py | 10 +++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index b98187b..b57edca 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -35,3 +35,6 @@ jobs: - name: Check with mdformat run: mdformat --check *.md + + - name: Check with style-doc + run: style-doc --max_len 119 --check_only --py_only ${{ env.src }} diff --git a/Makefile b/Makefile index 366bd8c..23e9ab7 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,14 @@ src := style_doc setup.py # format the code format: + style-doc --max_len 119 --py_only $(src) black $(src) isort $(src) mdformat *.md # check the code check: + style-doc --max_len 119 --check_only --py_only $(src) black $(src) --check --diff flake8 $(src) isort $(src) --check --diff diff --git a/style_doc/style_doc.py b/style_doc/style_doc.py index 4a06b69..1811fcd 100644 --- a/style_doc/style_doc.py +++ b/style_doc/style_doc.py @@ -27,7 +27,7 @@ # Special blocks where the inside should be formatted. TEXTUAL_BLOCKS = ["note", "warning"] # List of acceptable characters for titles and sections underline. -TITLE_SPECIAL_CHARS = """= - ` : ' " ~ ^ _ * + # < >""".split(" ") +TITLE_SPECIAL_CHARS = ["=", "-", "`", ":", "'", '"', "~", "^", "_", "*", "+", "#", "<", ">"] # Special words for docstrings (s? means the s is optional) DOC_SPECIAL_WORD = [ "Args?", @@ -492,12 +492,16 @@ def style_file_docstrings(code_file, max_len=119, check_only=False): """Style all docstrings in `code_file` to `max_len`.""" with open(code_file, "r", encoding="utf-8", newline="\n") as f: code = f.read() - splits = code.split('"""') + # fmt: off + splits = code.split("\"\"\"") + # fmt: on splits = [ (s if i % 2 == 0 or _re_doc_ignore.search(splits[i - 1]) is not None else style_docstring(s, max_len=max_len)) for i, s in enumerate(splits) ] - clean_code = '"""'.join(splits) + # fmt: off + clean_code = "\"\"\"".join(splits) + # fmt: on diff = clean_code != code if not check_only and diff: