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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Install
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
python -m pip install --constraint requirements-ci.txt -e ".[dev]"

- name: Run tests
run: pytest --cov=formbridge --cov-report=term-missing -v
Expand All @@ -70,7 +70,7 @@ jobs:
- name: Install
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
python -m pip install --constraint requirements-ci.txt -e ".[dev]"

- name: Ruff
run: ruff check src tests --output-format=github
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.1.2

Requires ObjectState 3 (`objectstate>=3.0,<4`).

- `strategies.preview_formatting` reads a config group's abbreviation with
`objectstate.lazy_factory.get_group_abbreviation`, the one owner of that
lookup in ObjectState 3 (`GROUP_ABBREVIATIONS_REGISTRY` is removed there).
The module's own copy of the lookup is deleted; the name
`formbridge.strategies.preview_formatting.get_group_abbreviation` is now
ObjectState's function.

## 0.1.1

Added:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ keywords = ["forms", "reactive", "dataclass", "ui-bridge", "headless"]
dependencies = [
"docutils>=0.20",
"metaclass-registry>=0.1.5",
"objectstate>=2.0,<3",
"objectstate>=3.0,<4",
"psutil>=5.9",
"python-introspect>=0.2.7,<0.3",
"pyzmq>=22.0",
Expand Down
2 changes: 2 additions & 0 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Source candidates needed to validate this checkout before coordinated publication.
# Empty: every first-party dependency is released (objectstate 3.0.0).
2 changes: 1 addition & 1 deletion src/formbridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
nothing and loads no GUI toolkit.
"""

__version__ = "0.1.1"
__version__ = "0.1.2"
13 changes: 1 addition & 12 deletions src/formbridge/strategies/preview_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from typing import TYPE_CHECKING, TypeAlias

from objectstate import DottedFieldPath, ParameterOwner
from objectstate.lazy_factory import get_group_abbreviation

from formbridge.utils.preview_formatters import (
PreviewFieldFormatRequest,
PreviewValueDetail,
canonical_declaration_mro,
format_preview_value,
)

Expand All @@ -23,17 +23,6 @@
ItemValueFormatter: TypeAlias = Callable[[object], str | None]


def get_group_abbreviation(config_type: type) -> str:
"""Resolve a group abbreviation from the canonical declaration MRO."""
from objectstate.lazy_factory import GROUP_ABBREVIATIONS_REGISTRY

for declaration_type in canonical_declaration_mro(config_type):
abbreviation = GROUP_ABBREVIATIONS_REGISTRY.get(declaration_type)
if abbreviation is not None:
return abbreviation
return config_type.__name__.split("_", 1)[0]


@dataclass(frozen=True, slots=True)
class FormattingConfig:
"""List-preview presentation derived from declared fields and ObjectState.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_preview_formatter_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@ class BaseConfig:
)

assert PreviewFormatterRegistry.format_field(lazy_type(), "value") == "base"


def test_group_heading_default_reads_the_objectstate_declaration() -> None:
from objectstate.lazy_factory import abbreviation, get_group_abbreviation

from formbridge.strategies.preview_formatting import FormattingConfig

@abbreviation("cfg")
@dataclass
class HeadedConfig:
value: int = 0

class SpecializedHeadedConfig(HeadedConfig):
pass

lazy_type = LazyDataclassFactory.make_lazy_simple(HeadedConfig, "LazyHeadedConfig")
heading = FormattingConfig().container_abbr_func

assert heading is get_group_abbreviation
assert heading(HeadedConfig) == "cfg"
assert heading(SpecializedHeadedConfig) == "cfg"
assert heading(lazy_type) == "cfg"
Loading