Skip to content
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
40 changes: 40 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
## Changes in version 0.5.0 (in development)

### Enhancements

- The **Cuiman** client's opener API has been revised. (#243)
The changes are

- `Client` and `AsyncClient` now use `read_job_result()`.
Their `open_job_result()` methods remain temporarily as deprecated helpers
that forward calls and emit `DeprecationWarning`.

- Breaking API changes: imports move from
`cuiman.api.opener` to `cuiman.api.reader`, with reader class and error
names. Configuration uses `extra_job_result_readers`,
`register_job_result_reader()`, and `get_job_result_reader_registry()`.
`JobOptions.opener_options` becomes `reader_options`.
No other compatibility aliases are provided.
See the [reader guide](docs/cuiman/guides/readers.md).

- Custom readers implement `accept_job_result()` and `read_job_result()`;
path readers implement `read_path_like()`. Each concrete
reader, including subclasses, must declare a unique `reader_id`. Callers
can select a reader with `reader_id`; inherited `option_policy` continues
to govern backend options independently of reader identity.

- `Client` and `AsyncClient` accept already retrieved `JobResults`,
selecting an output without polling, process lookup, refetching the result
document, or modifying the supplied results. Reusing the original result
object preserves available URL context for relative STAC links, including
across clients. A sole output is selected automatically; multiple outputs
require `output_name`.

- When `read_job_result()` is called with a `data_type` it either returns a
compatible value or raises `JobResultReadError`.
Unsupported representation conversions, such as a Zarr dataset result to
`data_type=pandas.DataFrame`, will raise.

- `read_job_result()` uses media types ahead of filename suffixes when
choosing readers. Explicit `engine` options override inferred defaults;
unsupported overrides raise. Zarr dataset reads infer the xarray `"zarr"`
engine and preserve lazy loading.

### Fixes

- **Cuiman** allows its app to connect when a service's landing page returns
Expand Down
2 changes: 1 addition & 1 deletion appligator/tests/airflow/test_gen_workflow_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from typing import Annotated
from unittest.mock import patch

import pytest
import pyruff
import pytest
from pydantic import Field

from appligator.airflow.gen_workflow_dag import (
Expand Down
16 changes: 8 additions & 8 deletions appligator/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_pvc_mount_appears_in_generated_dag(self):
content,
)
self.assertIn(
"k8s.V1VolumeMount(name=\"my-vol\", mount_path=\"/mnt/data\")", content
'k8s.V1VolumeMount(name="my-vol", mount_path="/mnt/data")', content
)

def test_config_map_mount_appears_in_generated_dag(self):
Expand All @@ -92,10 +92,10 @@ def test_config_map_mount_appears_in_generated_dag(self):
dag_files = list(Path(tmpdir).glob("*.py"))
content = dag_files[0].read_text(encoding="utf-8")
self.assertIn(
"config_map=k8s.V1ConfigMapVolumeSource(name=\"app-config\")", content
'config_map=k8s.V1ConfigMapVolumeSource(name="app-config")', content
)
self.assertIn(
"k8s.V1VolumeMount(name=\"my-cm\", mount_path=\"/etc/config\")", content
'k8s.V1VolumeMount(name="my-cm", mount_path="/etc/config")', content
)
self.assertNotIn("sub_path", content)

Expand All @@ -114,7 +114,7 @@ def test_config_map_mount_with_sub_path_appears_in_generated_dag(self):
self.assertEqual(0, result.exit_code, msg=result.output)
dag_files = list(Path(tmpdir).glob("*.py"))
content = dag_files[0].read_text(encoding="utf-8")
self.assertIn("sub_path=\"settings.yaml\"", content)
self.assertIn('sub_path="settings.yaml"', content)

def test_invalid_pvc_mount_format_exits_with_error(self):
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_config_file_values_used(self):
dag_files = list(Path(tmpdir).glob("*.py"))
content = dag_files[0].read_text(encoding="utf-8")
self.assertIn("from-file-secret", content)
self.assertIn("claim_name=\"file-pvc\"", content)
self.assertIn('claim_name="file-pvc"', content)

def test_config_map_mount_from_config_file(self):
"""Exercises the cfg.config_map_mounts fallback in effective_config_map_mounts."""
Expand All @@ -237,7 +237,7 @@ def test_config_map_mount_from_config_file(self):
self.assertEqual(0, result.exit_code, msg=result.output)
content = list(Path(tmpdir).glob("*.py"))[0].read_text(encoding="utf-8")
self.assertIn(
"config_map=k8s.V1ConfigMapVolumeSource(name=\"file-config\")", content
'config_map=k8s.V1ConfigMapVolumeSource(name="file-config")', content
)

def test_cli_flag_overrides_config_file(self):
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_node_selector_appears_in_generated_dag(self):
)
self.assertEqual(0, result.exit_code, msg=result.output)
content = list(Path(tmpdir).glob("*.py"))[0].read_text(encoding="utf-8")
self.assertIn("_node_selector = {\"pool\": \"airflow-workers-big\"}", content)
self.assertIn('_node_selector = {"pool": "airflow-workers-big"}', content)
self.assertIn("node_selector=_node_selector", content)

def test_invalid_node_selector_format_exits_with_error(self):
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_toleration_appears_in_generated_dag(self):
self.assertEqual(0, result.exit_code, msg=result.output)
content = list(Path(tmpdir).glob("*.py"))[0].read_text(encoding="utf-8")
self.assertIn("_tolerations = [", content)
self.assertIn("key=\"airflow/component\"", content)
self.assertIn('key="airflow/component"', content)
self.assertIn("tolerations=_tolerations", content)

def test_invalid_toleration_format_exits_with_error(self):
Expand Down
10 changes: 5 additions & 5 deletions cuiman/src/cuiman/api/assets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def display_assets(
*,
roles: str | Iterable[str] | None = None,
previews: bool = True,
open_asset: "Callable[[Asset], Any] | None" = None,
read_asset: "Callable[[Asset], Any] | None" = None,
) -> None:
"""Render job result tables or grouped STAC assets and optional previews.

Expand All @@ -36,7 +36,7 @@ async def display_assets(
Set to ``False`` to prevent asset preview reads. Geometry previews
remain enabled. Asset previews are independent of the table's
role filter; unreadable or unsupported previews are skipped.
open_asset: A synchronous or asynchronous asset opener. If omitted,
read_asset: A synchronous or asynchronous asset reader. If omitted,
asset previews are skipped; tables and geometry maps remain enabled.
Job result tables never open linked outputs.
"""
Expand All @@ -45,7 +45,7 @@ async def display_assets(
expression=_get_items_expression("display_assets"),
roles=roles,
previews=previews,
open_asset=open_asset,
read_asset=read_asset,
)


Expand All @@ -55,7 +55,7 @@ async def _display_assets(
expression: str | None,
roles: str | Iterable[str] | None = None,
previews: bool = True,
open_asset: "Callable[[Asset], Any] | None" = None,
read_asset: "Callable[[Asset], Any] | None" = None,
) -> None:
"""Dispatch notebook display without importing optional STAC dependencies."""
if isinstance(items, JobResults):
Expand All @@ -72,5 +72,5 @@ async def _display_assets(
expression=expression,
roles=roles,
previews=previews,
open_asset=open_asset,
read_asset=read_asset,
)
18 changes: 9 additions & 9 deletions cuiman/src/cuiman/api/assets/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def _display_stac_assets(
expression: str | None,
roles: str | Iterable[str] | None = None,
previews: bool = True,
open_asset: "Callable[[Asset], Any] | None" = None,
read_asset: "Callable[[Asset], Any] | None" = None,
) -> None:
"""Display items with the expression captured before entering client bridges."""

Expand Down Expand Up @@ -96,8 +96,8 @@ def expression_prefix_for(i):

for item_index, item in enumerate(item_list):
previews_html = (
await _load_previews(item, open_asset=open_asset)
if previews and open_asset is not None
await _load_previews(item, read_asset=read_asset)
if previews and read_asset is not None
else ""
)
display(
Expand Down Expand Up @@ -354,13 +354,13 @@ def mercator_y(latitude):
return max(0, min(16, floor(log2(scale))))


async def _load_previews(item: "Item", *, open_asset: "Callable[[Asset], Any]") -> str:
async def _load_previews(item: "Item", *, read_asset: "Callable[[Asset], Any]") -> str:
"""Load captioned previews for the item's viewable preview assets."""
previews = []
for key, asset in item.assets.items():
if not {"thumbnail", "overview", "visual"}.intersection(asset.roles or []):
continue
preview = await _load_preview(asset, open_asset=open_asset)
preview = await _load_preview(asset, read_asset=read_asset)
if preview is not None:
caption = escape(str(asset.title or key))
previews.append(
Expand All @@ -375,14 +375,14 @@ async def _load_previews(item: "Item", *, open_asset: "Callable[[Asset], Any]")


async def _load_preview(
asset: "Asset", *, open_asset: "Callable[[Asset], Any]"
asset: "Asset", *, read_asset: "Callable[[Asset], Any]"
) -> str | None:
"""Open, render, and close one preview using the supplied reader."""
try:
if iscoroutinefunction(open_asset):
value = await open_asset(asset)
if iscoroutinefunction(read_asset):
value = await read_asset(asset)
else:
value = await asyncio.to_thread(open_asset, asset)
value = await asyncio.to_thread(read_asset, asset)
try:
return _render_preview(value)
finally:
Expand Down
Loading
Loading