@platforma-sdk/workflow-tengo 2.9.2 → 2.9.4

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,17 +15,28 @@ rDescriptor: desc.runEnvScheme,
15
15
  R: validation.reference
16
16
  }
17
17
 
18
- runRBuilder := func(wd, rPackage, rDescriptor) {
18
+ runRBuilder := func(operationMode, wd, rPackage, rDescriptor) {
19
19
  t := desc.canBackendUseExpressions() ? constants.ARG_TYPE_EXPRESSION : constants.ARG_TYPE_VAR
20
20
  rule := desc.canBackendUseExpressions() ? "R" : "{R}"
21
21
 
22
- return runcmd.builder(wd).
22
+ builder := runcmd.builder(wd).
23
23
  ref("r-run-environment", rPackage).
24
24
  substitutionRule(rule, "r-run-environment").
25
25
  addToPath(t, path.join("{R}", rDescriptor.binDir)).
26
- envTyped("R_HOME_DIR", t, "{R}").
27
26
  envTyped("RHOME", t, "{R}").
28
- envTyped("RENV_PATHS_ROOT", t, path.join("{R}", "renv-root"))
27
+ envTyped("R_HOME_DIR", t, "{R}").
28
+ envTyped("RENV_PATHS_ROOT", t, path.join("{R}", "renv-root")).
29
+ envTyped("RENV_PATHS_BINARY", t, path.join("{R}", "renv-root", "binaries")).
30
+ envTyped("RENV_PATHS_SOURCE", t, path.join("{R}", "renv-root", "sources")).
31
+ envTyped("RENV_PATHS_CACHE", t, path.join("{R}", "renv-root", "cache"))
32
+
33
+ if (operationMode != "dev-local") {
34
+
35
+
36
+ builder.envTyped("RENV_CONFIG_REPOS_OVERRIDE", t, path.join("{R}", "renv-root", "packages"))
37
+ }
38
+
39
+ return builder
29
40
  }
30
41
 
31
42
  export ll.toStrict({
@@ -33,6 +33,13 @@ _expr := func(varName) {
33
33
  return "{" + varName + "}"
34
34
  }
35
35
 
36
+ _newTypedArg := func(type, value) {
37
+ return ll.toStrict({
38
+ type: type,
39
+ value: value
40
+ })
41
+ }
42
+
36
43
 
37
44
 
38
45
 
@@ -42,21 +49,12 @@ return "{" + varName + "}"
42
49
 
43
50
  _newArg := func(isString, value) {
44
51
  if isString {
45
- return ll.toStrict({
46
- type: constants.ARG_TYPE_STRING,
47
- value: value
48
- })
52
+ return _newTypedArg(constants.ARG_TYPE_STRING, value)
49
53
  }
50
54
  if desc.canBackendUseExpressions() {
51
- return ll.toStrict({
52
- type: constants.ARG_TYPE_EXPRESSION,
53
- value: value
54
- })
55
+ return _newTypedArg(constants.ARG_TYPE_EXPRESSION, value)
55
56
  }
56
- return ll.toStrict({
57
- type: constants.ARG_TYPE_VAR,
58
- value: value
59
- })
57
+ return _newTypedArg(constants.ARG_TYPE_VAR, value)
60
58
  }
61
59
 
62
60
  _newRefVar := func(varName, refName, reference) {
@@ -164,20 +162,31 @@ rRefVar := _newRefVar(_ARG_VAR_R, rRefKey, rPackage)
164
162
  rEnvRefKey := softName + "/R-virtual-env"
165
163
  rEnvRefVar := _newRefVar(_ARG_VAR_R_VENV, rEnvRefKey, rEnv)
166
164
 
165
+ renvRootArg := path.join(_expr(_ARG_VAR_R), "renv-root")
166
+
167
+ envs := {
168
+ "RHOME": _newArg(false, _expr(_ARG_VAR_R)), // for Rscript (it uses RHOME instead of R_HOME)
169
+ "R_HOME_DIR": _newArg(false, _expr(_ARG_VAR_R)), // for R startup script. It configures all the rest required for R to start.
170
+ "RENV_PATHS_ROOT": _newArg(false, renvRootArg),
171
+ "RENV_PATHS_BINARY": _newArg(false, path.join(renvRootArg, "binaries")),
172
+ "RENV_PATHS_SOURCE": _newArg(false, path.join(renvRootArg, "sources")),
173
+ "RENV_PATHS_CACHE": _newArg(false, path.join(renvRootArg, "cache")),
174
+ "RENV_PATHS_RENV": _newArg(false, path.join(_expr(_ARG_VAR_R_VENV), "renv")),
175
+ "RENV_PATHS_LOCKFILE": _newArg(false, path.join(_expr(_ARG_VAR_PKG), descriptor.dependencies.lockFile))
176
+ }
177
+
178
+ if (operationMode != "dev-local") {
179
+
180
+
181
+ envs["RENV_CONFIG_REPOS_OVERRIDE"] = _newArg(false, path.join(renvRootArg, "packages"))
182
+ }
183
+
167
184
  return ll.toStrict({
168
185
  runEnvType: "R",
169
186
 
170
187
  variables: [ rRefVar, rEnvRefVar ],
171
188
  customPaths: [ _newArg(false, rBinDir) ],
172
- envs: {
173
- "R_HOME_DIR": _newArg(false, _expr(_ARG_VAR_R)),
174
- "RHOME": _newArg(false, _expr(_ARG_VAR_R)),
175
- "RENV_PATHS_ROOT": _newArg(false, path.join(_expr(_ARG_VAR_R), "renv-root")),
176
- "RENV_PATHS_RENV": _newArg(false, path.join(_expr(_ARG_VAR_R_VENV), "renv")),
177
- "RENV_PATHS_LOCKFILE": _newArg(false, path.join(_expr(_ARG_VAR_PKG), descriptor.dependencies.lockFile)),
178
- "RENV_CONFIG_AUTO_SNAPSHOT": _newArg(true, "FALSE"),
179
- "RENV_CONFIG_SYNCHRONIZED_CHECK": _newArg(true, "FALSE")
180
- }
189
+ envs: envs
181
190
  })
182
191
  }
183
192
 
@@ -308,13 +317,11 @@ binaryRunOptions := func(runOptions, mnzEnvs) {
308
317
  validation.assertJsonSchema(mnzEnvs, {"any": validation.reference})
309
318
 
310
319
  runCmdOpts := undefined
311
- onlyStrings := false
312
320
  if (is_undefined(ll.fromStrict(runOptions).software)) {
313
321
 
314
322
 
315
323
 
316
324
  runCmdOpts = _directCallOptions(runOptions)
317
- onlyStrings = true
318
325
  } else {
319
326
  software := runOptions.software
320
327
  descriptor := software.descriptor
@@ -323,11 +330,22 @@ runCmdOpts = swToRunCmdOptions(software.name, software.version, descriptor)
323
330
  }
324
331
 
325
332
 
326
- for arg in runOptions.args {
327
- runCmdOpts.args = append(runCmdOpts.args, _newArg(true, arg))
333
+
334
+
335
+
336
+ opts := ll.fromStrict(runOptions)
337
+ shouldUseNewTyped := !is_undefined(opts.argsTyped) || !is_undefined(opts.envsTyped)
338
+
339
+ args := shouldUseNewTyped ? runOptions.argsTyped : runOptions.args
340
+ for _, arg in args {
341
+ typedArg := shouldUseNewTyped ? _newTypedArg(arg.type, arg.value) : _newArg(true, arg)
342
+ runCmdOpts.args = append(runCmdOpts.args, typedArg)
328
343
  }
329
- for name, val in runOptions.envs {
330
- runCmdOpts.envs[name] = _newArg(true, val)
344
+
345
+ envs := shouldUseNewTyped ? runOptions.envsTyped : runOptions.envs
346
+ for name, v in envs {
347
+ typedEnv := shouldUseNewTyped ? _newTypedArg(v.type, v.value) : _newArg(true, v)
348
+ runCmdOpts.envs[name] = typedEnv
331
349
  }
332
350
 
333
351
  for name, val in mnzEnvs { // can be empty
@@ -17,6 +17,7 @@ validation := import("@platforma-sdk/workflow-tengo:validation")
17
17
  constants := import("@platforma-sdk/workflow-tengo:constants")
18
18
  desc := import("@platforma-sdk/workflow-tengo:exec.descriptor")
19
19
  monetization := import("@platforma-sdk/workflow-tengo:exec.monetization")
20
+ execConstants := import("@platforma-sdk/workflow-tengo:exec.constants")
20
21
 
21
22
  _HEAVY_QUEUE := "heavy"
22
23
  _MEDIUM_QUEUE := "medium"
@@ -33,7 +34,14 @@ self := undefined
33
34
 
34
35
  soft := undefined
35
36
  cmd := undefined
36
- args := []
37
+ args := [] // list of strings
38
+ argsTyped := [] // list of {type: expression|string, value: string}
39
+ typedArgSet := false
40
+ typedEnvSet := false
41
+ envs := {} // map of names to values-strings
42
+ envsTyped := {} // map of names to {type: expression|string, value: string}
43
+ secrets := {} // { "env_name": "{secrets.secret_name}", ... }
44
+
37
45
  entrypointSet := false
38
46
 
39
47
  assertEntrypointNotSet := func() {
@@ -41,8 +49,6 @@ ll.assert(!entrypointSet,
41
49
  "either a command with arguments or a software were already set.")
42
50
  }
43
51
 
44
- envs := {}
45
- secrets := {} // { "env_name": "{secrets.secret_name}", ... }
46
52
  queue := _HEAVY_QUEUE
47
53
  cache := 0
48
54
  nErrorLines := 200
@@ -137,10 +143,31 @@ return self
137
143
 
138
144
 
139
145
  arg: func(arg) {
140
- if is_undefined(arg) {
141
- ll.panic("exec: arg can't be undefined")
142
- }
146
+ ll.assert(is_string(arg), "exec.arg(): argument must be a string, got: %v", arg)
143
147
  args = append(args, arg)
148
+ argsTyped = append(argsTyped, {
149
+ type: execConstants.ARG_TYPE_STRING,
150
+ value: arg
151
+ })
152
+ return self
153
+ },
154
+
155
+
156
+
157
+
158
+
159
+
160
+ argWithVar: func(arg) {
161
+ ll.assert(is_string(arg), "exec.argWithVar(): argument with var must be a string, got: %v", arg)
162
+
163
+
164
+ t := desc.canBackendUseExpressions() ? execConstants.ARG_TYPE_EXPRESSION : execConstants.ARG_TYPE_VAR
165
+ argsTyped = append(argsTyped, {
166
+ type: t,
167
+ value: arg
168
+ })
169
+ typedArgSet = true
170
+
144
171
  return self
145
172
  },
146
173
 
@@ -153,6 +180,30 @@ return self
153
180
  env: func(name, value) {
154
181
  validation.assertJsonSchema([name, value], ["string"])
155
182
  envs[name] = value
183
+ envsTyped[name] = {
184
+ type: execConstants.ARG_TYPE_STRING,
185
+ value: value
186
+ }
187
+ return self
188
+ },
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+ envWithVar: func(name, value) {
197
+ validation.assertJsonSchema([name, value], ["string"])
198
+
199
+
200
+ t := desc.canBackendUseExpressions() ? execConstants.ARG_TYPE_EXPRESSION : execConstants.ARG_TYPE_VAR
201
+ envsTyped[name] = {
202
+ type: t,
203
+ value: value
204
+ }
205
+ typedEnvSet = true
206
+
156
207
  return self
157
208
  },
158
209
 
@@ -656,6 +707,13 @@ if monetization.shouldRun(mnz) {
656
707
  execInputs.runOptions.monetization = monetization.toJson(mnz)
657
708
  }
658
709
 
710
+
711
+
712
+ if typedArgSet || typedEnvSet {
713
+ execInputs.runOptions.argsTyped = argsTyped
714
+ execInputs.runOptions.envsTyped = envsTyped
715
+ }
716
+
659
717
  if !is_undefined(soft) {
660
718
  execInputs.softwareInfo = soft.resource
661
719
  execInputs.runOptions.software = {
@@ -355,7 +355,7 @@ return self
355
355
  build: func() {
356
356
 
357
357
 
358
- ll.assert(!(hasPatternArgs || hasExpressionArgs) || len(substRules) != 0,
358
+ ll.assert(!hasPatternArgs || len(substRules) != 0,
359
359
  "found pattern argument, but no substitution rules were set: hasPatternArgs: %v, substRules: %v, cmd: %v, args: %v, envs: %v",
360
360
  hasPatternArgs, substRules, cmd, args, envs)
361
361
  ll.assert(!hasExpressionArgs || desc.canBackendUseExpressions(),
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/workflow-tengo",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "Tengo SDK library",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "./dist/**/*"
17
17
  ],
18
18
  "dependencies": {
19
- "@milaboratories/software-pframes-conv": "2.1.3",
19
+ "@milaboratories/software-pframes-conv": "2.1.4",
20
20
  "@platforma-open/milaboratories.software-small-binaries": "^1.15.6"
21
21
  },
22
22
  "devDependencies": {