pineforge-codegen 1.4.0__py3-none-any.whl → 1.5.0__py3-none-any.whl

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.
@@ -15,6 +15,7 @@ from .library_inline import inline_libraries
15
15
  from .limits import TimeBudget, check_ast_depth, check_source_size, ensure_recursion_headroom
16
16
  from .pragmas import extract_pf_trace_pragmas
17
17
  from .request_discovery import discover_requests, request_sites
18
+ from .request_feed_inventory import build_request_feed_inventory
18
19
  from .security_contexts import specialize_security_contexts
19
20
  from .block_locals import rename_block_locals
20
21
  from .support_checker import check_support as _support_diagnostics
@@ -172,10 +173,10 @@ def transpile_full(pine_source: str, *, check_support: bool = True,
172
173
  See :meth:`CodeGen.extract_input_manifest`.
173
174
  - ``strategyParams``: the literal ``strategy(...)`` kwargs the analyzer
174
175
  surfaced (e.g. ``initial_capital``, ``pyramiding``).
175
- - ``diagnostics``: the warnings (:class:`~pineforge_codegen.errors.Diagnostic`,
176
- ``Level.WARNING``) the support checker and the analyzer raised for a
176
+ - ``diagnostics``: the warnings and notes (:class:`~pineforge_codegen.errors.Diagnostic`,
177
+ ``Level.WARNING`` / ``Level.NOTE``) the support checker and the analyzer raised for a
177
178
  script that transpiled -- e.g. an approximated ``ta.vwap`` anchor. An
178
- error still raises ``CompileError``, which carries the warnings too.
179
+ error still raises ``CompileError``, which carries nonfatal diagnostics too.
179
180
  - ``requests``: every request site that reads another symbol's feed,
180
181
  by line: its symbol and timeframe as registration computes them
181
182
  before the first bar (``literal`` / ``input`` / ``computed`` /
@@ -198,6 +199,61 @@ def transpile_full(pine_source: str, *, check_support: bool = True,
198
199
  "inputs": gen.extract_input_manifest(),
199
200
  "strategyParams": dict(ctx.strategy_params),
200
201
  "diagnostics": [d for d in (*support_diagnostics, *ctx.diagnostics)
201
- if d.level == Level.WARNING],
202
+ if d.level in (Level.WARNING, Level.NOTE)],
202
203
  "requests": discover_requests(gen, ctx, sites),
203
204
  }
205
+
206
+
207
+ def transpile_with_request_inventory(pine_source: str, *, check_support: bool = True,
208
+ filename: str = "<input>",
209
+ libraries: Mapping[str, str] | None = None,
210
+ primary_chart_timeframe: str | None = None) -> dict:
211
+ """Transpile like :func:`transpile_full`, plus the request-feed inventory
212
+ bound to the C++ it returns (``pineforge_codegen.request_feed_inventory``).
213
+
214
+ Runs the pipeline once (``_generate``) and returns six keys, the five
215
+ :func:`transpile_full` returns computed from that one generation by the
216
+ same expressions, and the inventory:
217
+
218
+ - ``cpp``: the generated C++ source (identical to :func:`transpile`).
219
+ - ``inputs``: the input manifest, as :func:`transpile_full` lists it.
220
+ - ``strategyParams``: the literal ``strategy(...)`` kwargs, as
221
+ :func:`transpile_full` lists them.
222
+ - ``diagnostics``: the warnings and notes, as :func:`transpile_full` lists
223
+ them.
224
+ - ``requests``: the other-symbol feed projection of
225
+ :func:`transpile_full` (``request_discovery.discover_requests``). It
226
+ leaves out the same-ticker requests, so it is not the strategy's
227
+ complete request list.
228
+ - ``request_feed_inventory``: the request-feed inventory bound to ``cpp``
229
+ (``build_request_feed_inventory``). It lists every bar request the
230
+ compiled strategy can make, same ticker included, from the same
231
+ registration context as ``requests``. Its ``artifact_sha256`` is null
232
+ until the trusted compile pipeline binds it after linking with
233
+ :func:`pineforge_codegen.request_feed_inventory.bind_request_feed_inventory`.
234
+
235
+ :func:`transpile` and :func:`transpile_full` are unchanged.
236
+
237
+ Args mirror :func:`transpile_full`, plus:
238
+ primary_chart_timeframe: The chart timeframe the compiled artifact is
239
+ bound to, as a wire token (a request that reads the chart's own
240
+ timeframe is then that token; without it, ``unknown``). A value
241
+ that is no wire token raises ``RequestFeedInventoryError``.
242
+
243
+ Returns:
244
+ ``{"cpp": str, "inputs": list[dict], "strategyParams": dict,
245
+ "diagnostics": list[Diagnostic], "requests": list[dict],
246
+ "request_feed_inventory": dict}``.
247
+ """
248
+ gen, ctx, cpp, support_diagnostics, sites = _generate(
249
+ pine_source, check_support, filename, libraries)
250
+ return {
251
+ "cpp": cpp,
252
+ "inputs": gen.extract_input_manifest(),
253
+ "strategyParams": dict(ctx.strategy_params),
254
+ "diagnostics": [d for d in (*support_diagnostics, *ctx.diagnostics)
255
+ if d.level in (Level.WARNING, Level.NOTE)],
256
+ "requests": discover_requests(gen, ctx, sites),
257
+ "request_feed_inventory": build_request_feed_inventory(
258
+ gen, ctx, sites, cpp, primary_chart_timeframe=primary_chart_timeframe),
259
+ }
@@ -1,7 +1,7 @@
1
1
  """Stable codes and named arguments for every transpile diagnostic.
2
2
 
3
3
  Every :class:`~pineforge_codegen.errors.Diagnostic` carries a ``code``
4
- (``PF-E1203`` for an error, ``PF-W0412`` for a warning) and ``args``, the
4
+ (``PF-E1203`` / ``PF-W0412``) and ``args``, the
5
5
  named data its English ``message`` and ``hint`` were built from. The codes,
6
6
  their severities, English ICU MessageFormat templates and one-line
7
7
  explanations live in ``diagnostics_catalog.json`` beside this module, which
@@ -40,7 +40,9 @@ from typing import Any
40
40
 
41
41
  CATALOG_PATH = Path(__file__).with_name("diagnostics_catalog.json")
42
42
  CATALOG_SCHEMA = "pineforge-diagnostics-catalog/v1"
43
- UNCATALOGUED = {"error": "PF-E0000", "warning": "PF-W0000"}
43
+ # Notes keep historical PF-W identities. The nonfatal fallback is shared;
44
+ # its catalog severity remains warning, while a Diagnostic retains its level.
45
+ UNCATALOGUED = {"error": "PF-E0000", "warning": "PF-W0000", "note": "PF-W0000"}
44
46
 
45
47
 
46
48
  @lru_cache(maxsize=1)
@@ -52,16 +54,22 @@ def _load() -> dict:
52
54
  def diagnostics_catalog() -> dict:
53
55
  """The diagnostics catalog: ``{"schema", "codes": {code: entry}}``.
54
56
 
55
- Each entry gives ``severity`` (``error`` / ``warning``), ``area``, the
57
+ Each entry gives ``severity`` (``error`` / ``warning`` / ``note``), ``area``, the
56
58
  English ICU MessageFormat ``message`` template, the ``hint`` template or
57
59
  ``None``, a one-line ``explanation`` and ``args``: per argument name its
58
60
  ``kind`` (``identifier``, ``type``, ``keyword``, ``number``, ``vocab`` or
59
- ``text``) and, for ``vocab``, its closed set of ``values``. A fresh copy
60
- is returned on every call.
61
+ ``text``) and, for ``vocab``, its closed set of ``values``. ``user_message``
62
+ is a short ICU template over those same arguments, not rendered English.
63
+ A fresh copy is returned on every call.
61
64
  """
62
65
  return json.loads(json.dumps(_load()))
63
66
 
64
67
 
68
+ def _user_message_template(code: str) -> str:
69
+ """The short presentation template; never classify from or render it here."""
70
+ return _load()["codes"][code]["user_message"]
71
+
72
+
65
73
  # ---------------------------------------------------------------------------
66
74
  # ICU MessageFormat subset
67
75
  # ---------------------------------------------------------------------------
@@ -308,7 +316,7 @@ class _Matcher:
308
316
 
309
317
  @lru_cache(maxsize=1)
310
318
  def _matchers() -> dict[str, list[_Matcher]]:
311
- by_severity: dict[str, list[_Matcher]] = {"error": [], "warning": []}
319
+ by_severity: dict[str, list[_Matcher]] = {"error": [], "warning": [], "note": []}
312
320
  for code, entry in _load()["codes"].items():
313
321
  if code in UNCATALOGUED.values():
314
322
  continue
@@ -323,8 +331,10 @@ def _matchers() -> dict[str, list[_Matcher]]:
323
331
  def classify(severity: str, message: str, hint: str | None = None) -> tuple[str, dict]:
324
332
  """The ``(code, args)`` of a diagnostic's English text.
325
333
 
326
- ``severity`` is ``"error"`` or ``"warning"``. A text no catalog template
327
- renders gets ``PF-E0000`` / ``PF-W0000`` with its text as ``args``.
334
+ ``severity`` is ``"error"``, ``"warning"`` or ``"note"``; the catalog's
335
+ declared severity selects the templates, never a code's prefix. A text
336
+ no template renders gets ``PF-E0000`` for an error or ``PF-W0000`` for
337
+ a warning/note, with its text as ``args`` and no new fallback identity.
328
338
  """
329
339
  for matcher in _matchers().get(severity, ()):
330
340
  if matcher.has_hint != (hint is not None):