Skip to content
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

Update mypy / pylint / pytest and make everything work on latest Pythons #704

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/se-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,deprecated-method

[FORMAT]
indent-string=\t
Expand Down
3 changes: 1 addition & 2 deletions se/commands/interactive_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion se/commands/word_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ 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:
category = "se:novella"
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
4 changes: 2 additions & 2 deletions se/se_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading