continuo-python-runtime 0.12.0__py3-none-any.whl → 0.13.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.
- continuo_python_runtime/cli.py +102 -37
- continuo_python_runtime/content_check.py +4 -4
- continuo_python_runtime/contract/kinds.py +37 -29
- continuo_python_runtime/contract/loader.py +207 -439
- continuo_python_runtime/contract/model.py +12 -6
- continuo_python_runtime/contract/pack.py +299 -0
- continuo_python_runtime/contract/paths.py +1 -1
- continuo_python_runtime/contract/read_tables.py +85 -0
- continuo_python_runtime/harness.py +14 -5
- continuo_python_runtime/hashing.py +23 -40
- continuo_python_runtime/packages.py +56 -0
- {continuo_python_runtime-0.12.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/METADATA +191 -119
- {continuo_python_runtime-0.12.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/RECORD +17 -16
- continuo_python_runtime/contract/merge.py +0 -178
- continuo_python_runtime/contract/secret_ref.py +0 -31
- {continuo_python_runtime-0.12.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/WHEEL +0 -0
- {continuo_python_runtime-0.12.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/entry_points.txt +0 -0
- {continuo_python_runtime-0.12.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/licenses/LICENSE +0 -0
- {continuo_python_runtime-0.12.0.dist-info → continuo_python_runtime-0.13.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"""Contract v1 merger: wire contract builder."""
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
import yaml
|
|
6
|
-
|
|
7
|
-
from continuo_python_runtime.contract.loader import load_contract_dir
|
|
8
|
-
from continuo_python_runtime.contract.model import CONTRACT_VERSION, DEFAULT_MODE_TYPE, Node
|
|
9
|
-
from continuo_python_runtime.errors import ContractError
|
|
10
|
-
from continuo_python_runtime.hash_inputs import gather_hash_inputs
|
|
11
|
-
from continuo_python_runtime.hashing import hash_parts
|
|
12
|
-
from continuo_python_runtime.lint import lint_source
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def node_entry(node: Node) -> dict:
|
|
16
|
-
"""Convert a Node to its wire form dict.
|
|
17
|
-
|
|
18
|
-
Returns the node as a dict with all fields, output_columns as list of
|
|
19
|
-
dicts. The entry carries no hash fields: build_wire_contract adds all
|
|
20
|
-
four (source_hash, shared_code_hash, config_hash, content_hash). The
|
|
21
|
-
nullable field is always present in output_columns. ``secret_ref``,
|
|
22
|
-
``mode_type``, ``primary_key`` and ``assets`` appear only when they differ
|
|
23
|
-
from their default, so the entry of a node that does not use them stays
|
|
24
|
-
minimal.
|
|
25
|
-
"""
|
|
26
|
-
entry = {
|
|
27
|
-
"schema": node.schema,
|
|
28
|
-
"table": node.table,
|
|
29
|
-
"owner": node.owner,
|
|
30
|
-
"schedule": node.schedule,
|
|
31
|
-
"criticality": node.criticality,
|
|
32
|
-
"kind": node.kind,
|
|
33
|
-
"script": node.script,
|
|
34
|
-
"reads": node.reads,
|
|
35
|
-
"output_columns": [
|
|
36
|
-
{
|
|
37
|
-
"name": col.name,
|
|
38
|
-
"type": col.type,
|
|
39
|
-
"nullable": col.nullable,
|
|
40
|
-
}
|
|
41
|
-
for col in node.output_columns
|
|
42
|
-
],
|
|
43
|
-
"description": node.description,
|
|
44
|
-
"extra_columns": node.extra_columns,
|
|
45
|
-
"config": dict(node.config),
|
|
46
|
-
}
|
|
47
|
-
# Only a kind that may name a Secret ever carries one; the key is emitted
|
|
48
|
-
# only when set.
|
|
49
|
-
if node.secret_ref:
|
|
50
|
-
entry["secret_ref"] = node.secret_ref
|
|
51
|
-
# Same reasoning: a replace node's entry carries no mode_type.
|
|
52
|
-
if node.mode_type != DEFAULT_MODE_TYPE:
|
|
53
|
-
entry["mode_type"] = node.mode_type
|
|
54
|
-
if node.mode_type == "upsert":
|
|
55
|
-
entry["primary_key"] = list(node.primary_key)
|
|
56
|
-
if node.assets:
|
|
57
|
-
entry["assets"] = list(node.assets)
|
|
58
|
-
return entry
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def _lint_node_closure(
|
|
62
|
-
node: Node,
|
|
63
|
-
repo_root: Path,
|
|
64
|
-
code_files: tuple[tuple[Path, bytes], ...],
|
|
65
|
-
) -> None:
|
|
66
|
-
"""Lint the node's script and every resolved closure member.
|
|
67
|
-
|
|
68
|
-
Every file that executes for this node — the script plus its transitive
|
|
69
|
-
in-repo import closure — is held to the same lint rules
|
|
70
|
-
(``continuo_python_runtime.lint.lint_source``: L1 forbidden driver
|
|
71
|
-
imports, L2 SQL string literals, L3 forbidden data-access calls, L4
|
|
72
|
-
private-attribute access, L5 dynamic-import constructs, L6 constructs
|
|
73
|
-
that run code the hash cannot see) that CI's
|
|
74
|
-
``continuo-runtime lint`` applies to ``scripts/``. Enforcing it again
|
|
75
|
-
here, at merge time, means a helper file outside ``scripts/`` — which
|
|
76
|
-
the CI lint step never looks at — cannot become a side channel around
|
|
77
|
-
the harness's sole write sink, and the check cannot be defeated by a
|
|
78
|
-
stale or hand-edited workflow file: whatever produces the release
|
|
79
|
-
artifact is the thing that checked.
|
|
80
|
-
|
|
81
|
-
Paths in violation messages are repo-root-relative (``str(path.relative_to
|
|
82
|
-
(repo_root))``), so a message reads ``lib/shared.py:1: ...`` identically
|
|
83
|
-
in CI and on a laptop, never an absolute path that differs between the
|
|
84
|
-
two.
|
|
85
|
-
|
|
86
|
-
Raises ``ContractError`` naming the node and listing every violation
|
|
87
|
-
from every offending file — not just the first file's — so an author
|
|
88
|
-
can act on the full report in one pass instead of an iterative guessing
|
|
89
|
-
game.
|
|
90
|
-
|
|
91
|
-
Every file is decoded as ``"utf-8-sig"`` (identical to plain ``"utf-8"``
|
|
92
|
-
except that a leading BOM, if present, is stripped rather than kept as a
|
|
93
|
-
literal ``U+FEFF`` character) — this matches what ``ast.parse(bytes)``
|
|
94
|
-
already does for the same file in ``resolve_closure`` (bytes-mode
|
|
95
|
-
parsing treats a UTF-8 BOM as an implicit encoding declaration and
|
|
96
|
-
strips it), so a BOM file that parses and runs fine is not rejected here
|
|
97
|
-
on a mismatch between the two decoders. A file that isn't valid UTF-8 at
|
|
98
|
-
all (e.g. a PEP 263 ``# -*- coding: latin-1 -*-`` cookie plus a
|
|
99
|
-
non-ASCII byte — valid input to ``ast.parse(bytes)``, which honors the
|
|
100
|
-
cookie) raises ``UnicodeDecodeError``; that is caught and re-raised as a
|
|
101
|
-
``ContractError`` naming the node and the offending repo-relative path,
|
|
102
|
-
so it joins the same error taxonomy as every other rejection here
|
|
103
|
-
instead of escaping as a bare stdlib exception past ``cli.main``, which
|
|
104
|
-
catches only ``HarnessError``/``OSError``.
|
|
105
|
-
"""
|
|
106
|
-
repo_root_resolved = repo_root.resolve()
|
|
107
|
-
violations: list[str] = []
|
|
108
|
-
for path, data in code_files:
|
|
109
|
-
rel = path.relative_to(repo_root_resolved)
|
|
110
|
-
try:
|
|
111
|
-
text = data.decode("utf-8-sig")
|
|
112
|
-
except UnicodeDecodeError as exc:
|
|
113
|
-
raise ContractError(f"{node.relation}: {rel}: not valid UTF-8: {exc}") from exc
|
|
114
|
-
violations.extend(lint_source(text, str(rel)))
|
|
115
|
-
|
|
116
|
-
if violations:
|
|
117
|
-
report = "\n".join(violations)
|
|
118
|
-
raise ContractError(
|
|
119
|
-
f"{node.relation}: lint violations in script or import closure:\n{report}"
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def build_wire_contract(
|
|
124
|
-
contract_dir: Path, repo_root: Path, service: str, *, dialect: str | None = None
|
|
125
|
-
) -> dict:
|
|
126
|
-
"""Build and return a wire contract document.
|
|
127
|
-
|
|
128
|
-
Loads contracts from contract_dir, resolves script paths against repo_root,
|
|
129
|
-
computes content hashes, and returns a contract document sorted by relation.
|
|
130
|
-
``dialect`` is forwarded to :func:`~continuo_python_runtime.contract.loader
|
|
131
|
-
.load_contract_dir` so every declared read is checked against that sqlglot
|
|
132
|
-
dialect (``None`` -- the default -- uses sqlglot's dialect-neutral parser).
|
|
133
|
-
|
|
134
|
-
Raises ContractError if any script file is missing, or if the repository
|
|
135
|
-
root holds a ``sitecustomize.py`` or ``usercustomize.py``: Python imports
|
|
136
|
-
either at startup, before the harness, so nothing in a node's import
|
|
137
|
-
closure reaches it.
|
|
138
|
-
"""
|
|
139
|
-
nodes = load_contract_dir(contract_dir, dialect=dialect)
|
|
140
|
-
|
|
141
|
-
for hook in ("sitecustomize.py", "usercustomize.py"):
|
|
142
|
-
if (repo_root / hook).exists():
|
|
143
|
-
raise ContractError(
|
|
144
|
-
f"{hook} at the repository root runs before the harness and is not in the hash"
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
wire_nodes = []
|
|
148
|
-
for node in nodes:
|
|
149
|
-
entry = node_entry(node)
|
|
150
|
-
|
|
151
|
-
inputs = gather_hash_inputs(node, repo_root)
|
|
152
|
-
_lint_node_closure(node, repo_root, inputs.code_files)
|
|
153
|
-
entry.update(hash_parts(node, inputs.primary, inputs.units))
|
|
154
|
-
# The one wire key outside config_hash: it is written after the hashes
|
|
155
|
-
# are computed, so changing it alone never changes content_hash.
|
|
156
|
-
if node.timeout_minutes is not None:
|
|
157
|
-
entry["timeout_minutes"] = node.timeout_minutes
|
|
158
|
-
|
|
159
|
-
wire_nodes.append(entry)
|
|
160
|
-
|
|
161
|
-
# Sort by relation (schema.table)
|
|
162
|
-
wire_nodes.sort(key=lambda entry: f"{entry['schema']}.{entry['table']}")
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
"contract_version": CONTRACT_VERSION,
|
|
166
|
-
"service": service,
|
|
167
|
-
"nodes": wire_nodes,
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
def write_wire_contract(doc: dict, out: Path) -> None:
|
|
172
|
-
"""Write a wire contract document to a YAML file.
|
|
173
|
-
|
|
174
|
-
Creates ``out``'s parent directory (and any missing ancestors) first, so
|
|
175
|
-
callers don't need to pre-create the output directory.
|
|
176
|
-
"""
|
|
177
|
-
out.parent.mkdir(parents=True, exist_ok=True)
|
|
178
|
-
out.write_text(yaml.safe_dump(doc, sort_keys=False))
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""The name of the Kubernetes Secret a node's pod receives as env vars.
|
|
2
|
-
|
|
3
|
-
The ``continuo-api-`` prefix keeps a contract from naming any other Secret in
|
|
4
|
-
the namespace (the warehouse credentials, the platform's own credentials).
|
|
5
|
-
continuo's topology-controller and execution-controller enforce the same
|
|
6
|
-
pattern; this check gives the author the error in CI instead.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import re
|
|
12
|
-
|
|
13
|
-
from continuo_python_runtime.errors import ContractError
|
|
14
|
-
|
|
15
|
-
SECRET_REF_PATTERN = re.compile(r"^continuo-api-[a-z0-9]([-a-z0-9]*[a-z0-9])?$")
|
|
16
|
-
SECRET_REF_MAX_LEN = 253
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def validate_secret_ref(value: object, label: str) -> str:
|
|
20
|
-
"""Return ``value`` if it is a valid ``continuo-api-*`` Secret name."""
|
|
21
|
-
if (
|
|
22
|
-
not isinstance(value, str)
|
|
23
|
-
or len(value) > SECRET_REF_MAX_LEN
|
|
24
|
-
or not SECRET_REF_PATTERN.fullmatch(value)
|
|
25
|
-
):
|
|
26
|
-
raise ContractError(
|
|
27
|
-
f"{label}: 'secret_ref' must be a Kubernetes Secret name starting with "
|
|
28
|
-
f"'continuo-api-' (lowercase letters, digits, '-'; at most "
|
|
29
|
-
f"{SECRET_REF_MAX_LEN} chars), got {value!r}"
|
|
30
|
-
)
|
|
31
|
-
return value
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|