Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add customizable progressbar and release #637

Merged
merged 3 commits into from
Oct 14, 2024
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ To keep the bioimageio.spec Python package version in sync with the (model) desc

### bioimageio.spec Python package

#### bioimageio.spec 0.5.3.3 (not yet released)
#### bioimageio.spec 0.5.3.3

* expose `progressbar` to customize display of download progress
* expose `get_resource_package_content`
* prefer `rdf.yaml` over `bioimageio.yaml` (name `bioimageio.yaml` file `rdf.yaml` file when packaging, look for `rdf.yaml` first, etc.)
* enforce: (generic 0.3/model 0.5 spec) documentation source file encoding has to be UTF-8.
* bugfix: allow optional pre- and postprocessing to be missing in an RDF (before it required an empty dict).
Expand Down
2 changes: 1 addition & 1 deletion bioimageio/spec/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.5.3.2"
"version": "0.5.3.3"
}
1 change: 1 addition & 0 deletions bioimageio/spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from ._io import load_model_description as load_model_description
from ._io import save_bioimageio_yaml_only as save_bioimageio_yaml_only
from ._package import get_resource_package_content as get_resource_package_content
from ._package import save_bioimageio_package as save_bioimageio_package
from ._package import (
save_bioimageio_package_as_folder as save_bioimageio_package_as_folder,
Expand Down
25 changes: 21 additions & 4 deletions bioimageio/spec/_internal/io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

# pyright: reportUnnecessaryTypeIgnoreComment=warning

import hashlib
import sys
import warnings
Expand All @@ -20,6 +19,7 @@
Iterable,
List,
Optional,
Protocol,
Sequence,
Tuple,
Type,
Expand Down Expand Up @@ -560,9 +560,21 @@ def _get_unique_file_name(url: Union[HttpUrl, pydantic.HttpUrl]):
return unique_name


class Progressbar(Protocol):
count: int
total: int

def update(self, i: int): ...

def reset(self): ...

def close(self): ...


def download(
source: Union[PermissiveFileSource, FileDescr],
/,
progressbar: Union[Progressbar, bool, None] = None,
**kwargs: Unpack[HashKwargs],
) -> DownloadedFile:
"""download `source` URL (or pass local file path)"""
Expand All @@ -584,15 +596,20 @@ def download(

if settings.CI:
headers = {"User-Agent": "ci"}
progressbar = False
if progressbar is None:
progressbar = False
else:
headers = {}
progressbar = True
if progressbar is None:
progressbar = True

if settings.user_agent is not None:
headers["User-Agent"] = settings.user_agent

downloader = pooch.HTTPDownloader(headers=headers, progressbar=progressbar)
downloader = pooch.HTTPDownloader(
headers=headers,
progressbar=progressbar, # pyright: ignore[reportArgumentType]
)
fname = _get_unique_file_name(strict_source)
_ls: Any = pooch.retrieve(
url=str(strict_source),
Expand Down
Loading