Skip to content

Commit ca7c3bd

Browse files
authored
chore(http): improvements on the streamlit app (#295)
* feat: replace TUI by a Streamlit http server * feat(http): include the download page * chore(http): improvements on the streamlit app * chore: improve testing
1 parent db96a5a commit ca7c3bd

24 files changed

Lines changed: 1111 additions & 175 deletions

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
uses: docker/build-push-action@v6
7878
with:
7979
context: .
80-
file: ./docker/Dockerfile
80+
file: ./Dockerfile
8181
push: true
8282
tags: |
8383
alertadengue/pysus:latest

poetry.lock

Lines changed: 28 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pysus/api/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@
55
"""
66

77
from .client import PySUS as PySUSClient # noqa
8+
from .errors import ( # noqa
9+
AuthenticationError,
10+
CatalogError,
11+
ConnectionError,
12+
ConversionError,
13+
DownloadError,
14+
FormatError,
15+
ParseError,
16+
PySUSError,
17+
ValidationError,
18+
)

pysus/api/client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from .dadosgov import DadosGovClient
2424
from .ducklake.client import DuckLake
25+
from .errors import ConnectionError, DownloadError, FormatError, ValidationError
2526
from .extensions import Parquet
2627
from .ftp import FTPClient
2728
from .models import BaseLocalFile, BaseRemoteFile
@@ -115,11 +116,14 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
115116
await self._dadosgov.close()
116117
self.engine.dispose()
117118

118-
async def get_ducklake(self) -> DuckLake:
119+
async def get_ducklake(
120+
self,
121+
callback: Callable[[int, int], None] | None = None,
122+
) -> DuckLake:
119123
"""Return the DuckLake client, initializing it lazily if needed."""
120124
if self._ducklake is None:
121125
self._ducklake = DuckLake()
122-
await self._ducklake.connect()
126+
await self._ducklake.connect(callback=callback)
123127
return self._ducklake
124128

125129
async def get_dadosgov(self, access_token: str | None) -> DadosGovClient:
@@ -292,7 +296,7 @@ async def download(
292296
elif client_name == "dadosgov":
293297
client = await self.get_dadosgov(token)
294298
else:
295-
raise ValueError(
299+
raise ValidationError(
296300
f"No download logic for client: {client_name}",
297301
)
298302

@@ -326,7 +330,7 @@ async def download(
326330
DownloadStatus.FAILED,
327331
)
328332
local_path.unlink(missing_ok=True)
329-
raise RuntimeError(
333+
raise DownloadError(
330334
f"Unexpected error downloading {file.basename}: {e}",
331335
) from e
332336

@@ -405,7 +409,7 @@ async def download_to_parquet(
405409

406410
return parquet_file
407411

408-
raise NotImplementedError(
412+
raise FormatError(
409413
f"{local_file} can't be converted to Parquet",
410414
)
411415

@@ -564,7 +568,7 @@ def read_parquet(
564568
from pysus.api.utils import is_geocode_column
565569

566570
if not paths:
567-
raise ValueError("No paths provided")
571+
raise ValidationError("No paths provided")
568572

569573
def get_columns(path: Path) -> set[tuple[str, str]]:
570574
"""Return the schema of a Parquet file as (name, type) pairs."""
@@ -583,7 +587,7 @@ def get_columns(path: Path) -> set[tuple[str, str]]:
583587
if mode == "strict":
584588
for i, schema in enumerate(schemas):
585589
if schema != schemas[0]:
586-
raise ValueError(
590+
raise ValidationError(
587591
f"Schema mismatch: file {i} has columns "
588592
f"{[c[0] for c in schema]}, "
589593
f"expected {[c[0] for c in schemas[0]]}"

pysus/api/dadosgov/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import httpx
1111
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PrivateAttr
1212
from pysus import __version__
13+
from pysus.api.errors import AuthenticationError, ConnectionError
1314
from pysus.api.models import BaseRemoteClient, BaseRemoteFile
1415
from pysus.api.types import DADOSGOV
1516

@@ -131,7 +132,7 @@ async def connect(self, token: str | None = None) -> None:
131132
_token = token or self._token
132133

133134
if not _token:
134-
raise ValueError(
135+
raise AuthenticationError(
135136
"A token is required to connect to DadosGov. "
136137
"Pass it to connect(token=...) or login(token=...)."
137138
)

0 commit comments

Comments
 (0)