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
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

All notable changes to this project will be documented in this file.

## 0.4.3

### Changed

- Added `__all__` to the `lionweb.language`, `lionweb.model`, `lionweb.model.impl`,
`lionweb.self`, `lionweb.presentation`, `lionweb.utils`, `lionweb.serialization`
and `lionweb.generation` packages to explicitly control their public API.
- Replaced generic `RuntimeError`/`ValueError` usages with more specific exception
types where it improves clarity and lets callers handle failures precisely:
- `lionweb.serialization.classifier_resolver.UnresolvedClassifierError` is now
raised by `ClassifierResolver` when a classifier, concept, or annotation
cannot be resolved from a `MetaPointer`.
- `lionweb.utils.language_validator.InvalidLanguageError` is now raised by
`LanguageValidator.ensure_is_valid` when a `Language` fails validation,
carrying the offending language and its `ValidationResult`.
- Rewrote the `isinstance`-chain in `LanguageValidator.check_ancestors_helper`
using `match`/`case` pattern matching for clarity.
- Added Google-style docstrings (with typed `Args`/`Returns`/`Raises` sections)
to `ClassifierResolver` and `LanguageValidator`.
- Tightened type hints (e.g. `Sequence[object]`, forward-referenced `Concept`/
`Annotation` dictionaries) in `ClassifierResolver` and `LanguageValidator`.

### Removed

- Removed `ROADMAP.md`; the items it tracked have been addressed.
11 changes: 0 additions & 11 deletions ROADMAP.md

This file was deleted.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ dev = [
"diff-cover",
"testcontainers>=4.0",
"types-requests",
"types-protobuf",
"types-click",
]

[tool.ruff]
Expand Down
107 changes: 9 additions & 98 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,99 +1,10 @@
annotated-types==0.7.0
anyio==4.9.0
astor==0.8.1
asttokens==3.0.0
backports.tarfile==1.2.0
black==25.1.0
build==1.2.2.post1
bump2version==1.0.1
certifi==2025.1.31
cfgv==3.4.0
charset-normalizer==3.4.1
click==8.1.8
coverage==7.10.6
decorator==5.2.1
distlib==0.3.9
distro==1.9.0
docker==7.1.0
docutils==0.21.2
exceptiongroup==1.2.2
executing==2.2.0
faiss-cpu==1.10.0
filelock==3.17.0
h11==0.14.0
hatch==1.14.0
hatchling==1.27.0
httpcore==1.0.7
httpx==0.28.1
hyperlink==21.0.0
id==1.5.0
identify==2.6.7
idna==3.10
importlib_metadata==8.6.1
iniconfig==2.0.0
ipython==8.18.1
isort==6.0.0
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.1.0
jedi==0.19.2
jiter==0.9.0
keyring==25.6.0
markdown-it-py==3.0.0
matplotlib-inline==0.1.7
mdurl==0.1.2
more-itertools==10.6.0
mypy==1.15.0
mypy-extensions==1.0.0
mypy-protobuf==3.6.0
nh3==0.2.20
nodeenv==1.9.1
numpy==2.0.2
packaging==24.2
parso==0.8.4
pathspec==0.12.1
pexpect==4.9.0
platformdirs==4.3.6
pluggy==1.5.0
pre_commit==4.1.0
prompt_toolkit==3.0.50
protobuf==6.32.1
ptyprocess==0.7.0
pure_eval==0.2.3
pydantic==2.10.6
pydantic_core==2.27.2
Pygments==2.19.1
pyproject_hooks==1.2.0
pytest==8.3.4
python-dotenv==1.0.1
PyYAML==6.0.2
readme_renderer==44.0
regex==2024.11.6
requests==2.32.3
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==13.9.4
ruff==0.9.6
shellingham==1.5.4
sniffio==1.3.1
stack-data==0.6.3
testcontainers==4.9.2
tiktoken==0.9.0
tomli==2.2.1
tomli_w==1.2.0
tomlkit==0.13.2
tqdm==4.67.1
traitlets==5.14.3
trove-classifiers==2025.3.13.13
twine==6.1.0
types-protobuf==6.30.2.20250822
types-requests==2.32.0.20241016
typing_extensions==4.12.2
urllib3==2.3.0
userpath==1.9.2
uv==0.6.6
virtualenv==20.29.2
wcwidth==0.2.13
wrapt==1.17.2
zipp==3.21.0
zstandard==0.23.0
certifi==2026.5.20
charset-normalizer==3.4.7
idna==3.18
pydantic==2.13.4
pydantic_core==2.46.4
requests==2.34.2
typing-inspection==0.4.2
typing_extensions==4.15.0
urllib3==2.7.0
22 changes: 22 additions & 0 deletions src/lionweb/api/composite_classifier_instance_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@


class CompositeClassifierInstanceResolver(ClassifierInstanceResolver):
"""A resolver that delegates to a sequence of resolvers, in order.

The first resolver able to resolve a given instance ID wins.
"""

def __init__(self, *classifier_instance_resolvers: ClassifierInstanceResolver):
self.classifier_instance_resolvers: list[ClassifierInstanceResolver] = list(
classifier_instance_resolvers
Expand All @@ -11,10 +16,27 @@ def __init__(self, *classifier_instance_resolvers: ClassifierInstanceResolver):
def add(
self, classifier_instance_resolver: ClassifierInstanceResolver
) -> "CompositeClassifierInstanceResolver":
"""Append a resolver to the chain.

Args:
classifier_instance_resolver: The resolver to add.

Returns:
CompositeClassifierInstanceResolver: This instance, to allow chaining.
"""
self.classifier_instance_resolvers.append(classifier_instance_resolver)
return self

def resolve(self, instance_id: str) -> ClassifierInstance | None:
"""Resolve the instance ID using the first resolver in the chain that succeeds.

Args:
instance_id: The ID of the classifier instance to resolve.

Returns:
The resolved classifier instance, or None if no resolver in the chain
could resolve it.
"""
for resolver in self.classifier_instance_resolvers:
instance = resolver.resolve(instance_id)
if instance is not None:
Expand Down
37 changes: 33 additions & 4 deletions src/lionweb/api/local_classifier_instance_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,52 @@


class LocalClassifierInstanceResolver(ClassifierInstanceResolver):
"""A resolver backed by an in-memory dictionary of classifier instances, keyed by ID."""

def __init__(self, *instances: "ClassifierInstance"):
self.instances: dict[str, ClassifierInstance] = {
cast(str, instance.id): instance for instance in instances if instance.id
}

def add(self, instance) -> "LocalClassifierInstanceResolver":
self.instances[instance.id] = instance
def add(self, instance: "ClassifierInstance") -> "LocalClassifierInstanceResolver":
"""Register a single classifier instance, keyed by its ID.

Args:
instance: The classifier instance to register.

Returns:
LocalClassifierInstanceResolver: This instance, to allow chaining.
"""
if instance.id is not None:
self.instances[instance.id] = instance
return self

def resolve(self, instance_id) -> Optional["ClassifierInstance"]:
def resolve(self, instance_id: str) -> Optional["ClassifierInstance"]:
"""Look up a classifier instance by ID in the local registry.

Args:
instance_id: The ID of the classifier instance to resolve.

Returns:
The registered classifier instance, or None if not registered.
"""
return self.instances.get(instance_id)

def extend(self, instances: Iterable["ClassifierInstance"]) -> None:
"""Register multiple classifier instances.

Args:
instances: The classifier instances to register.
"""
for instance in instances:
self.add(instance)

def add_tree(self, root: "ClassifierInstance"):
def add_tree(self, root: "ClassifierInstance") -> None:
"""Register the given instance and all of its descendants, recursively.

Args:
root: The root of the tree of classifier instances to register.
"""
self.add(root)
for child in root.get_children():
self.add_tree(child)
Expand Down
27 changes: 23 additions & 4 deletions src/lionweb/client/bulk_import.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from dataclasses import dataclass

from lionweb import LionWebVersion
from lionweb.language import Containment
from lionweb.model import ClassifierInstance
Expand All @@ -10,6 +12,14 @@


class BulkImport:
"""Accumulates serialized nodes and attach points for a bulk-import request.

Nodes can be added either as already-serialized `SerializedClassifierInstance`
objects, or as live `ClassifierInstance` objects (which get serialized
immediately). Attach points describe where imported subtrees should be
grafted onto an existing repository.
"""

# Cache for JsonSerialization per LionWebVersion
_json_serializations: dict[LionWebVersion, JsonSerialization] = {}

Expand Down Expand Up @@ -89,11 +99,20 @@ def __bool__(self) -> bool:

# --- nested class ---

@dataclass
class AttachPoint:
def __init__(self, container: str, containment: MetaPointer, root_id: str) -> None:
self.container: str = container
self.containment: MetaPointer = containment
self.root_id: str = root_id
"""Describes where a set of imported nodes should be attached.

Attributes:
container: ID of the node that will contain the imported root.
containment: The containment feature (as a MetaPointer) under which
the imported root will be attached.
root_id: ID of the root node being attached.
"""

container: str
containment: MetaPointer
root_id: str

@classmethod
def from_meta(
Expand Down
Loading
Loading