Skip to content

Commit 4b86ac5

Browse files
committed
wip: store artifact deps in tg context
1 parent 0e34974 commit 4b86ac5

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

typegraph/node/sdk/src/runtimes/python.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
import * as t from "../types.js";
55
import { runtimes } from "../wit.js";
6-
import { Effect } from "../gen/interfaces/metatype-typegraph-runtimes.js";
6+
import {
7+
DependencyMeta,
8+
Effect,
9+
} from "../gen/interfaces/metatype-typegraph-runtimes.js";
710
import { Materializer, Runtime } from "./mod.js";
811
import { fx } from "../index.js";
912
import { getFileHash } from "../utils/file_utils.js";
@@ -22,10 +25,16 @@ interface DefMat extends Materializer {
2225
interface PythonImport {
2326
name: string;
2427
module: string;
28+
deps: Array<string>;
2529
secrets?: Array<string>;
2630
effect?: Effect;
2731
}
2832

33+
// interface DependencyMeta {
34+
// path: string;
35+
// hash: string;
36+
// }
37+
2938
interface ImportMat extends Materializer {
3039
module: string;
3140
name: string;
@@ -91,7 +100,7 @@ export class PythonRuntime extends Runtime {
91100
>(
92101
inp: I,
93102
out: O,
94-
{ name, module, effect = fx.read(), secrets = [] }: PythonImport,
103+
{ name, module, deps = [], effect = fx.read(), secrets = [] }: PythonImport,
95104
): Promise<t.Func<I, O, ImportMat>> {
96105
const base = {
97106
runtime: this._id,
@@ -100,10 +109,22 @@ export class PythonRuntime extends Runtime {
100109

101110
const artifactHash = await getFileHash(module);
102111

112+
// generate dep meta
113+
const depMetas: DependencyMeta[] = [];
114+
for (const dep of deps) {
115+
const depHash = await getFileHash(dep);
116+
const depMeta: DependencyMeta = {
117+
path: dep,
118+
depHash: depHash,
119+
};
120+
depMetas.push(depMeta);
121+
}
122+
103123
const matId = runtimes.fromPythonModule(base, {
104124
artifact: module,
105125
runtime: this._id,
106126
artifactHash: artifactHash,
127+
deps: depMetas,
107128
});
108129

109130
const pyModMatId = runtimes.fromPythonImport(base, {

typegraph/python/typegraph/runtimes/python.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from typegraph.gen.exports.runtimes import (
1111
BaseMaterializer,
12+
DependencyMeta,
1213
Effect,
1314
EffectRead,
1415
MaterializerPythonDef,
@@ -94,6 +95,7 @@ def import_(
9495
*,
9596
module: str,
9697
name: str,
98+
deps: List[str] = [],
9799
effect: Optional[Effect] = None,
98100
secrets: Optional[List[str]] = None,
99101
):
@@ -102,12 +104,22 @@ def import_(
102104

103105
artifact_hash = get_file_hash(module)
104106

107+
# generate dep_metas
108+
dep_metas = []
109+
for dep in deps:
110+
dep_hash = get_file_hash(dep)
111+
dep_meta = DependencyMeta(path=dep, dep_hash=dep_hash)
112+
dep_metas.append(dep_meta)
113+
105114
base = BaseMaterializer(runtime=self.id.value, effect=effect)
106115
mat_id = runtimes.from_python_module(
107116
store,
108117
base,
109118
MaterializerPythonModule(
110-
artifact=module, artifact_hash=artifact_hash, runtime=self.id.value
119+
artifact=module,
120+
artifact_hash=artifact_hash,
121+
deps=deps,
122+
runtime=self.id.value,
111123
),
112124
)
113125

0 commit comments

Comments
 (0)