diff --git a/pyproject.toml b/pyproject.toml index 4261b6c3a..97dd6c2c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -185,31 +185,32 @@ line-ending = "lf" [tool.ruff.lint] # https://docs.astral.sh/ruff/rules/ extend-select = [ - "B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b - "COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com - "DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz - "DJ", # https://docs.astral.sh/ruff/rules/#flake8-django-dj - "EXE", # https://docs.astral.sh/ruff/rules/#flake8-executable-exe - "FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt - "FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly - "G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g - "I", # https://docs.astral.sh/ruff/rules/#isort-i - "ICN", # https://docs.astral.sh/ruff/rules/#flake8-import-conventions-icn - "INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp - "ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc - "PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie - "PLC", # https://docs.astral.sh/ruff/rules/#pylint-pl - "PLE", # https://docs.astral.sh/ruff/rules/#pylint-pl - "PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth - "Q", # https://docs.astral.sh/ruff/rules/#flake8-quotes-q - "RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse - "RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf - "SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim - "T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20 - "TC", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc - "TID", # https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid - "UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up - "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w + "B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com + "DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz + "PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf + "DJ", # https://docs.astral.sh/ruff/rules/#flake8-django-dj + "EXE", # https://docs.astral.sh/ruff/rules/#flake8-executable-exe + "FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt + "FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly + "G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g + "I", # https://docs.astral.sh/ruff/rules/#isort-i + "ICN", # https://docs.astral.sh/ruff/rules/#flake8-import-conventions-icn + "INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp + "ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc + "PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie + "PLC", # https://docs.astral.sh/ruff/rules/#pylint-pl + "PLE", # https://docs.astral.sh/ruff/rules/#pylint-pl + "PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth + "Q", # https://docs.astral.sh/ruff/rules/#flake8-quotes-q + "RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse + "RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf + "SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim + "T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20 + "TC", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc + "TID", # https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid + "UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up + "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w ] ignore = [ "DJ001", diff --git a/src/documents/management/commands/document_retagger.py b/src/documents/management/commands/document_retagger.py index fc2e52e86..2e8b45d61 100644 --- a/src/documents/management/commands/document_retagger.py +++ b/src/documents/management/commands/document_retagger.py @@ -133,11 +133,14 @@ def _build_suggestion_table( else: doc_cell = Text(f"{doc} [{doc.pk}]") - tag_parts: list[str] = [] - for tag in sorted(suggestion.tags_to_add, key=lambda t: t.name): - tag_parts.append(f"[green]+{tag.name}[/green]") - for tag in sorted(suggestion.tags_to_remove, key=lambda t: t.name): - tag_parts.append(f"[red]-{tag.name}[/red]") + tag_parts: list[str] = [ + f"[green]+{tag.name}[/green]" + for tag in sorted(suggestion.tags_to_add, key=lambda t: t.name) + ] + tag_parts.extend( + f"[red]-{tag.name}[/red]" + for tag in sorted(suggestion.tags_to_remove, key=lambda t: t.name) + ) tag_cell = Text.from_markup(", ".join(tag_parts)) if tag_parts else Text("-") table.add_row( diff --git a/src/documents/tests/management/test_management_base_cmd.py b/src/documents/tests/management/test_management_base_cmd.py index 572bcd52d..ea42f11f5 100644 --- a/src/documents/tests/management/test_management_base_cmd.py +++ b/src/documents/tests/management/test_management_base_cmd.py @@ -29,9 +29,7 @@ class SimpleCommand(PaperlessCommand): def handle(self, *args, **options): items = list(range(5)) - results = [] - for item in self.track(items, description="Processing..."): - results.append(item * 2) + results = [item * 2 for item in self.track(items, description="Processing...")] self.stdout.write(f"Results: {results}") @@ -57,13 +55,13 @@ class MultiprocessCommand(PaperlessCommand): def handle(self, *args, **options): items = list(range(5)) - results = [] - for result in self.process_parallel( - _double_value, - items, - description="Processing...", - ): - results.append(result) + results = list( + self.process_parallel( + _double_value, + items, + description="Processing...", + ), + ) successes = sum(1 for r in results if r.success) self.stdout.write(f"Successes: {successes}") diff --git a/src/documents/views.py b/src/documents/views.py index 24c5a1041..ca99da685 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1799,28 +1799,28 @@ class DocumentViewSet( ] # custom fields - for entry in LogEntry.objects.get_for_objects( - doc.custom_fields.all(), - ).select_related("actor"): - entries.append( - { - "id": entry.id, - "timestamp": entry.timestamp, - "action": entry.get_action_display(), - "changes": { - "custom_fields": { - "type": "custom_field", - "field": str(entry.object_repr).split(":")[0].strip(), - "value": str(entry.object_repr).split(":")[1].strip(), - }, + entries.extend( + { + "id": entry.id, + "timestamp": entry.timestamp, + "action": entry.get_action_display(), + "changes": { + "custom_fields": { + "type": "custom_field", + "field": str(entry.object_repr).split(":")[0].strip(), + "value": str(entry.object_repr).split(":")[1].strip(), }, - "actor": ( - {"id": entry.actor.id, "username": entry.actor.username} - if entry.actor - else None - ), }, - ) + "actor": ( + {"id": entry.actor.id, "username": entry.actor.username} + if entry.actor + else None + ), + } + for entry in LogEntry.objects.get_for_objects( + doc.custom_fields.all(), + ).select_related("actor") + ) return Response(sorted(entries, key=lambda x: x["timestamp"], reverse=True)) diff --git a/src/paperless/checks.py b/src/paperless/checks.py index 6cc646f6b..876f52e15 100644 --- a/src/paperless/checks.py +++ b/src/paperless/checks.py @@ -84,10 +84,11 @@ def binaries_check(app_configs: Any, **kwargs: Any) -> list[Error]: binaries = (settings.CONVERT_BINARY, "tesseract", "gs") - check_messages = [] - for binary in binaries: - if shutil.which(binary) is None: - check_messages.append(Warning(error.format(binary), hint)) + check_messages = [ + Warning(error.format(binary), hint) + for binary in binaries + if shutil.which(binary) is None + ] return check_messages @@ -383,14 +384,14 @@ def check_default_language_available(app_configs: Any, **kwargs: Any) -> list[Er specified_langs = [x.strip() for x in settings.OCR_LANGUAGE.split("+")] - for lang in specified_langs: - if lang not in installed_langs: - errs.append( - Error( - f"The selected ocr language {lang} is " - f"not installed. Paperless cannot OCR your documents " - f"without it. Please fix PAPERLESS_OCR_LANGUAGE.", - ), - ) + errs.extend( + Error( + f"The selected ocr language {lang} is " + f"not installed. Paperless cannot OCR your documents " + f"without it. Please fix PAPERLESS_OCR_LANGUAGE.", + ) + for lang in specified_langs + if lang not in installed_langs + ) return errs diff --git a/src/paperless/parsers/mail.py b/src/paperless/parsers/mail.py index 8188b7933..556b6eddf 100644 --- a/src/paperless/parsers/mail.py +++ b/src/paperless/parsers/mail.py @@ -649,11 +649,10 @@ class MailDocumentParser: if data["bcc"]: data["bcc_label"] = "BCC" - att = [] - for a in mail.attachments: - att.append( - f"{a.filename} ({naturalsize(a.size, binary=True, format='%.2f')})", - ) + att = [ + f"{a.filename} ({naturalsize(a.size, binary=True, format='%.2f')})" + for a in mail.attachments + ] data["attachments"] = clean_html(", ".join(att)) if data["attachments"]: data["attachments_label"] = "Attachments" diff --git a/src/paperless_ai/embedding.py b/src/paperless_ai/embedding.py index 2695e9fb3..722a886e5 100644 --- a/src/paperless_ai/embedding.py +++ b/src/paperless_ai/embedding.py @@ -152,8 +152,10 @@ def build_llm_index_text(doc: Document) -> str: f"Notes: {','.join([str(c.note) for c in Note.objects.filter(document=doc)])}", ] - for instance in doc.custom_fields.all(): - lines.append(f"Custom Field - {instance.field.name}: {instance}") + lines.extend( + f"Custom Field - {instance.field.name}: {instance}" + for instance in doc.custom_fields.all() + ) lines.append("\nContent:\n") lines.append(doc.content or "")