@platforma-sdk/workflow-tengo 2.9.6 → 2.9.8

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 (64) hide show
  1. package/dist/tengo/lib/assets.lib.tengo +52 -52
  2. package/dist/tengo/lib/assets.swinfo.lib.tengo +45 -45
  3. package/dist/tengo/lib/constants.lib.tengo +32 -32
  4. package/dist/tengo/lib/exec.R.internal.lib.tengo +29 -29
  5. package/dist/tengo/lib/exec.R.lib.tengo +166 -166
  6. package/dist/tengo/lib/exec.constants.lib.tengo +4 -4
  7. package/dist/tengo/lib/exec.descriptor.lib.tengo +31 -31
  8. package/dist/tengo/lib/exec.internal.lib.tengo +297 -297
  9. package/dist/tengo/lib/exec.lib.tengo +815 -815
  10. package/dist/tengo/lib/exec.monetization.lib.tengo +130 -130
  11. package/dist/tengo/lib/exec.package.lib.tengo +212 -212
  12. package/dist/tengo/lib/exec.python.internal.lib.tengo +6 -6
  13. package/dist/tengo/lib/exec.python.lib.tengo +146 -146
  14. package/dist/tengo/lib/exec.runcmd.lib.tengo +371 -371
  15. package/dist/tengo/lib/exec.runenv.lib.tengo +92 -92
  16. package/dist/tengo/lib/exec.stream.lib.tengo +40 -40
  17. package/dist/tengo/lib/file.internal.lib.tengo +77 -77
  18. package/dist/tengo/lib/file.lib.tengo +57 -57
  19. package/dist/tengo/lib/ll.lib.tengo +244 -244
  20. package/dist/tengo/lib/maps.lib.tengo +152 -152
  21. package/dist/tengo/lib/objects.lib.tengo +13 -13
  22. package/dist/tengo/lib/oop.lib.tengo +19 -19
  23. package/dist/tengo/lib/path.lib.tengo +125 -125
  24. package/dist/tengo/lib/pframes.constants.lib.tengo +28 -28
  25. package/dist/tengo/lib/pframes.export-pcolumn.lib.tengo +33 -33
  26. package/dist/tengo/lib/pframes.lib.tengo +43 -43
  27. package/dist/tengo/lib/pframes.ll.lib.tengo +72 -72
  28. package/dist/tengo/lib/pframes.pcolumn.lib.tengo +49 -49
  29. package/dist/tengo/lib/pframes.spec.lib.tengo +96 -96
  30. package/dist/tengo/lib/pframes.util.lib.tengo +288 -288
  31. package/dist/tengo/lib/pframes.xsv.lib.tengo +272 -272
  32. package/dist/tengo/lib/render.lib.tengo +75 -75
  33. package/dist/tengo/lib/sets.lib.tengo +68 -68
  34. package/dist/tengo/lib/slices.lib.tengo +258 -155
  35. package/dist/tengo/lib/smart.lib.tengo +1069 -1069
  36. package/dist/tengo/lib/test.lib.tengo +161 -161
  37. package/dist/tengo/lib/tpl.lib.tengo +515 -515
  38. package/dist/tengo/lib/tpl.state-await.lib.tengo +240 -240
  39. package/dist/tengo/lib/tpl.util.lib.tengo +9 -9
  40. package/dist/tengo/lib/validation.lib.tengo +378 -378
  41. package/dist/tengo/lib/workdir.lib.tengo +331 -331
  42. package/dist/tengo/lib/workdir.proc.lib.tengo +144 -144
  43. package/dist/tengo/lib/workdir.save.lib.tengo +130 -130
  44. package/dist/tengo/lib/workflow.bobject.lib.tengo +26 -26
  45. package/dist/tengo/lib/workflow.bquery.lib.tengo +165 -165
  46. package/dist/tengo/lib/workflow.constants.lib.tengo +2 -2
  47. package/dist/tengo/lib/workflow.context.lib.tengo +32 -32
  48. package/dist/tengo/lib/workflow.lib.tengo +206 -206
  49. package/dist/tengo/tpl/exec.R.create-renv.plj.gz +0 -0
  50. package/dist/tengo/tpl/exec.exec.plj.gz +0 -0
  51. package/dist/tengo/tpl/exec.monetization_to_json.plj.gz +0 -0
  52. package/dist/tengo/tpl/exec.python.create-venv.plj.gz +0 -0
  53. package/dist/tengo/tpl/exec.python.install-deps.plj.gz +0 -0
  54. package/dist/tengo/tpl/pframes.aggregate.plj.gz +0 -0
  55. package/dist/tengo/tpl/pframes.export-multiple-pcolumns.plj.gz +0 -0
  56. package/dist/tengo/tpl/pframes.export-pframe.plj.gz +0 -0
  57. package/dist/tengo/tpl/pframes.export-single-pcolumn.plj.gz +0 -0
  58. package/dist/tengo/tpl/pframes.import-dir.plj.gz +0 -0
  59. package/dist/tengo/tpl/pframes.map-pframe.plj.gz +0 -0
  60. package/dist/tengo/tpl/pframes.xsv-export-pframe.plj.gz +0 -0
  61. package/dist/tengo/tpl/pframes.xsv-import-map.plj.gz +0 -0
  62. package/dist/tengo/tpl/workdir.save.plj.gz +0 -0
  63. package/dist/tengo/tpl/workflow.build-ctx.plj.gz +0 -0
  64. package/package.json +2 -2
@@ -1,9 +1,9 @@
1
-
2
-
3
-
4
-
5
-
6
-
1
+ /**
2
+ * Internal 'exec' module library.
3
+ *
4
+ * NOT INTENDEND FOR USE OUTSIDE 'exec' MODULE.
5
+ * May completely change API from release to release.
6
+ */
7
7
 
8
8
  ll := import("@platforma-sdk/workflow-tengo:ll")
9
9
  json := import("json")
@@ -20,7 +20,7 @@ constants := import("@platforma-sdk/workflow-tengo:exec.constants")
20
20
  desc := import("@platforma-sdk/workflow-tengo:exec.descriptor")
21
21
  validation := import("@platforma-sdk/workflow-tengo:validation")
22
22
 
23
-
23
+ // Variables, substituted in command arguments and environment variable values.
24
24
  _ARG_VAR_PKG := "pkg" // abs path to software package
25
25
  _ARG_VAR_JAVA := "java" // abs path to 'java' run environment
26
26
  _ARG_VAR_PYTHON := "python" // abs path to 'python' run environment
@@ -28,388 +28,388 @@ _ARG_VAR_R := "R" // abs path to 'R' run environment runtime
28
28
  _ARG_VAR_R_VENV := "rVenv" // abs path to 'R' portable virtual environment
29
29
  _ARG_VAR_MNZ := "monetization" // monetization env value
30
30
 
31
-
31
+ /** Converts the args above to the expressions. */
32
32
  _expr := func(varName) {
33
- return "{" + varName + "}"
33
+ return "{" + varName + "}"
34
34
  }
35
35
 
36
36
  _newTypedArg := func(type, value) {
37
- return ll.toStrict({
38
- type: type,
39
- value: value
40
- })
41
- }
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
37
+ return ll.toStrict({
38
+ type: type,
39
+ value: value
40
+ })
41
+ }
42
+
43
+ /**
44
+ * Create new argument with a type. The type can be either string, expression or variable.
45
+ * Decides whether we need a simple argument or an expression one.
46
+ * Until 15 Mar 2025, we keep deprecated variable arguments.
47
+ *
48
+ * @param isString: boolean - whether it is a string or a difficult (expression) argument.
49
+ */
50
50
  _newArg := func(isString, value) {
51
- if isString {
52
- return _newTypedArg(constants.ARG_TYPE_STRING, value)
53
- }
54
- if desc.canBackendUseExpressions() {
55
- return _newTypedArg(constants.ARG_TYPE_EXPRESSION, value)
56
- }
57
- return _newTypedArg(constants.ARG_TYPE_VAR, value)
51
+ if isString {
52
+ return _newTypedArg(constants.ARG_TYPE_STRING, value)
53
+ }
54
+ if desc.canBackendUseExpressions() {
55
+ return _newTypedArg(constants.ARG_TYPE_EXPRESSION, value)
56
+ }
57
+ return _newTypedArg(constants.ARG_TYPE_VAR, value)
58
58
  }
59
59
 
60
60
  _newRefVar := func(varName, refName, reference) {
61
-
62
- if !desc.canBackendUseExpressions() {
63
- return ll.toStrict({
64
- varName: "{" + varName + "}",
65
- refName: refName,
66
- reference: reference
67
- })
68
- }
69
-
70
- return ll.toStrict({
71
- varName: varName,
72
- refName: refName,
73
- reference: reference
74
- })
61
+ // deprecated, remove on 15 Mar 2025
62
+ if !desc.canBackendUseExpressions() {
63
+ return ll.toStrict({
64
+ varName: "{" + varName + "}",
65
+ refName: refName,
66
+ reference: reference
67
+ })
68
+ }
69
+
70
+ return ll.toStrict({
71
+ varName: varName,
72
+ refName: refName,
73
+ reference: reference
74
+ })
75
75
  }
76
76
 
77
77
  _installSoftware := func(registry, pkgName) {
78
- ll.assert(is_string(registry), "exec.internal._installSoftware(): registry is not a string, got: %v", registry, pkgName)
79
- ll.assert(is_string(pkgName), "exec.internal._installSoftware(): pkgName is not a string, got: %v", pkgName, registry)
78
+ ll.assert(is_string(registry), "exec.internal._installSoftware(): registry is not a string, got: %v", registry, pkgName)
79
+ ll.assert(is_string(pkgName), "exec.internal._installSoftware(): pkgName is not a string, got: %v", pkgName, registry)
80
80
 
81
- archive := pkg.get(registry, pkgName).archive()
82
- return pkg.install(archive).package()
81
+ archive := pkg.get(registry, pkgName).archive()
82
+ return pkg.install(archive).package()
83
83
  }
84
84
 
85
85
  _directCallOptions := func(runOptions) {
86
- return ll.toStrict({
87
- variables: [],
88
- customPaths: [],
89
- cmd: _newArg(true, runOptions.cmd),
90
- args: [],
91
- envs: {}
92
- })
86
+ return ll.toStrict({
87
+ variables: [],
88
+ customPaths: [],
89
+ cmd: _newArg(true, runOptions.cmd),
90
+ args: [],
91
+ envs: {}
92
+ })
93
93
  }
94
94
 
95
95
  _loadJavaRunEnvironment := func(operationMode, descriptor) {
96
- javaPkg := _installSoftware(descriptor.runEnv.registry, descriptor.runEnv.package)
97
- javaRefVar := _newRefVar(_ARG_VAR_JAVA, descriptor.runEnv.name, javaPkg)
96
+ javaPkg := _installSoftware(descriptor.runEnv.registry, descriptor.runEnv.package)
97
+ javaRefVar := _newRefVar(_ARG_VAR_JAVA, descriptor.runEnv.name, javaPkg)
98
98
 
99
- return ll.toStrict({
100
- runEnvType: "java",
99
+ return ll.toStrict({
100
+ runEnvType: "java",
101
101
 
102
- variables: [ javaRefVar ],
103
- customPaths: [ _newArg(false, path.join(_expr(_ARG_VAR_JAVA), descriptor.runEnv.binDir)) ],
104
- envs: {}
105
- })
102
+ variables: [ javaRefVar ],
103
+ customPaths: [ _newArg(false, path.join(_expr(_ARG_VAR_JAVA), descriptor.runEnv.binDir)) ],
104
+ envs: {}
105
+ })
106
106
  }
107
107
 
108
108
  _loadPythonRunEnvironment := func(operationMode, descriptor, softName, softPkg) {
109
- venvBuilder := python.venvBuilder().
110
- software(softPkg).
111
- runEnvDescriptor(descriptor.runEnv).
112
- dependencies(descriptor.dependencies)
109
+ venvBuilder := python.venvBuilder().
110
+ software(softPkg).
111
+ runEnvDescriptor(descriptor.runEnv).
112
+ dependencies(descriptor.dependencies)
113
113
 
114
- if !is_undefined(descriptor.toolset) && descriptor.toolset != "" {
115
- venvBuilder.useToolset(descriptor.toolset)
116
- }
114
+ if !is_undefined(descriptor.toolset) && descriptor.toolset != "" {
115
+ venvBuilder.useToolset(descriptor.toolset)
116
+ }
117
117
 
118
- venv := venvBuilder.
119
- cacheDays(7).
120
- build().
121
- venv()
118
+ venv := venvBuilder.
119
+ cacheDays(7).
120
+ build().
121
+ venv()
122
122
 
123
- venvRoot := path.join(_expr(_ARG_VAR_PYTHON), "venv")
124
- venvRefKey := softName + "/venv"
123
+ venvRoot := path.join(_expr(_ARG_VAR_PYTHON), "venv")
124
+ venvRefKey := softName + "/venv"
125
125
 
126
- pythonRefVar := _newRefVar(_ARG_VAR_PYTHON, venvRefKey, venv)
126
+ pythonRefVar := _newRefVar(_ARG_VAR_PYTHON, venvRefKey, venv)
127
127
 
128
- return ll.toStrict({
129
- runEnvType: "python",
128
+ return ll.toStrict({
129
+ runEnvType: "python",
130
130
 
131
- variables: [ pythonRefVar ],
132
- customPaths: [ _newArg(false, path.join(venvRoot, "bin")) ],
133
- envs: {
134
- "VIRTUAL_ENV": _newArg(false, venvRoot)
135
- }
136
- })
131
+ variables: [ pythonRefVar ],
132
+ customPaths: [ _newArg(false, path.join(venvRoot, "bin")) ],
133
+ envs: {
134
+ "VIRTUAL_ENV": _newArg(false, venvRoot)
135
+ }
136
+ })
137
137
  }
138
138
 
139
139
  _loadRRunEnvironment := func(operationMode, descriptor, softName, softPkg) {
140
- renvBuilder := R.rVenvBuilder().
141
- operationMode(operationMode).
142
- software(softPkg).
143
- runEnvDescriptor(descriptor.runEnv).
144
- dependencies(descriptor.dependencies)
145
-
146
- if !is_undefined(descriptor.toolset) && descriptor.toolset != "" {
147
- renvBuilder.useToolset(descriptor.toolset)
148
- }
149
-
150
- rRuntime := renvBuilder.
151
- cacheDays(7).
152
- build()
140
+ renvBuilder := R.rVenvBuilder().
141
+ operationMode(operationMode).
142
+ software(softPkg).
143
+ runEnvDescriptor(descriptor.runEnv).
144
+ dependencies(descriptor.dependencies)
153
145
 
154
- rEnv := rRuntime.venv()
155
- rPackage := rRuntime.R()
146
+ if !is_undefined(descriptor.toolset) && descriptor.toolset != "" {
147
+ renvBuilder.useToolset(descriptor.toolset)
148
+ }
156
149
 
157
- rBinDir := path.join(_expr(_ARG_VAR_R), descriptor.runEnv.binDir)
150
+ rRuntime := renvBuilder.
151
+ cacheDays(7).
152
+ build()
158
153
 
159
- rRefKey := softName + "/R-runtime"
160
- rRefVar := _newRefVar(_ARG_VAR_R, rRefKey, rPackage)
154
+ rEnv := rRuntime.venv()
155
+ rPackage := rRuntime.R()
161
156
 
162
- rEnvRefKey := softName + "/R-virtual-env"
163
- rEnvRefVar := _newRefVar(_ARG_VAR_R_VENV, rEnvRefKey, rEnv)
157
+ rBinDir := path.join(_expr(_ARG_VAR_R), descriptor.runEnv.binDir)
164
158
 
165
- renvRootArg := path.join(_expr(_ARG_VAR_R), "renv-root")
159
+ rRefKey := softName + "/R-runtime"
160
+ rRefVar := _newRefVar(_ARG_VAR_R, rRefKey, rPackage)
166
161
 
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
- }
162
+ rEnvRefKey := softName + "/R-virtual-env"
163
+ rEnvRefVar := _newRefVar(_ARG_VAR_R_VENV, rEnvRefKey, rEnv)
177
164
 
178
- if (operationMode != "dev-local") {
165
+ renvRootArg := path.join(_expr(_ARG_VAR_R), "renv-root")
179
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
+ }
180
177
 
181
- envs["RENV_CONFIG_REPOS_OVERRIDE"] = _newArg(false, path.join(_expr(_ARG_VAR_R), "packages"))
182
- }
178
+ if (operationMode != "dev-local") {
179
+ // In production we can use only locally cached packages: most of commercials have
180
+ // Platforma Backend executed in a very restricted environment with limited access to the internet.
181
+ envs["RENV_CONFIG_REPOS_OVERRIDE"] = _newArg(false, path.join(_expr(_ARG_VAR_R), "packages"))
182
+ }
183
183
 
184
- return ll.toStrict({
185
- runEnvType: "R",
184
+ return ll.toStrict({
185
+ runEnvType: "R",
186
186
 
187
- variables: [ rRefVar, rEnvRefVar ],
188
- customPaths: [ _newArg(false, rBinDir) ],
189
- envs: envs
190
- })
187
+ variables: [ rRefVar, rEnvRefVar ],
188
+ customPaths: [ _newArg(false, rBinDir) ],
189
+ envs: envs
190
+ })
191
191
  }
192
192
 
193
193
 
194
194
  _loadRunEnvironment := func(operationMode, descriptor, softName, softPackage) {
195
- if descriptor.runEnv.type == "java" {
196
- return _loadJavaRunEnvironment(operationMode, descriptor)
197
- }
198
- if descriptor.runEnv.type == "python" {
199
- return _loadPythonRunEnvironment(operationMode, descriptor, softName, softPackage)
200
- }
201
- if descriptor.runEnv.type == "R" {
202
- return _loadRRunEnvironment(operationMode, descriptor, softName, softPackage)
203
- }
204
-
205
- ll.panic("run environment type %q is not currently supported by workflow-sdk", descriptor.runEnv.type)
206
- }
207
-
208
-
209
-
210
-
195
+ if descriptor.runEnv.type == "java" {
196
+ return _loadJavaRunEnvironment(operationMode, descriptor)
197
+ }
198
+ if descriptor.runEnv.type == "python" {
199
+ return _loadPythonRunEnvironment(operationMode, descriptor, softName, softPackage)
200
+ }
201
+ if descriptor.runEnv.type == "R" {
202
+ return _loadRRunEnvironment(operationMode, descriptor, softName, softPackage)
203
+ }
204
+
205
+ ll.panic("run environment type %q is not currently supported by workflow-sdk", descriptor.runEnv.type)
206
+ }
207
+
208
+ /**
209
+ * @param operationMode: "remote" | "dev-local"
210
+ */
211
211
  _binPackageCallOptions := func(operationMode, softwareName, variables, descriptor, softPackage) {
212
- customPaths := []
213
- envs := ll.toStrict({})
214
- args := []
215
- runEnvType := "binary"
216
-
217
-
218
-
219
- if (maps.containsKey(descriptor, "runEnv")) {
220
- runEnvInfo := _loadRunEnvironment(operationMode, descriptor, softwareName, softPackage)
221
-
222
- runEnvType = runEnvInfo.runEnvType
223
- if len(runEnvInfo.variables) > 0 {
224
- variables = append(variables, runEnvInfo.variables...)
225
- }
226
- if len(runEnvInfo.customPaths) > 0 {
227
- customPaths = append(customPaths, runEnvInfo.customPaths...)
228
- }
229
- if len(runEnvInfo.envs) > 0 {
230
- for n, v in runEnvInfo.envs {
231
- envs[n] = v
232
- }
233
- }
234
- }
235
-
236
- ll.assert(
237
- len(descriptor.cmd) != 0,
238
- "cannot render final command for software: empty 'cmd' and 'command' in software descriptor")
239
-
240
- cmd := _newArg(false, descriptor.cmd[0])
241
-
242
- for arg in splice(descriptor.cmd, 1) {
243
- args = append(args, _newArg(false, arg))
244
- }
245
-
246
- return ll.toStrict({
247
- runEnvType: runEnvType,
248
- variables: variables,
249
- customPaths: customPaths,
250
- cmd: cmd,
251
- args: args,
252
- envs: envs
253
- })
212
+ customPaths := []
213
+ envs := ll.toStrict({})
214
+ args := []
215
+ runEnvType := "binary"
216
+
217
+ // Real command should be:
218
+ // [<runEnv bin>] [<runEnv options>] [<entrypoint bin>] [<entrypoint options>] <cmd> <args>
219
+ if (maps.containsKey(descriptor, "runEnv")) {
220
+ runEnvInfo := _loadRunEnvironment(operationMode, descriptor, softwareName, softPackage)
221
+
222
+ runEnvType = runEnvInfo.runEnvType
223
+ if len(runEnvInfo.variables) > 0 {
224
+ variables = append(variables, runEnvInfo.variables...)
225
+ }
226
+ if len(runEnvInfo.customPaths) > 0 {
227
+ customPaths = append(customPaths, runEnvInfo.customPaths...)
228
+ }
229
+ if len(runEnvInfo.envs) > 0 {
230
+ for n, v in runEnvInfo.envs {
231
+ envs[n] = v
232
+ }
233
+ }
234
+ }
235
+
236
+ ll.assert(
237
+ len(descriptor.cmd) != 0,
238
+ "cannot render final command for software: empty 'cmd' and 'command' in software descriptor")
239
+
240
+ cmd := _newArg(false, descriptor.cmd[0])
241
+
242
+ for arg in splice(descriptor.cmd, 1) {
243
+ args = append(args, _newArg(false, arg))
244
+ }
245
+
246
+ return ll.toStrict({
247
+ runEnvType: runEnvType,
248
+ variables: variables,
249
+ customPaths: customPaths,
250
+ cmd: cmd,
251
+ args: args,
252
+ envs: envs
253
+ })
254
254
  }
255
255
 
256
256
  _devLocalPackageCallOptions := func(softwareName, localDescriptor) {
257
- softPackage := pkg.use({
258
- hash: localDescriptor.hash,
259
- path: localDescriptor.path,
260
- descriptor: json.encode(ll.fromStrict(localDescriptor)),
261
- origin: {
262
- registry: "dev-local",
263
- url: "file://" + localDescriptor.path,
264
- packageName: softwareName
265
- }
266
- }).package()
257
+ softPackage := pkg.use({
258
+ hash: localDescriptor.hash,
259
+ path: localDescriptor.path,
260
+ descriptor: json.encode(ll.fromStrict(localDescriptor)),
261
+ origin: {
262
+ registry: "dev-local",
263
+ url: "file://" + localDescriptor.path,
264
+ packageName: softwareName
265
+ }
266
+ }).package()
267
267
 
268
- variables := [ _newRefVar(_ARG_VAR_PKG, softwareName, softPackage) ]
268
+ variables := [ _newRefVar(_ARG_VAR_PKG, softwareName, softPackage) ]
269
269
 
270
- return _binPackageCallOptions("dev-local", softwareName, variables, localDescriptor, softPackage)
270
+ return _binPackageCallOptions("dev-local", softwareName, variables, localDescriptor, softPackage)
271
271
  }
272
272
 
273
273
  _remotePackageCallOptions := func(softwareName, binaryDescriptor) {
274
- softPackage := _installSoftware(binaryDescriptor.registry, binaryDescriptor.package)
274
+ softPackage := _installSoftware(binaryDescriptor.registry, binaryDescriptor.package)
275
275
 
276
- variables := [ _newRefVar(_ARG_VAR_PKG, softwareName, softPackage) ]
276
+ variables := [ _newRefVar(_ARG_VAR_PKG, softwareName, softPackage) ]
277
277
 
278
- return _binPackageCallOptions("remote", softwareName, variables, binaryDescriptor, softPackage)
278
+ return _binPackageCallOptions("remote", softwareName, variables, binaryDescriptor, softPackage)
279
279
  }
280
280
 
281
-
282
-
283
-
284
-
281
+ /** Turns a given software to a list of options that needs to be passed to run cmd builder.
282
+ * Creates resources to install a software
283
+ * and runs R or Python env builder templates
284
+ * if it's necessary. */
285
285
  swToRunCmdOptions := func(softwareName, softwareVersion, softwareDescriptor) {
286
- ll.assert(is_string(softwareName),
287
- "exec.internal.swToRunCmdOptions: software name must be a string, got %v", softwareName)
288
- ll.assert(is_string(softwareVersion),
289
- "exec.internal.swToRunCmdOptions: software version must be a string, got %v", softwareVersion)
290
- validation.assertJsonSchema(softwareDescriptor, desc.scheme,
291
- "exec.internal.swToRunCmdOptions: descriptor does not fit schema")
292
-
293
- result := undefined
294
- if maps.containsKey(softwareDescriptor, "local") {
295
- result = _devLocalPackageCallOptions(softwareName, softwareDescriptor.local)
296
- } else if maps.containsKey(softwareDescriptor, "binary") {
297
- result = _remotePackageCallOptions(softwareName, softwareDescriptor.binary)
298
- } else {
299
- ll.panic(
300
- "Unable to run software %s v%s: 'binary' execution mode is not enabled in software descriptor",
301
- softwareName, softwareVersion)
302
- }
303
-
304
-
305
-
306
- return ll.toStrict({
307
- runEnvType: result.runEnvType,
308
- variables: result.variables,
309
- customPaths: result.customPaths,
310
- cmd: result.cmd,
311
- args: result.args,
312
- envs: result.envs
313
- })
286
+ ll.assert(is_string(softwareName),
287
+ "exec.internal.swToRunCmdOptions: software name must be a string, got %v", softwareName)
288
+ ll.assert(is_string(softwareVersion),
289
+ "exec.internal.swToRunCmdOptions: software version must be a string, got %v", softwareVersion)
290
+ validation.assertJsonSchema(softwareDescriptor, desc.scheme,
291
+ "exec.internal.swToRunCmdOptions: descriptor does not fit schema")
292
+
293
+ result := undefined
294
+ if maps.containsKey(softwareDescriptor, "local") {
295
+ result = _devLocalPackageCallOptions(softwareName, softwareDescriptor.local)
296
+ } else if maps.containsKey(softwareDescriptor, "binary") {
297
+ result = _remotePackageCallOptions(softwareName, softwareDescriptor.binary)
298
+ } else {
299
+ ll.panic(
300
+ "Unable to run software %s v%s: 'binary' execution mode is not enabled in software descriptor",
301
+ softwareName, softwareVersion)
302
+ }
303
+
304
+ // Clone result fields explicitly here
305
+ // just to have a gist of what the function returns.
306
+ return ll.toStrict({
307
+ runEnvType: result.runEnvType,
308
+ variables: result.variables,
309
+ customPaths: result.customPaths,
310
+ cmd: result.cmd,
311
+ args: result.args,
312
+ envs: result.envs
313
+ })
314
314
  }
315
315
 
316
316
  binaryRunOptions := func(runOptions, mnzEnvs) {
317
- validation.assertJsonSchema(mnzEnvs, {"any": validation.reference})
318
-
319
- runCmdOpts := undefined
320
- if (is_undefined(ll.fromStrict(runOptions).software)) {
317
+ validation.assertJsonSchema(mnzEnvs, {"any": validation.reference})
321
318
 
319
+ runCmdOpts := undefined
320
+ if (is_undefined(ll.fromStrict(runOptions).software)) {
321
+ //
322
+ // Simple local command run, no software packages involved (backward compatibility)
323
+ //
324
+ runCmdOpts = _directCallOptions(runOptions)
325
+ } else {
326
+ software := runOptions.software
327
+ descriptor := software.descriptor
322
328
 
329
+ runCmdOpts = swToRunCmdOptions(software.name, software.version, descriptor)
330
+ }
323
331
 
324
- runCmdOpts = _directCallOptions(runOptions)
325
- } else {
326
- software := runOptions.software
327
- descriptor := software.descriptor
332
+ // adds exec builder's defined options from run options.
333
+ // If argsTyped or envsTyped are set (which is a new API from exec.builder),
334
+ // then pass them directly.
335
+ // Otherwise, pass args and envs the old way, without possible expression evaluating.
336
+ opts := ll.fromStrict(runOptions)
337
+ shouldUseNewTyped := !is_undefined(opts.argsTyped) || !is_undefined(opts.envsTyped)
328
338
 
329
- runCmdOpts = swToRunCmdOptions(software.name, software.version, descriptor)
330
- }
331
-
332
-
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)
343
- }
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
349
- }
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)
343
+ }
350
344
 
351
- for name, val in mnzEnvs { // can be empty
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
349
+ }
352
350
 
351
+ for name, val in mnzEnvs { // can be empty
352
+ // if it's not empty, then we create an env that has
353
+ // a result of monetization client.
354
+ runCmdOpts.envs[name] = _newArg(false, _expr(_ARG_VAR_MNZ))
353
355
 
354
- runCmdOpts.envs[name] = _newArg(false, _expr(_ARG_VAR_MNZ))
355
-
356
- runCmdOpts.variables = append(runCmdOpts.variables,
357
- _newRefVar(_ARG_VAR_MNZ, "monetization", val))
358
- }
356
+ runCmdOpts.variables = append(runCmdOpts.variables,
357
+ _newRefVar(_ARG_VAR_MNZ, "monetization", val))
358
+ }
359
359
 
360
360
 
361
- return oop.inherit(runOptions, ll.fromStrict(runCmdOpts))
361
+ return oop.inherit(runOptions, ll.fromStrict(runCmdOpts))
362
362
  }
363
363
 
364
364
  prepareCommandRun := func(wd, opts) {
365
- runBuilder := runcmd.builder(wd)
366
-
367
-
368
- for varInfo in opts.variables {
369
- runBuilder.ref(varInfo.refName, varInfo.reference)
370
- runBuilder.substitutionRule(varInfo.varName, varInfo.refName)
371
- }
365
+ runBuilder := runcmd.builder(wd)
372
366
 
367
+ // Make installed packages to be available for the command run
368
+ for varInfo in opts.variables {
369
+ runBuilder.ref(varInfo.refName, varInfo.reference)
370
+ runBuilder.substitutionRule(varInfo.varName, varInfo.refName)
371
+ }
373
372
 
374
- for p in opts.customPaths {
375
- runBuilder.addToPath(p.type, p.value)
376
- }
377
-
373
+ // Patch command's PATH env variable
374
+ for p in opts.customPaths {
375
+ runBuilder.addToPath(p.type, p.value)
376
+ }
378
377
 
379
- for name, value in opts.envs {
380
- runBuilder.envTyped(name, value.type, value.value)
381
- }
378
+ // Configure environment variables required for correct command run environment setup
379
+ for name, value in opts.envs {
380
+ runBuilder.envTyped(name, value.type, value.value)
381
+ }
382
382
 
383
- return runBuilder
383
+ return runBuilder
384
384
  }
385
385
 
386
386
  _activateRenv := func(wd, opts) {
387
- activateRenv := prepareCommandRun(wd, opts)
388
- activateRenv.
389
- cmd("R").
390
- arg("-e").arg("renv::activate()")
387
+ activateRenv := prepareCommandRun(wd, opts)
388
+ activateRenv.
389
+ cmd("R").
390
+ arg("-e").arg("renv::activate()")
391
391
 
392
- activateRenvRun := activateRenv.build()
392
+ activateRenvRun := activateRenv.build()
393
393
 
394
- return activateRenvRun
394
+ return activateRenvRun
395
395
  }
396
396
 
397
397
  prepareWDForRunEnvironment := func(wd, opts) {
398
- if (!maps.containsKey(opts, "runEnvType")) {
399
- return wd
400
- }
398
+ if (!maps.containsKey(opts, "runEnvType")) {
399
+ return wd
400
+ }
401
401
 
402
- if (opts.runEnvType == "R") {
403
- return _activateRenv(wd, opts).workdir
404
- }
402
+ if (opts.runEnvType == "R") {
403
+ return _activateRenv(wd, opts).workdir
404
+ }
405
405
 
406
- return wd
406
+ return wd
407
407
  }
408
408
 
409
409
  export {
410
- swToRunCmdOptions : swToRunCmdOptions,
411
- binaryRunOptions : binaryRunOptions,
410
+ swToRunCmdOptions : swToRunCmdOptions,
411
+ binaryRunOptions : binaryRunOptions,
412
412
 
413
- prepareWDForRunEnvironment : prepareWDForRunEnvironment,
414
- prepareCommandRun : prepareCommandRun
413
+ prepareWDForRunEnvironment : prepareWDForRunEnvironment,
414
+ prepareCommandRun : prepareCommandRun
415
415
  }