intentdataflow 0.3.10__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.
Files changed (83) hide show
  1. intentdataflow-0.3.10.dist-info/METADATA +191 -0
  2. intentdataflow-0.3.10.dist-info/RECORD +83 -0
  3. intentdataflow-0.3.10.dist-info/WHEEL +5 -0
  4. intentdataflow-0.3.10.dist-info/entry_points.txt +2 -0
  5. intentdataflow-0.3.10.dist-info/licenses/LICENSE +202 -0
  6. intentdataflow-0.3.10.dist-info/licenses/NOTICE +4 -0
  7. intentdataflow-0.3.10.dist-info/top_level.txt +1 -0
  8. intentflow/__init__.py +2 -0
  9. intentflow/auth.py +30 -0
  10. intentflow/business_rules.py +77 -0
  11. intentflow/catalogs.py +100 -0
  12. intentflow/change_review.py +331 -0
  13. intentflow/checks/__init__.py +92 -0
  14. intentflow/checks/airflow3.py +174 -0
  15. intentflow/checks/business.py +27 -0
  16. intentflow/checks/catalog.py +43 -0
  17. intentflow/checks/cluster.py +81 -0
  18. intentflow/checks/contracts.py +79 -0
  19. intentflow/checks/cost.py +35 -0
  20. intentflow/checks/dbt_quality.py +90 -0
  21. intentflow/checks/dbt_run.py +83 -0
  22. intentflow/checks/deep.py +180 -0
  23. intentflow/checks/dq.py +53 -0
  24. intentflow/checks/elementary.py +50 -0
  25. intentflow/checks/external.py +91 -0
  26. intentflow/checks/lakehouse.py +46 -0
  27. intentflow/checks/lint.py +81 -0
  28. intentflow/checks/orchestration.py +148 -0
  29. intentflow/checks/probes.py +66 -0
  30. intentflow/checks/runtime_history.py +94 -0
  31. intentflow/checks/schema_drift.py +92 -0
  32. intentflow/checks/sql_quality.py +274 -0
  33. intentflow/checks/streaming.py +62 -0
  34. intentflow/cli.py +914 -0
  35. intentflow/contracts.py +107 -0
  36. intentflow/datadiff.py +172 -0
  37. intentflow/dbt_loader.py +194 -0
  38. intentflow/dbt_results.py +55 -0
  39. intentflow/dq_results.py +108 -0
  40. intentflow/extensions.py +51 -0
  41. intentflow/external.py +381 -0
  42. intentflow/http_utils.py +89 -0
  43. intentflow/i18n.py +76 -0
  44. intentflow/incidents.py +83 -0
  45. intentflow/integrations.py +139 -0
  46. intentflow/lakehouse.py +62 -0
  47. intentflow/lineage.py +336 -0
  48. intentflow/lineage_api.py +244 -0
  49. intentflow/lineage_oracle.py +374 -0
  50. intentflow/locale/pt.json +1300 -0
  51. intentflow/model.py +43 -0
  52. intentflow/monitoring.py +197 -0
  53. intentflow/notify.py +154 -0
  54. intentflow/ol_emit.py +93 -0
  55. intentflow/openlineage.py +168 -0
  56. intentflow/orchestrators/__init__.py +53 -0
  57. intentflow/orchestrators/airflow.py +69 -0
  58. intentflow/orchestrators/aws.py +93 -0
  59. intentflow/orchestrators/dagster.py +48 -0
  60. intentflow/orchestrators/dbtcloud.py +68 -0
  61. intentflow/orchestrators/extra.py +135 -0
  62. intentflow/orchestrators/ingestion.py +112 -0
  63. intentflow/orchestrators/kestra.py +27 -0
  64. intentflow/orchestrators/more.py +135 -0
  65. intentflow/orchestrators/prefect.py +53 -0
  66. intentflow/orchestrators/spark.py +118 -0
  67. intentflow/otel.py +53 -0
  68. intentflow/overview.py +123 -0
  69. intentflow/preflight.py +363 -0
  70. intentflow/promexport.py +39 -0
  71. intentflow/pyflow.py +554 -0
  72. intentflow/risks.py +178 -0
  73. intentflow/runner.py +264 -0
  74. intentflow/secrets_box.py +84 -0
  75. intentflow/sqlmesh_loader.py +134 -0
  76. intentflow/store.py +1006 -0
  77. intentflow/streaming.py +115 -0
  78. intentflow/totp.py +38 -0
  79. intentflow/warehouses/__init__.py +190 -0
  80. intentflow/warehouses/cloud.py +160 -0
  81. intentflow/warehouses/more.py +342 -0
  82. intentflow/web.html +878 -0
  83. intentflow/web.py +726 -0
@@ -0,0 +1,134 @@
1
+ """SQLMesh → the same `Project` the dbt loader produces, so lineage, impact, drift and checks work unchanged.
2
+
3
+ SQLMesh runs in its own interpreter (INTENTFLOW_SQLMESH_PYTHON, or the current one if importable); only JSON crosses the boundary.
4
+ For CI without SQLMesh installed: `intentflow sqlmesh-export PROJECT -o sqlmesh_export.json` and use the JSON as the target.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import os
10
+ import subprocess
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ from .dbt_loader import Col, DbtNode, Project
15
+ from .i18n import tr
16
+
17
+ SNAPSHOT = "sqlmesh_export.json"
18
+
19
+ _EXPORT = r'''
20
+ import json, sys
21
+ from sqlmesh import Context
22
+ ctx = Context(paths=sys.argv[1], gateway=(sys.argv[2] or None))
23
+ out = {"dialect": None, "models": []}
24
+ try:
25
+ out["dialect"] = ctx.config.model_defaults.dialect
26
+ except Exception:
27
+ pass
28
+ for fqn, m in ctx.models.items():
29
+ seed = m.kind.name == "SEED"
30
+ q = None
31
+ if not seed and getattr(m, "is_sql", False):
32
+ try:
33
+ q = m.render_query().sql(m.dialect)
34
+ except Exception as e:
35
+ q = None
36
+ try:
37
+ cols = {k: str(v) for k, v in (m.columns_to_types or {}).items()}
38
+ except Exception:
39
+ cols = {}
40
+ out["models"].append({
41
+ "fqn": fqn, "name": m.name, "kind": m.kind.name, "dialect": m.dialect or out["dialect"], "sql": q,
42
+ "columns": cols, "depends_on": sorted(m.depends_on), "owner": m.owner, "description": m.description,
43
+ "column_descriptions": dict(m.column_descriptions or {}), "grain": [str(g) for g in (m.grains or [])],
44
+ "audits": [a[0] for a in (m.audits or [])], "tags": sorted(m.tags or []), "cron": getattr(m, "cron", None),
45
+ "path": str(getattr(m, "_path", "") or ""), "python": not getattr(m, "is_sql", True) and m.kind.name != "SEED",
46
+ })
47
+ print(json.dumps(out))
48
+ '''
49
+
50
+
51
+ def _python() -> str:
52
+ return os.environ.get("INTENTFLOW_SQLMESH_PYTHON") or sys.executable
53
+
54
+
55
+ def is_project(path: str | Path) -> bool:
56
+ p = Path(path)
57
+ return p.is_dir() and (p / "models").is_dir() and any((p / n).exists() for n in ("config.yaml", "config.yml", "config.py"))
58
+
59
+
60
+ def is_snapshot(path: str | Path) -> bool:
61
+ p = Path(path)
62
+ return (p.is_file() and p.suffix == ".json" and "sqlmesh" in p.name) or (p.is_dir() and (p / SNAPSHOT).exists())
63
+
64
+
65
+ def export(project_dir: str | Path, gateway: str | None = None, python: str | None = None) -> dict:
66
+ r = subprocess.run([python or _python(), "-c", _EXPORT, str(project_dir), gateway or ""], capture_output=True, text=True, timeout=600)
67
+ if r.returncode != 0:
68
+ tail = "\n".join((r.stderr or r.stdout).strip().splitlines()[-6:])
69
+ hint = " (" + tr("set INTENTFLOW_SQLMESH_PYTHON to the Python where sqlmesh is installed") + ")" if "No module named 'sqlmesh'" in tail else ""
70
+ raise RuntimeError(tr("failed to read the SQLMesh project") + f"{hint}:\n{tail}")
71
+ return json.loads(r.stdout.strip().splitlines()[-1])
72
+
73
+
74
+ def _relation(fqn: str) -> str:
75
+ return fqn if fqn.startswith('"') else ".".join(f'"{p}"' for p in fqn.split("."))
76
+
77
+
78
+ def _parts(fqn: str) -> list[str]:
79
+ return [p.strip('"') for p in fqn.replace('"."', '\x00').strip('"').split("\x00")]
80
+
81
+
82
+ _MATERIALIZED = {"FULL": "table", "VIEW": "view", "SEED": "seed", "EMBEDDED": "ephemeral", "EXTERNAL": "source", "SCD_TYPE_2": "incremental",
83
+ "INCREMENTAL_BY_TIME_RANGE": "incremental", "INCREMENTAL_BY_UNIQUE_KEY": "incremental",
84
+ "INCREMENTAL_BY_PARTITION": "incremental", "MANAGED": "table"}
85
+
86
+
87
+ def from_export(data: dict, root: str | Path | None = None) -> Project:
88
+ models = data.get("models", [])
89
+ dialect = (data.get("dialect") or "duckdb").lower()
90
+ ids: dict[str, str] = {}
91
+ for m in models:
92
+ ids[m["fqn"]] = f"model.sqlmesh.{_parts(m['fqn'])[-1]}"
93
+ seen: dict[str, int] = {}
94
+ for _fqn, uid in list(ids.items()): # mesmo nome em schemas diferentes
95
+ seen[uid] = seen.get(uid, 0) + 1
96
+ for fqn, uid in list(ids.items()):
97
+ if seen[uid] > 1:
98
+ ids[fqn] = "model.sqlmesh." + ".".join(_parts(fqn)[-2:])
99
+ nodes: dict[str, DbtNode] = {}
100
+ for m in models:
101
+ uid = ids[m["fqn"]]
102
+ seed = m["kind"] == "SEED"
103
+ node = DbtNode(
104
+ unique_id=uid, name=_parts(m["fqn"])[-1], resource_type="seed" if seed else "model", relation=_relation(m["fqn"]),
105
+ path=m.get("path", ""), raw_code="" if seed else (m.get("sql") or ""), compiled_code="" if seed else (m.get("sql") or ""),
106
+ materialized=_MATERIALIZED.get(m["kind"], m["kind"].lower()),
107
+ unique_key=(m["grain"][0] if len(m.get("grain") or []) == 1 else (m.get("grain") or None)),
108
+ contract_enforced=bool(m.get("columns")) and m["kind"] != "VIEW",
109
+ meta={k: v for k, v in {"owner": m.get("owner"), "sqlmesh_kind": m["kind"], "cron": m.get("cron")}.items() if v},
110
+ tags=list(m.get("tags") or []), description=m.get("description") or "",
111
+ depends_on=[ids[d] for d in m.get("depends_on", []) if d in ids],
112
+ )
113
+ descs = {k.lower(): v for k, v in (m.get("column_descriptions") or {}).items()}
114
+ for cn, ct in (m.get("columns") or {}).items():
115
+ node.columns[cn.lower()] = Col(cn.lower(), ct, descs.get(cn.lower(), ""), {}, [], True)
116
+ for a in m.get("audits", []):
117
+ node.tests.append({"name": a, "column": None, "kwargs": {}})
118
+ nodes[uid] = node
119
+ for m in models: # tabelas externas viram "source"
120
+ for d in m.get("depends_on", []):
121
+ if d not in ids:
122
+ uid = f"source.sqlmesh.{_parts(d)[-1]}"
123
+ nodes.setdefault(uid, DbtNode(unique_id=uid, name=_parts(d)[-1], resource_type="source", relation=_relation(d)))
124
+ if uid not in nodes[ids[m["fqn"]]].depends_on:
125
+ nodes[ids[m["fqn"]]].depends_on.append(uid)
126
+ return Project(nodes=nodes, adapter=dialect, root=Path(root) if root else None)
127
+
128
+
129
+ def load(target: str | Path, root: str | Path | None = None) -> Project:
130
+ t = Path(target)
131
+ if is_snapshot(t):
132
+ f = t / SNAPSHOT if t.is_dir() else t
133
+ return from_export(json.loads(f.read_text()), root or f.parent)
134
+ return from_export(export(t), root or t)