From e7a5a6c02794e59cceb56a3552af2179b553c156 Mon Sep 17 00:00:00 2001 From: Robin Whittleton Date: Thu, 6 Jun 2024 11:26:59 +0200 Subject: [PATCH 1/5] Bump pytest / pylint / mypy versions --- .github/workflows/se-test.yml | 2 +- README.md | 2 +- tests/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/se-test.yml b/.github/workflows/se-test.yml index 245228fa..9676eb98 100644 --- a/.github/workflows/se-test.yml +++ b/.github/workflows/se-test.yml @@ -19,7 +19,7 @@ jobs: - name: Install pipx packages run: | pipx install . - pipx inject standardebooks pylint==2.17.3 pytest==7.3.1 mypy==1.2.0 types-requests==2.28.11.17 types-setuptools==67.7.0.0 types-Pillow==10.2.0.20240331 + pipx inject standardebooks pytest==8.2.2 pylint==3.2.2 mypy==1.10.0 types-requests==2.32.0.20240602 types-setuptools==70.0.0.20240524 types-Pillow==10.2.0.20240520 - name: Check type annotations with mypy run: $PIPX_HOME/venvs/standardebooks/bin/mypy - name: Check code with pylint diff --git a/README.md b/README.md index eda354eb..474bd6e1 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ We export `COLUMNS` because `se lint` needs to know the width of the terminal so Before we can use `pylint` or `mypy` on the toolset source, we have to inject them (and additional typings) into the venv `pipx` created for the `standardebooks` package: ```shell -pipx inject standardebooks pylint==2.17.3 mypy==1.2.0 types-requests==2.28.11.17 types-setuptools==67.7.0.0 types-Pillow==10.2.0.20240331 +pipx inject standardebooks pylint==3.2.2 mypy==1.10.0 types-requests==2.32.0.20240602 types-setuptools==70.0.0.20240524 types-Pillow==10.2.0.20240520 ``` Then make sure to call the `pylint` and `mypy` binaries that `pipx` installed in the `standardebooks` venv, *not* any other globally-installed binaries: diff --git a/tests/README.md b/tests/README.md index a285d914..6d1496e5 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,7 +3,7 @@ Similar to `pylint`, the `pytest` command can be injected into the venv `pipx` created for the `standardebooks` package: ```shell -pipx inject standardebooks pytest==7.3.1 +pipx inject standardebooks pytest==8.2.2 ``` The tests are executed by calling `pytest` from the top level of your tools repo: From 858a25abfa04ea992ac770bc14d0b03a3b9ba273 Mon Sep 17 00:00:00 2001 From: Robin Whittleton Date: Thu, 6 Jun 2024 12:22:20 +0200 Subject: [PATCH 2/5] Get pylint passing at 100% - a couple of branch removals - a couple of potentially unintialised variables --- se/commands/interactive_replace.py | 3 +-- se/commands/word_count.py | 4 +++- se/se_epub_lint.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/se/commands/interactive_replace.py b/se/commands/interactive_replace.py index eaf113f0..f54039aa 100644 --- a/se/commands/interactive_replace.py +++ b/se/commands/interactive_replace.py @@ -37,8 +37,7 @@ def _get_text_dimensions(text: str) -> Tuple[int, int]: else: line_length = line_length + 1 - if line_length > text_width: - text_width = line_length + text_width = max(text_width, line_length) return (text_height + 1, text_width + 1) diff --git a/se/commands/word_count.py b/se/commands/word_count.py index 78dd6335..233c92b9 100644 --- a/se/commands/word_count.py +++ b/se/commands/word_count.py @@ -75,6 +75,8 @@ def word_count(plain_output: bool) -> int: se.print_error(f"Couldn’t open file: [path][link=file://{filename}]{filename}[/][/].", plain_output=plain_output) return se.InvalidInputException.code + category = "" + if args.categorize: category = "se:short-story" if NOVELLA_MIN_WORD_COUNT <= total_word_count < NOVEL_MIN_WORD_COUNT: @@ -82,6 +84,6 @@ def word_count(plain_output: bool) -> int: elif total_word_count >= NOVEL_MIN_WORD_COUNT: category = "se:novel" - print(f"{total_word_count}\t{category if args.categorize else ''}") + print(f"{total_word_count}\t{category}") return 0 diff --git a/se/se_epub_lint.py b/se/se_epub_lint.py index 0ecdc42f..53738a6f 100644 --- a/se/se_epub_lint.py +++ b/se/se_epub_lint.py @@ -510,8 +510,7 @@ def __init__(self, code: str, text: str, message_type=se.MESSAGE_TYPE_WARNING, f for submessage in submessages: # Try to flatten leading indentation for indent in regex.findall(r"^\t+(?=<)", submessage, flags=regex.MULTILINE): - if len(indent) < smallest_indent: - smallest_indent = len(indent) + smallest_indent = min(smallest_indent, len(indent)) if smallest_indent == 1000: smallest_indent = 0 @@ -1505,6 +1504,7 @@ def _lint_special_file_checks(self, filename: Path, dom: se.easy_xml.EasyXmlTree for node in dom.xpath("/html/body/nav[contains(@epub:type, 'loi')]//li//a"): figure_ref = node.get_attr("href").split("#")[1] chapter_ref = regex.findall(r"(.*?)#.*", node.get_attr("href"))[0] + figure_img_alt = "" figcaption_text = "" loi_text = node.inner_text() file_dom = self.get_dom(self.content_path / "text" / chapter_ref) From 0d372b2c76107a8b3e177829c40e24588ab411b4 Mon Sep 17 00:00:00 2001 From: Robin Whittleton Date: Thu, 6 Jun 2024 17:47:55 +0200 Subject: [PATCH 3/5] Remove bare-except and no-member from lint exceptions Neither of them affect the output any more. --- pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylintrc b/pylintrc index 5c07342d..6270aea0 100644 --- a/pylintrc +++ b/pylintrc @@ -6,7 +6,7 @@ ignore=vendor extension-pkg-whitelist=lxml,math,unicodedata [MESSAGES CONTROL] -disable=line-too-long,too-many-nested-blocks,too-many-branches,too-many-statements,too-many-boolean-expressions,too-many-lines,too-many-locals,broad-except,bare-except,too-few-public-methods,too-many-arguments,too-many-instance-attributes,too-many-public-methods,duplicate-code,no-member +disable=line-too-long,too-many-nested-blocks,too-many-branches,too-many-statements,too-many-boolean-expressions,too-many-lines,too-many-locals,broad-except,too-few-public-methods,too-many-arguments,too-many-instance-attributes,too-many-public-methods,duplicate-code [FORMAT] indent-string=\t From 451c1ddf6cc353901f6de9c978a23ddeabf60c5f Mon Sep 17 00:00:00 2001 From: Robin Whittleton Date: Fri, 7 Jun 2024 18:07:01 +0200 Subject: [PATCH 4/5] Update mypy typing checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re already exempting the from arg-type so let’s just add var-annotated and revisit another time. --- se/se_epub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/se/se_epub.py b/se/se_epub.py index 6e95bab3..06857dce 100644 --- a/se/se_epub.py +++ b/se/se_epub.py @@ -1328,7 +1328,7 @@ def _check_endnotes(self) -> list: anchor = href[hash_position:] references.append(anchor) # keep these for later reverse check # Now try to find anchor in endnotes - matches = list(filter(lambda x, old=anchor: x.anchor == old, self.endnotes)) # type: ignore [arg-type] + matches = list(filter(lambda x, old=anchor: x.anchor == old, self.endnotes)) # type: ignore [arg-type, var-annotated] if not matches: missing.append(anchor) if len(matches) > 1: @@ -1521,7 +1521,7 @@ def __process_noteref_link(self, change_list, current_note_number, file_name, li link.lxml_element.text = str(current_note_number) needs_rewrite = True # Now try to find this in endnotes - matches = list(filter(lambda x, old=old_anchor: x.anchor == old, self.endnotes)) # type: ignore [arg-type] + matches = list(filter(lambda x, old=old_anchor: x.anchor == old, self.endnotes)) # type: ignore [arg-type, var-annotated] if not matches: raise se.InvalidInputException(f"Couldn’t find endnote with anchor [attr]{old_anchor}[/].") if len(matches) > 1: From 79351d8e376cc815ff0adbc8b42e8e27d6263644 Mon Sep 17 00:00:00 2001 From: Robin Whittleton Date: Fri, 7 Jun 2024 18:18:56 +0200 Subject: [PATCH 5/5] Remove pylint deprecated-code warnings These can be fixed in a separate chunk of work to remove importlib_resources. --- pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylintrc b/pylintrc index 6270aea0..769c3557 100644 --- a/pylintrc +++ b/pylintrc @@ -6,7 +6,7 @@ ignore=vendor extension-pkg-whitelist=lxml,math,unicodedata [MESSAGES CONTROL] -disable=line-too-long,too-many-nested-blocks,too-many-branches,too-many-statements,too-many-boolean-expressions,too-many-lines,too-many-locals,broad-except,too-few-public-methods,too-many-arguments,too-many-instance-attributes,too-many-public-methods,duplicate-code +disable=line-too-long,too-many-nested-blocks,too-many-branches,too-many-statements,too-many-boolean-expressions,too-many-lines,too-many-locals,broad-except,too-few-public-methods,too-many-arguments,too-many-instance-attributes,too-many-public-methods,duplicate-code,deprecated-method [FORMAT] indent-string=\t