Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 92
Refactor writer and add reader#14
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bf57c103dcb28acfaebfec6961c82adc5dadfd5ae3aecc4999ede2f8d9abb6732dd6baeef0c812ddd104dfce99c83c4d4369632f926ece9dd4ae8602f894bc1e4bb58524a24b9168f3fc560ab11780a3546a61983e8ea405e49ec7a7f2bf496b4cb8fa4adb88771ea1647f225447037d1eed062adbf5334cf93ce5886c44ace5cde9906b434edff54d749ba140278e20c571173856b53b629cfe435ad125385be34f8592a55614eb2e8c647File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Check Build | ||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| jobs: | ||
| package: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Set up Python 3.10 | ||
| uses: actions/setup-python@v2 | ||
| with: | ||
| python-version: "3.10" | ||
| - name: Install build dependencies | ||
| run: python -m pip install --upgrade pip wheel twine build | ||
| - name: Build package | ||
| run: python -m build | ||
| - name: Check package | ||
| run: twine check --strict dist/*.whl |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,3 +22,6 @@ __pycache__/ | ||
| # IDEs | ||
| /.idea/ | ||
| .vscode | ||
| # data | ||
| spatialdata-sandbox | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from abc import ABC, ABCMeta | ||
| from enum import Enum, EnumMeta | ||
| from functools import wraps | ||
| from typing import Any, Callable, Dict, Tuple, Type | ||
| class PrettyEnum(Enum): | ||
| """Enum with a pretty :meth:`__str__` and :meth:`__repr__`.""" | ||
| @property | ||
| def v(self) -> Any: | ||
| """Alias for :attr`value`.""" | ||
| return self.value | ||
| def __repr__(self) -> str: | ||
| return f"{self.value!r}" | ||
| def __str__(self) -> str: | ||
| return f"{self.value!s}" | ||
| def _pretty_raise_enum(cls: Type["ErrorFormatterABC"], func: Callable[..., Any]) -> Callable[..., Any]: | ||
| @wraps(func) | ||
| def wrapper(*args: Any, **kwargs: Any) -> "ErrorFormatterABC": | ||
| try: | ||
| return func(*args, **kwargs) # type: ignore[no-any-return] | ||
| except ValueError as e: | ||
| _cls, value, *_ = args | ||
| e.args = (cls._format(value),) | ||
| raise e | ||
| if not issubclass(cls, ErrorFormatterABC): | ||
| raise TypeError(f"Class `{cls}` must be subtype of `ErrorFormatterABC`.") | ||
| elif not len(cls.__members__): # type: ignore[attr-defined] | ||
| # empty enum, for class hierarchy | ||
| return func | ||
| return wrapper | ||
| class ABCEnumMeta(EnumMeta, ABCMeta): | ||
| def __call__(cls, *args: Any, **kwargs: Any) -> Any: | ||
| if getattr(cls, "__error_format__", None) is None: | ||
| raise TypeError(f"Can't instantiate class `{cls.__name__}` " f"without `__error_format__` class attribute.") | ||
| return super().__call__(*args, **kwargs) | ||
| def __new__(cls, clsname: str, superclasses: Tuple[type], attributedict: Dict[str, Any]) -> "ABCEnumMeta": | ||
| res = super().__new__(cls, clsname, superclasses, attributedict) # type: ignore[arg-type] | ||
| res.__new__ = _pretty_raise_enum(res, res.__new__) # type: ignore[assignment,arg-type] | ||
| return res | ||
| class ErrorFormatterABC(ABC): | ||
| """Mixin class that formats invalid value when constructing an enum.""" | ||
| __error_format__ = "Invalid option `{0}` for `{1}`. Valid options are: `{2}`." | ||
| @classmethod | ||
| def _format(cls, value: Enum) -> str: | ||
| return cls.__error_format__.format( | ||
| value, cls.__name__, [m.value for m in cls.__members__.values()] # type: ignore[attr-defined] | ||
| ) | ||
| # TODO: simplify this class | ||
| # https://github.com/napari/napari/blob/9ea0159ad2b690556fe56ce480886d8f0b79ffae/napari/layers/labels/_labels_constants.py#L9-L38 | ||
| # https://github.com/napari/napari/blob/9ea0159ad2b690556fe56ce480886d8f0b79ffae/napari/utils/misc.py#L300-L319 | ||
| class ModeEnum(str, ErrorFormatterABC, PrettyEnum, metaclass=ABCEnumMeta): | ||
giovp marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """Enum which prints available values when invalid value has been passed.""" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| from .spatialdata import SpatialData | ||
| __all__ = ["SpatialData"] | ||
| from spatialdata._core.spatialdata import SpatialData |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.