From 8682b2e259256b93ee7288ff13c2569275006bba Mon Sep 17 00:00:00 2001 From: James Stout Date: Mon, 11 Nov 2024 15:27:27 -0800 Subject: [PATCH] Added more Ruff checks. --- gaze_ocr_talon.py | 19 ++++++++++--------- pyproject.toml | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 pyproject.toml diff --git a/gaze_ocr_talon.py b/gaze_ocr_talon.py index a2e355e..7d11641 100644 --- a/gaze_ocr_talon.py +++ b/gaze_ocr_talon.py @@ -1,9 +1,10 @@ import glob import logging import sys +from collections.abc import Iterable, Sequence from math import floor from pathlib import Path -from typing import Dict, Iterable, Literal, Optional, Sequence +from typing import Literal, Optional import numpy as np from talon import Context, Module, actions, app, cron, fs, screen, settings @@ -146,7 +147,7 @@ def add_homophones( - homophones: Dict[str, Sequence[str]], to_add: Iterable[Iterable[str]] + homophones: dict[str, Sequence[str]], to_add: Iterable[Iterable[str]] ): for words in to_add: merged_words = set(words) @@ -394,7 +395,7 @@ def move_cursor_to_word_generator(text: TimestampedText): ) if not result: actions.user.show_ocr_overlay_for_query("text", f"{text.text}") - raise RuntimeError('Unable to find: "{}"'.format(text)) + raise RuntimeError(f'Unable to find: "{text}"') def move_text_cursor_to_word_generator( @@ -412,7 +413,7 @@ def move_text_cursor_to_word_generator( ) if not result: actions.user.show_ocr_overlay_for_query("text", f"{text.text}") - raise RuntimeError('Unable to find: "{}"'.format(text)) + raise RuntimeError(f'Unable to find: "{text}"') def move_text_cursor_to_longest_prefix_generator( @@ -431,7 +432,7 @@ def move_text_cursor_to_longest_prefix_generator( ) if not locations: actions.user.show_ocr_overlay_for_query("text", f"{text.text}") - raise RuntimeError('Unable to find: "{}"'.format(text)) + raise RuntimeError(f'Unable to find: "{text}"') return prefix_length @@ -451,7 +452,7 @@ def move_text_cursor_to_longest_suffix_generator( ) if not locations: actions.user.show_ocr_overlay_for_query("text", f"{text.text}") - raise RuntimeError('Unable to find: "{}"'.format(text)) + raise RuntimeError(f'Unable to find: "{text}"') return prefix_length @@ -464,7 +465,7 @@ def move_text_cursor_to_difference(text: TimestampedText): ) if not result: actions.user.show_ocr_overlay_for_query("text", f"{text.text}") - raise RuntimeError('Unable to find: "{}"'.format(text)) + raise RuntimeError(f'Unable to find: "{text}"') return result @@ -493,7 +494,7 @@ def select_text_generator( actions.user.show_ocr_overlay_for_query( "text", f"{start.text}...{end.text if end else None}" ) - raise RuntimeError('Unable to select "{}" to "{}"'.format(start, end)) + raise RuntimeError(f'Unable to select "{start}" to "{end}"') def select_matching_text_generator(text: TimestampedText): @@ -506,7 +507,7 @@ def select_matching_text_generator(text: TimestampedText): ) if not result: actions.user.show_ocr_overlay_for_query("text", f"{text.text}") - raise RuntimeError('Unable to find: "{}"'.format(text)) + raise RuntimeError(f'Unable to find: "{text}"') def perform_ocr_action_generator( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e29189c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,27 @@ +[project] +name = "talon-gaze-ocr" +version = "0.1.0" +description = "Talon scripts to enable advanced cursor control using eye tracking and text recognition (OCR)." +readme = "README.md" +requires-python = ">=3.11" +dependencies = [] + +[tool.ruff.lint] +select = [ + # pycodestyle + "E", + # Pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # flake8-simplify + "SIM", + # isort + "I", +] +ignore = ["E501", "SIM105", "SIM116", "UP007"] + +[tool.pyright] +reportSelfClsParameterName = false