Skip to content

Commit e5c50c4

Browse files
committed
fix(client,demo): accept schema_mode as str|int; fix error messages; run install-sdk.sh at Jupyter startup
1 parent 4ed2391 commit e5c50c4

2 files changed

Lines changed: 48 additions & 18 deletions

File tree

coordinode/coordinode/client.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ def _build_property_definitions(
474474
# list | tuple union syntax is valid in isinstance() for Python ≥3.10 (PEP 604).
475475
# This project targets Python ≥3.11 (pyproject.toml: requires-python = ">=3.11").
476476
if not isinstance(properties, list | tuple):
477-
raise ValueError(f"'properties' must be a list of property dicts or None; got {type(properties).__name__}")
477+
raise ValueError(
478+
f"'properties' must be a list or tuple of property dicts or None; got {type(properties).__name__}"
479+
)
478480
result = []
479481
for idx, p in enumerate(properties):
480482
name, type_str, required, unique = AsyncCoordinodeClient._validate_property_dict(p, idx)
@@ -498,7 +500,7 @@ async def create_label(
498500
name: str,
499501
properties: list[dict[str, Any]] | None = None,
500502
*,
501-
schema_mode: str = "strict",
503+
schema_mode: str | int = "strict",
502504
) -> LabelInfo:
503505
"""Create a node label in the schema registry.
504506
@@ -525,17 +527,28 @@ async def create_label(
525527
"validated": SchemaMode.SCHEMA_MODE_VALIDATED,
526528
"flexible": SchemaMode.SCHEMA_MODE_FLEXIBLE,
527529
}
528-
if not isinstance(schema_mode, str):
529-
raise ValueError(f"schema_mode must be a str, got {type(schema_mode).__name__!r}")
530-
schema_mode_normalized = schema_mode.strip().lower()
531-
if schema_mode_normalized not in _mode_map:
532-
raise ValueError(f"schema_mode must be one of {list(_mode_map)}, got {schema_mode!r}")
530+
if isinstance(schema_mode, int):
531+
# Accept int to allow round-tripping LabelInfo.schema_mode back into this call.
532+
valid_ints = set(_mode_map.values())
533+
if schema_mode not in valid_ints:
534+
raise ValueError(
535+
f"schema_mode integer {schema_mode!r} is not a valid SchemaMode value; "
536+
f"expected one of {sorted(valid_ints)} or a string {list(_mode_map)!r}"
537+
)
538+
proto_schema_mode = schema_mode
539+
elif isinstance(schema_mode, str):
540+
schema_mode_normalized = schema_mode.strip().lower()
541+
if schema_mode_normalized not in _mode_map:
542+
raise ValueError(f"schema_mode must be one of {list(_mode_map)}, got {schema_mode!r}")
543+
proto_schema_mode = _mode_map[schema_mode_normalized]
544+
else:
545+
raise ValueError(f"schema_mode must be a str or int, got {type(schema_mode).__name__!r}")
533546

534547
proto_props = self._build_property_definitions(properties, PropertyType, PropertyDefinition)
535548
req = CreateLabelRequest(
536549
name=name,
537550
properties=proto_props,
538-
schema_mode=_mode_map[schema_mode_normalized],
551+
schema_mode=proto_schema_mode,
539552
)
540553
label = await self._schema_stub.CreateLabel(req, timeout=self._timeout)
541554
return LabelInfo(label)
@@ -545,7 +558,7 @@ async def create_edge_type(
545558
name: str,
546559
properties: list[dict[str, Any]] | None = None,
547560
*,
548-
schema_mode: str = "strict",
561+
schema_mode: str | int = "strict",
549562
) -> EdgeTypeInfo:
550563
"""Create an edge type in the schema registry.
551564
@@ -571,17 +584,28 @@ async def create_edge_type(
571584
"validated": SchemaMode.SCHEMA_MODE_VALIDATED,
572585
"flexible": SchemaMode.SCHEMA_MODE_FLEXIBLE,
573586
}
574-
if not isinstance(schema_mode, str):
575-
raise ValueError(f"schema_mode must be a str, got {type(schema_mode).__name__!r}")
576-
schema_mode_normalized = schema_mode.strip().lower()
577-
if schema_mode_normalized not in _mode_map:
578-
raise ValueError(f"schema_mode must be one of {list(_mode_map)}, got {schema_mode!r}")
587+
if isinstance(schema_mode, int):
588+
# Accept int to allow round-tripping EdgeTypeInfo.schema_mode back into this call.
589+
valid_ints = set(_mode_map.values())
590+
if schema_mode not in valid_ints:
591+
raise ValueError(
592+
f"schema_mode integer {schema_mode!r} is not a valid SchemaMode value; "
593+
f"expected one of {sorted(valid_ints)} or a string {list(_mode_map)!r}"
594+
)
595+
proto_schema_mode = schema_mode
596+
elif isinstance(schema_mode, str):
597+
schema_mode_normalized = schema_mode.strip().lower()
598+
if schema_mode_normalized not in _mode_map:
599+
raise ValueError(f"schema_mode must be one of {list(_mode_map)}, got {schema_mode!r}")
600+
proto_schema_mode = _mode_map[schema_mode_normalized]
601+
else:
602+
raise ValueError(f"schema_mode must be a str or int, got {type(schema_mode).__name__!r}")
579603

580604
proto_props = self._build_property_definitions(properties, PropertyType, PropertyDefinition)
581605
req = CreateEdgeTypeRequest(
582606
name=name,
583607
properties=proto_props,
584-
schema_mode=_mode_map[schema_mode_normalized],
608+
schema_mode=proto_schema_mode,
585609
)
586610
et = await self._schema_stub.CreateEdgeType(req, timeout=self._timeout)
587611
return EdgeTypeInfo(et)
@@ -626,7 +650,7 @@ async def create_text_index(
626650
elif isinstance(properties, list | tuple):
627651
prop_list = list(properties)
628652
else:
629-
raise ValueError("'properties' must be a property name (str) or a list of property names")
653+
raise ValueError("'properties' must be a property name (str) or a list or tuple of property names")
630654
if not prop_list:
631655
raise ValueError("'properties' must contain at least one property name")
632656
for prop in prop_list:
@@ -942,7 +966,7 @@ def create_label(
942966
name: str,
943967
properties: list[dict[str, Any]] | None = None,
944968
*,
945-
schema_mode: str = "strict",
969+
schema_mode: str | int = "strict",
946970
) -> LabelInfo:
947971
"""Create a node label in the schema registry."""
948972
return self._run(self._async.create_label(name, properties, schema_mode=schema_mode))
@@ -952,7 +976,7 @@ def create_edge_type(
952976
name: str,
953977
properties: list[dict[str, Any]] | None = None,
954978
*,
955-
schema_mode: str = "strict",
979+
schema_mode: str | int = "strict",
956980
) -> EdgeTypeInfo:
957981
"""Create an edge type in the schema registry."""
958982
return self._run(self._async.create_edge_type(name, properties, schema_mode=schema_mode))

demo/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ services:
3535
- JUPYTER_ENABLE_LAB=yes
3636
- JUPYTER_TOKEN=demo # intentional: localhost-only demo stack, documented in README ("token: demo")
3737
- SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 # hatch-vcs: skip git, use fixed version
38+
# Install SDK packages from the mounted /sdk source at container start,
39+
# then hand off to the default Jupyter Lab startup script.
40+
# /tmp/install-sdk.sh is copied into the image by Dockerfile.jupyter;
41+
# it must run after /sdk is mounted (i.e. at runtime, not during build).
42+
command: >-
43+
bash -c "/tmp/install-sdk.sh && start-notebook.sh"
3844
depends_on:
3945
coordinode:
4046
condition: service_healthy

0 commit comments

Comments
 (0)