libbeachcomber 0.8.0__tar.gz → 0.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: libbeachcomber
3
- Version: 0.8.0
3
+ Version: 0.9.1
4
4
  Summary: Python client SDK for the beachcomber (comb) shell-state daemon
5
5
  Project-URL: Homepage, https://github.com/NavistAu/beachcomber
6
6
  Project-URL: Repository, https://github.com/NavistAu/beachcomber
@@ -85,6 +85,15 @@ with client.session() as session:
85
85
  hostname = session.get("hostname")
86
86
  ```
87
87
 
88
+ ## Resolve and eval
89
+
90
+ `client.resolve(key, cwd, env=None, overrides=None)` evaluates a declared
91
+ virtual field client-side; `client.eval(template_str, cwd, env=None,
92
+ overrides=None)` evaluates a raw expression the same way. Both `cwd`
93
+ arguments are required. The expression itself accepts a bare expression, a
94
+ single `{{ expr }}` tag, or literal text/several tags — the first two keep
95
+ the expression's natural type, the third is always a string.
96
+
88
97
  ## Custom socket path
89
98
 
90
99
  ```python
@@ -61,6 +61,15 @@ with client.session() as session:
61
61
  hostname = session.get("hostname")
62
62
  ```
63
63
 
64
+ ## Resolve and eval
65
+
66
+ `client.resolve(key, cwd, env=None, overrides=None)` evaluates a declared
67
+ virtual field client-side; `client.eval(template_str, cwd, env=None,
68
+ overrides=None)` evaluates a raw expression the same way. Both `cwd`
69
+ arguments are required. The expression itself accepts a bare expression, a
70
+ single `{{ expr }}` tag, or literal text/several tags — the first two keep
71
+ the expression's natural type, the third is always a string.
72
+
64
73
  ## Custom socket path
65
74
 
66
75
  ```python
@@ -153,8 +153,8 @@ def _run_op(
153
153
  Returns the raw response data (or None for ops that return nothing),
154
154
  or raises CombError / ServerError on failure.
155
155
 
156
- `resolve_ctx` (only consulted for the `resolve` op) carries the
157
- fixture's `virtual`/`env`/`cwd` blocks — see
156
+ `resolve_ctx` (only consulted for the `resolve` and `eval` ops) carries
157
+ the fixture's `virtual`/`env`/`cwd` blocks — see
158
158
  tests/conformance/README.md.
159
159
  """
160
160
  if op == "resolve":
@@ -166,6 +166,19 @@ def _run_op(
166
166
  env=resolve_ctx["env"] or None,
167
167
  overrides=resolve_ctx["virtual"] or None,
168
168
  )
169
+ if op == "eval":
170
+ assert resolve_ctx is not None
171
+ from libbeachcomber.result import CombResult
172
+
173
+ value = client.eval(
174
+ args.get("template", ""),
175
+ cwd=resolve_ctx["cwd"],
176
+ env=resolve_ctx["env"] or None,
177
+ overrides=resolve_ctx["virtual"] or None,
178
+ )
179
+ # Client.eval returns the bare value; wrap it the way Client.resolve
180
+ # already does so the shared expectation checks see one shape.
181
+ return CombResult(ok=True, data=value, age_ms=0, stale=False)
169
182
  if op == "get":
170
183
  return client.get(**args)
171
184
  if op == "refresh":
@@ -221,6 +234,7 @@ _SUPPORTED_OPS = {
221
234
  "watch",
222
235
  "introspect",
223
236
  "resolve",
237
+ "eval",
224
238
  }
225
239
 
226
240
 
@@ -408,7 +422,7 @@ def _check_data_type(data: Any, expected_type: str) -> bool:
408
422
  return isinstance(data, str)
409
423
  if expected_type == "number":
410
424
  return isinstance(data, (int, float)) and not isinstance(data, bool)
411
- if expected_type == "boolean":
425
+ if expected_type == "bool":
412
426
  return isinstance(data, bool)
413
427
  if expected_type == "null":
414
428
  return data is None
@@ -394,9 +394,13 @@ class Client:
394
394
  env: Optional[dict] = None,
395
395
  overrides: Optional[dict] = None,
396
396
  ) -> Any:
397
- """Evaluate an arbitrary expression string — the same evaluator
398
- :meth:`resolve` uses for a declared virtual field, but for a raw
399
- expression that need not be registered anywhere.
397
+ """Evaluate a value expression — the same evaluator :meth:`resolve`
398
+ uses for a declared virtual field, but for a raw expression that
399
+ need not be registered anywhere.
400
+
401
+ ``template_str`` accepts a bare expression, a single ``{{ expr }}``
402
+ tag, or literal text/several tags — the first two keep the
403
+ expression's natural type, the third is always a string.
400
404
 
401
405
  Args:
402
406
  template_str: The expression to evaluate.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "libbeachcomber"
7
- version = "0.8.0"
7
+ version = "0.9.1"
8
8
  description = "Python client SDK for the beachcomber (comb) shell-state daemon"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }