diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad82c7a..3c05d4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 588f841..bee7eff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/pyproject.toml b/pyproject.toml index ff435c1..73b59e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/requirements-ci.txt b/requirements-ci.txt new file mode 100644 index 0000000..14a296b --- /dev/null +++ b/requirements-ci.txt @@ -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). diff --git a/src/formbridge/__init__.py b/src/formbridge/__init__.py index d127046..088e276 100644 --- a/src/formbridge/__init__.py +++ b/src/formbridge/__init__.py @@ -4,4 +4,4 @@ nothing and loads no GUI toolkit. """ -__version__ = "0.1.1" +__version__ = "0.1.2" diff --git a/src/formbridge/strategies/preview_formatting.py b/src/formbridge/strategies/preview_formatting.py index 0df6e69..07da0f4 100644 --- a/src/formbridge/strategies/preview_formatting.py +++ b/src/formbridge/strategies/preview_formatting.py @@ -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, ) @@ -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. diff --git a/tests/test_preview_formatter_registry.py b/tests/test_preview_formatter_registry.py index 66f0afe..132c663 100644 --- a/tests/test_preview_formatter_registry.py +++ b/tests/test_preview_formatter_registry.py @@ -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"