generated from john/python-template
style: apply ruff formatting sweep
Co-authored-by: Copilot App <[email protected]>
This commit is contained in:
co-authored by
Copilot App
parent
4aaa9bd581
commit
2a56365847
@@ -207,7 +207,7 @@ LOGGING_CONFIG: dict[str, Any] = {
|
||||
"maxBytes": 10 * 1024 * 1024,
|
||||
"backupCount": 5,
|
||||
"encoding": "utf-8",
|
||||
}
|
||||
},
|
||||
},
|
||||
"root": {
|
||||
"level": "INFO",
|
||||
|
||||
@@ -93,11 +93,15 @@ def export_bundle(*, source_db_url: str, source_upload_dir: Path, bundle_dir: Pa
|
||||
if legacy_column not in export_columns:
|
||||
export_columns.append(legacy_column)
|
||||
if table_name == "person" and "portrait_path" in source_table.columns:
|
||||
legacy_portrait_rows = connection.execute(
|
||||
select(source_table.c["id"], source_table.c["portrait_path"]).where(
|
||||
source_table.c["portrait_path"].is_not(None)
|
||||
legacy_portrait_rows = (
|
||||
connection.execute(
|
||||
select(source_table.c["id"], source_table.c["portrait_path"]).where(
|
||||
source_table.c["portrait_path"].is_not(None)
|
||||
)
|
||||
)
|
||||
).mappings().all()
|
||||
.mappings()
|
||||
.all()
|
||||
)
|
||||
rows = connection.execute(select(*(source_table.c[name] for name in export_columns))).mappings().all()
|
||||
payload["tables"][table_name] = [
|
||||
_serialize_row(row, table_name=table_name, source_upload_dir=source_upload_dir) for row in rows
|
||||
@@ -344,15 +348,9 @@ def _prepare_photo_payload_and_uploads( # noqa: PLR0915
|
||||
photo_rows[:] = retained_rows
|
||||
|
||||
existing_homepage_rows = [row for row in photo_rows if row.get("person_id") is None]
|
||||
existing_person_ids = {
|
||||
str(row["person_id"])
|
||||
for row in photo_rows
|
||||
if row.get("person_id") is not None
|
||||
}
|
||||
existing_person_ids = {str(row["person_id"]) for row in photo_rows if row.get("person_id") is not None}
|
||||
existing_primary_person_ids = {
|
||||
str(row["person_id"])
|
||||
for row in photo_rows
|
||||
if row.get("person_id") is not None and bool(row.get("is_primary"))
|
||||
str(row["person_id"]) for row in photo_rows if row.get("person_id") is not None and bool(row.get("is_primary"))
|
||||
}
|
||||
has_homepage_primary = any(bool(row.get("is_primary")) for row in existing_homepage_rows)
|
||||
|
||||
|
||||
@@ -435,9 +435,7 @@ class Source(SQLModel, table=True):
|
||||
"""
|
||||
job_sources = _loaded_attribute(self, "job_sources") or ()
|
||||
dated = [
|
||||
(job, job_source)
|
||||
for job_source in job_sources
|
||||
if (job := _loaded_attribute(job_source, "job")) is not None
|
||||
(job, job_source) for job_source in job_sources if (job := _loaded_attribute(job_source, "job")) is not None
|
||||
]
|
||||
if dated:
|
||||
return max(dated, key=lambda pair: pair[0].date_created)[1]
|
||||
|
||||
@@ -50,8 +50,7 @@ def initialize_database_runtime(*, settings: Settings | None = None) -> Database
|
||||
runtime_url = runtime.engine.url.render_as_string(hide_password=False)
|
||||
if runtime_url != database_url:
|
||||
raise RuntimeError(
|
||||
"Database runtime is already initialized for a different database: "
|
||||
f"{runtime_url!r} != {database_url!r}"
|
||||
f"Database runtime is already initialized for a different database: {runtime_url!r} != {database_url!r}"
|
||||
)
|
||||
return runtime
|
||||
|
||||
|
||||
@@ -582,8 +582,7 @@ class DocumentService(ServiceBase):
|
||||
)
|
||||
|
||||
existing_tags = (
|
||||
(await _session.exec(select(Tag).where(col(Tag.normalized_label).in_(label_keys))))
|
||||
.all()
|
||||
(await _session.exec(select(Tag).where(col(Tag.normalized_label).in_(label_keys)))).all()
|
||||
if label_keys
|
||||
else []
|
||||
)
|
||||
@@ -598,9 +597,7 @@ class DocumentService(ServiceBase):
|
||||
tags_by_key[key] = tag
|
||||
selected_tag_ids.add(tag.id)
|
||||
|
||||
links = (
|
||||
await _session.exec(select(DocumentTag).where(DocumentTag.document_id == document_id))
|
||||
).all()
|
||||
links = (await _session.exec(select(DocumentTag).where(DocumentTag.document_id == document_id))).all()
|
||||
existing_ids = {link.tag_id for link in links}
|
||||
|
||||
for link in links:
|
||||
|
||||
@@ -278,9 +278,7 @@ class JobService(ServiceBase):
|
||||
)
|
||||
attempt_count = (
|
||||
await _session.exec(
|
||||
select(func.count())
|
||||
.select_from(ExecutionAttempt)
|
||||
.where(ExecutionAttempt.job_id == job_id)
|
||||
select(func.count()).select_from(ExecutionAttempt).where(ExecutionAttempt.job_id == job_id)
|
||||
)
|
||||
).one()
|
||||
if attempt_count:
|
||||
@@ -320,11 +318,7 @@ class JobService(ServiceBase):
|
||||
)
|
||||
|
||||
attempts = list(
|
||||
(
|
||||
await session.exec(
|
||||
select(ExecutionAttempt).where(ExecutionAttempt.job_id == job_id)
|
||||
)
|
||||
).all()
|
||||
(await session.exec(select(ExecutionAttempt).where(ExecutionAttempt.job_id == job_id))).all()
|
||||
)
|
||||
for attempt in attempts:
|
||||
await session.delete(attempt)
|
||||
|
||||
@@ -67,9 +67,13 @@ async def persist_named_media(
|
||||
) -> Path:
|
||||
"""Resolve a target directory/name and persist media bytes safely."""
|
||||
target_dir = root if namespace is None else root / Path(namespace)
|
||||
stored_name = Path(filename).name if preserve_original_name else build_stored_filename(
|
||||
filename=filename,
|
||||
filename_stem=filename_stem,
|
||||
stored_name = (
|
||||
Path(filename).name
|
||||
if preserve_original_name
|
||||
else build_stored_filename(
|
||||
filename=filename,
|
||||
filename_stem=filename_stem,
|
||||
)
|
||||
)
|
||||
return await write_media_bytes(
|
||||
target_dir=target_dir,
|
||||
|
||||
@@ -277,8 +277,7 @@ class PeopleService(ServiceBase):
|
||||
)
|
||||
|
||||
existing_tags = (
|
||||
(await _session.exec(select(Tag).where(col(Tag.normalized_label).in_(label_keys))))
|
||||
.all()
|
||||
(await _session.exec(select(Tag).where(col(Tag.normalized_label).in_(label_keys)))).all()
|
||||
if label_keys
|
||||
else []
|
||||
)
|
||||
|
||||
@@ -65,9 +65,7 @@ def analyze_transcription_quality(text: str) -> tuple[QualityWarning, ...]:
|
||||
warnings.append(
|
||||
QualityWarning(
|
||||
code=QualityWarningCode.REDUNDANT_HANDWRITING_WRAPPERS,
|
||||
detail=(
|
||||
"A wholly handwritten document also uses repeated whole-line handwriting wrappers."
|
||||
),
|
||||
detail=("A wholly handwritten document also uses repeated whole-line handwriting wrappers."),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -249,8 +249,7 @@ class RegistryService[ModelT: RegistryEntry](ServiceBase):
|
||||
f"Built-in {self.noun} {entry.label!r} cannot be deleted",
|
||||
category=ErrorCategory.CONFLICT,
|
||||
suggestion=(
|
||||
f"Deactivate the {self.short_noun} instead; "
|
||||
"its built-in meaning must remain available."
|
||||
f"Deactivate the {self.short_noun} instead; its built-in meaning must remain available."
|
||||
),
|
||||
)
|
||||
if await self._is_referenced(session=_session, entry=entry):
|
||||
@@ -258,8 +257,7 @@ class RegistryService[ModelT: RegistryEntry](ServiceBase):
|
||||
f"{self.noun} {entry.label!r} is referenced and cannot be deleted",
|
||||
category=ErrorCategory.CONFLICT,
|
||||
suggestion=(
|
||||
f"Deactivate the {self.short_noun} instead; "
|
||||
f"{self.referenced_retainer} will retain it."
|
||||
f"Deactivate the {self.short_noun} instead; {self.referenced_retainer} will retain it."
|
||||
),
|
||||
)
|
||||
await _session.delete(entry)
|
||||
|
||||
@@ -351,9 +351,7 @@ class SourceService(ServiceBase):
|
||||
async with self._session_scope(session) as _session:
|
||||
job_source = (
|
||||
await _session.exec(
|
||||
select(JobSource)
|
||||
.where(JobSource.job_id == job_id)
|
||||
.where(JobSource.source_id == source_id)
|
||||
select(JobSource).where(JobSource.job_id == job_id).where(JobSource.source_id == source_id)
|
||||
)
|
||||
).first()
|
||||
if job_source is None:
|
||||
@@ -400,9 +398,7 @@ class SourceService(ServiceBase):
|
||||
linked_job_sources = list(source.job_sources)
|
||||
attempt_count = (
|
||||
await _session.exec(
|
||||
select(func.count())
|
||||
.select_from(ExecutionAttempt)
|
||||
.where(ExecutionAttempt.source_id == source_id)
|
||||
select(func.count()).select_from(ExecutionAttempt).where(ExecutionAttempt.source_id == source_id)
|
||||
)
|
||||
).one()
|
||||
if attempt_count:
|
||||
@@ -586,11 +582,7 @@ class SourceService(ServiceBase):
|
||||
_session.add(attempt)
|
||||
await _session.flush()
|
||||
|
||||
if (
|
||||
text is not None
|
||||
and source.raw_transcription is None
|
||||
and source.preferred_execution_attempt_id is None
|
||||
):
|
||||
if text is not None and source.raw_transcription is None and source.preferred_execution_attempt_id is None:
|
||||
source.raw_transcription = text
|
||||
source.preferred_execution_attempt_id = attempt.id
|
||||
|
||||
|
||||
@@ -43,8 +43,4 @@ def render_upload_picker(
|
||||
props.append("webkitdirectory directory")
|
||||
if multiple:
|
||||
props.append("multiple")
|
||||
return (
|
||||
ui.upload(on_upload=on_upload, auto_upload=True, label=label)
|
||||
.props(" ".join(props))
|
||||
.classes("w-full")
|
||||
)
|
||||
return ui.upload(on_upload=on_upload, auto_upload=True, label=label).props(" ".join(props)).classes("w-full")
|
||||
|
||||
@@ -377,9 +377,7 @@ def register_page() -> None: # noqa: PLR0915
|
||||
if document.sources or document.jobs:
|
||||
render_delete_blocked_notice(
|
||||
reason="Delete is blocked because related records exist.",
|
||||
detail=dependency_summary(
|
||||
[("Sources", bool(document.sources)), ("Jobs", bool(document.jobs))]
|
||||
),
|
||||
detail=dependency_summary([("Sources", bool(document.sources)), ("Jobs", bool(document.jobs))]),
|
||||
guidance="Remove related records first, then retry deletion.",
|
||||
back_label="Back to Document",
|
||||
back_target=f"/documents/{document.id}",
|
||||
@@ -497,14 +495,18 @@ def _render_document_form_fields(
|
||||
if document is not None
|
||||
else []
|
||||
)
|
||||
tags_input = ui.select(
|
||||
sorted(tag_options, key=str.casefold),
|
||||
label="Tags",
|
||||
value=selected_tags,
|
||||
multiple=True,
|
||||
with_input=True,
|
||||
new_value_mode="add-unique",
|
||||
).props("outlined use-chips").classes("w-full ui-form-surface")
|
||||
tags_input = (
|
||||
ui.select(
|
||||
sorted(tag_options, key=str.casefold),
|
||||
label="Tags",
|
||||
value=selected_tags,
|
||||
multiple=True,
|
||||
with_input=True,
|
||||
new_value_mode="add-unique",
|
||||
)
|
||||
.props("outlined use-chips")
|
||||
.classes("w-full ui-form-surface")
|
||||
)
|
||||
|
||||
linked_people.render()
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ def _render_homepage_gallery(
|
||||
ui.label(f"{active_index[0] + 1} of {len(photos)}").classes("text-xs ui-text-muted")
|
||||
|
||||
if enable_rotation and rotate_enabled is not None:
|
||||
|
||||
def set_rotation(enabled: bool) -> None:
|
||||
rotate_enabled[0] = enabled
|
||||
if on_change is not None:
|
||||
@@ -128,10 +129,14 @@ def _render_homepage_editor(*, render_image_panel, markdown_input, on_upload) ->
|
||||
render_image_panel()
|
||||
|
||||
with ui.column().classes("col-span-12 lg:col-span-5 gap-4"), archival_card(title="Home Text"):
|
||||
markdown_input[0] = ui.textarea(
|
||||
label="Homepage markdown",
|
||||
value=read_homepage_markdown(),
|
||||
).props("outlined autogrow").classes("w-full")
|
||||
markdown_input[0] = (
|
||||
ui.textarea(
|
||||
label="Homepage markdown",
|
||||
value=read_homepage_markdown(),
|
||||
)
|
||||
.props("outlined autogrow")
|
||||
.classes("w-full")
|
||||
)
|
||||
|
||||
with ui.column().classes("col-span-12 lg:col-span-3"):
|
||||
ui.element("div")
|
||||
@@ -198,10 +203,14 @@ def register_page() -> None: # noqa: PLR0915
|
||||
|
||||
if photos:
|
||||
current_photo = photos[active_index[0]]
|
||||
description_input = ui.input(
|
||||
label="Image description",
|
||||
value=current_photo.description or "",
|
||||
).props("outlined dense").classes("w-full")
|
||||
description_input = (
|
||||
ui.input(
|
||||
label="Image description",
|
||||
value=current_photo.description or "",
|
||||
)
|
||||
.props("outlined dense")
|
||||
.classes("w-full")
|
||||
)
|
||||
|
||||
async def save_description() -> None:
|
||||
try:
|
||||
|
||||
@@ -361,9 +361,7 @@ def register_page() -> None: # noqa: PLR0915
|
||||
return
|
||||
|
||||
resubmittable_count = sum(
|
||||
1
|
||||
for js in job.job_sources
|
||||
if js.status in {JobSourceStatus.FAILED, JobSourceStatus.CANCELLED}
|
||||
1 for js in job.job_sources if js.status in {JobSourceStatus.FAILED, JobSourceStatus.CANCELLED}
|
||||
)
|
||||
|
||||
with ui.column().classes("w-full max-w-xl mx-auto p-4 gap-4"):
|
||||
@@ -374,8 +372,7 @@ def register_page() -> None: # noqa: PLR0915
|
||||
metadata_row("Current Status:", job.status.value.upper())
|
||||
metadata_row("Resubmittable Sources:", str(resubmittable_count))
|
||||
ui.label(
|
||||
"Resubmit queues failed and cancelled linked sources. "
|
||||
"Prior execution evidence remains preserved."
|
||||
"Resubmit queues failed and cancelled linked sources. Prior execution evidence remains preserved."
|
||||
).classes("text-xs ui-text-muted")
|
||||
|
||||
async def submit_resubmit() -> None:
|
||||
@@ -440,9 +437,7 @@ def register_page() -> None: # noqa: PLR0915
|
||||
ui.label(
|
||||
"Related JobSource links, execution attempts, transport responses, and attempt artifacts "
|
||||
"will be removed. Source records and files remain until deleted separately."
|
||||
).classes(
|
||||
"text-xs ui-text-muted"
|
||||
)
|
||||
).classes("text-xs ui-text-muted")
|
||||
|
||||
async def submit_delete() -> None:
|
||||
try:
|
||||
|
||||
@@ -368,9 +368,9 @@ def register_page() -> None: # noqa: PLR0915
|
||||
label="",
|
||||
on_upload=on_photo_selected,
|
||||
auto_upload=True,
|
||||
).props(
|
||||
f'multiple accept="{",".join(sorted(IMAGE_UPLOAD_EXTENSIONS))}"'
|
||||
).classes("hidden person-photo-upload")
|
||||
).props(f'multiple accept="{",".join(sorted(IMAGE_UPLOAD_EXTENSIONS))}"').classes(
|
||||
"hidden person-photo-upload"
|
||||
)
|
||||
ui.button(
|
||||
"Upload Photo(s)",
|
||||
on_click=lambda: ui.run_javascript(
|
||||
@@ -606,14 +606,18 @@ def _render_person_form_fields(
|
||||
if person is not None
|
||||
else []
|
||||
)
|
||||
tags_input = ui.select(
|
||||
sorted(tag_options, key=str.casefold),
|
||||
label="Tags",
|
||||
value=selected_tags,
|
||||
multiple=True,
|
||||
with_input=True,
|
||||
new_value_mode="add-unique",
|
||||
).props("outlined use-chips").classes("w-full ui-form-surface")
|
||||
tags_input = (
|
||||
ui.select(
|
||||
sorted(tag_options, key=str.casefold),
|
||||
label="Tags",
|
||||
value=selected_tags,
|
||||
multiple=True,
|
||||
with_input=True,
|
||||
new_value_mode="add-unique",
|
||||
)
|
||||
.props("outlined use-chips")
|
||||
.classes("w-full ui-form-surface")
|
||||
)
|
||||
|
||||
return PersonFormFields(
|
||||
last_name=last_name_input,
|
||||
|
||||
@@ -651,19 +651,11 @@ def _render_machine_candidates(
|
||||
evidence_service: EvidenceService,
|
||||
) -> None:
|
||||
successful = [
|
||||
attempt
|
||||
for attempt in attempts
|
||||
if attempt.status == JobSourceStatus.TRANSCRIBED and attempt.raw_transcription
|
||||
]
|
||||
candidates = [
|
||||
attempt for attempt in successful if attempt.id != source.preferred_execution_attempt_id
|
||||
attempt for attempt in attempts if attempt.status == JobSourceStatus.TRANSCRIBED and attempt.raw_transcription
|
||||
]
|
||||
candidates = [attempt for attempt in successful if attempt.id != source.preferred_execution_attempt_id]
|
||||
preferred_attempt = next(
|
||||
(
|
||||
attempt
|
||||
for attempt in successful
|
||||
if attempt.id == source.preferred_execution_attempt_id
|
||||
),
|
||||
(attempt for attempt in successful if attempt.id == source.preferred_execution_attempt_id),
|
||||
None,
|
||||
)
|
||||
|
||||
@@ -697,9 +689,7 @@ def _render_machine_candidates(
|
||||
with ui.grid().classes("w-full grid-cols-1 md:grid-cols-2 gap-3"):
|
||||
with ui.column().classes("gap-1"):
|
||||
ui.label("Preferred machine transcription").classes("text-xs font-semibold")
|
||||
ui.label(source.raw_transcription).classes(
|
||||
"p-2 ui-note-box text-xs whitespace-pre-wrap"
|
||||
)
|
||||
ui.label(source.raw_transcription).classes("p-2 ui-note-box text-xs whitespace-pre-wrap")
|
||||
with ui.column().classes("gap-1"):
|
||||
ui.label("Candidate transcription").classes("text-xs font-semibold")
|
||||
ui.label(attempt.raw_transcription or "").classes(
|
||||
|
||||
Reference in New Issue
Block a user