@platforma-sdk/workflow-tengo 1.4.2 → 1.6.0

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
2
- declare type TplName = "pframes.aggregate" | "pframes.export-single-pcolumn" | "pframes.import-dir" | "pframes.map-pframe" | "workdir.save" | "workflow.build-ctx" | "exec.create-python-venv" | "exec.exec" | "pframes.export-multiple-pcolumns" | "pframes.export-pframe" | "pframes.import-xsv-map";
2
+ declare type TplName = "pframes.aggregate" | "pframes.export-single-pcolumn" | "pframes.import-dir" | "pframes.map-pframe" | "workdir.save" | "workflow.build-ctx" | "exec.python.install-deps" | "pframes.export-multiple-pcolumns" | "pframes.export-pframe" | "exec.python.create-venv" | "exec.exec" | "pframes.import-xsv-map";
3
3
  declare const Templates: Record<TplName, TemplateFromFile>;
4
4
  export { Templates };
package/dist/index.js CHANGED
@@ -5,9 +5,10 @@ module.exports = { Templates: {
5
5
  'pframes.map-pframe': { type: 'from-file', path: require.resolve('./tengo/tpl/pframes.map-pframe.plj.gz') },
6
6
  'workdir.save': { type: 'from-file', path: require.resolve('./tengo/tpl/workdir.save.plj.gz') },
7
7
  'workflow.build-ctx': { type: 'from-file', path: require.resolve('./tengo/tpl/workflow.build-ctx.plj.gz') },
8
- 'exec.create-python-venv': { type: 'from-file', path: require.resolve('./tengo/tpl/exec.create-python-venv.plj.gz') },
9
- 'exec.exec': { type: 'from-file', path: require.resolve('./tengo/tpl/exec.exec.plj.gz') },
8
+ 'exec.python.install-deps': { type: 'from-file', path: require.resolve('./tengo/tpl/exec.python.install-deps.plj.gz') },
10
9
  'pframes.export-multiple-pcolumns': { type: 'from-file', path: require.resolve('./tengo/tpl/pframes.export-multiple-pcolumns.plj.gz') },
11
10
  'pframes.export-pframe': { type: 'from-file', path: require.resolve('./tengo/tpl/pframes.export-pframe.plj.gz') },
11
+ 'exec.python.create-venv': { type: 'from-file', path: require.resolve('./tengo/tpl/exec.python.create-venv.plj.gz') },
12
+ 'exec.exec': { type: 'from-file', path: require.resolve('./tengo/tpl/exec.exec.plj.gz') },
12
13
  'pframes.import-xsv-map': { type: 'from-file', path: require.resolve('./tengo/tpl/pframes.import-xsv-map.plj.gz') }
13
14
  }};
package/dist/index.mjs CHANGED
@@ -6,9 +6,10 @@ export const Templates = {
6
6
  'pframes.map-pframe': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/pframes.map-pframe.plj.gz') },
7
7
  'workdir.save': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/workdir.save.plj.gz') },
8
8
  'workflow.build-ctx': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/workflow.build-ctx.plj.gz') },
9
- 'exec.create-python-venv': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/exec.create-python-venv.plj.gz') },
10
- 'exec.exec': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/exec.exec.plj.gz') },
9
+ 'exec.python.install-deps': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/exec.python.install-deps.plj.gz') },
11
10
  'pframes.export-multiple-pcolumns': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/pframes.export-multiple-pcolumns.plj.gz') },
12
11
  'pframes.export-pframe': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/pframes.export-pframe.plj.gz') },
12
+ 'exec.python.create-venv': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/exec.python.create-venv.plj.gz') },
13
+ 'exec.exec': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/exec.exec.plj.gz') },
13
14
  'pframes.import-xsv-map': { type: 'from-file', path: resolve(import.meta.dirname, './tengo/tpl/pframes.import-xsv-map.plj.gz') }
14
15
  };
@@ -1,5 +1,13 @@
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
+
1
8
  ll := import("@platforma-sdk/workflow-tengo:ll")
2
9
  json := import("json")
10
+ times := import("times")
3
11
  text := import("text")
4
12
  oop := import("@platforma-sdk/workflow-tengo:oop")
5
13
  maps := import("@platforma-sdk/workflow-tengo:maps")
@@ -80,7 +88,10 @@ _loadPythonRunEnvironment := func(descriptor, softName, softPkg) {
80
88
  venvBuilder.useToolset(descriptor.toolset)
81
89
  }
82
90
 
83
- venv := venvBuilder.build().venv()
91
+ venv := venvBuilder.
92
+ cache(7 * 24 * times.hour).
93
+ build().
94
+ venv()
84
95
 
85
96
  venvRoot := path.join(_ARG_VAR_PYTHON, "venv")
86
97
  venvRefKey := softName + "/venv"
@@ -104,7 +115,7 @@ _loadRunEnvironment := func(descriptor, softName, softPackage) {
104
115
  return _loadPythonRunEnvironment(descriptor, softName, softPackage)
105
116
  }
106
117
 
107
- ll.panic("run environment type %q is not currently supported by tengo-sdk", descriptor.runEnv.type)
118
+ ll.panic("run environment type %q is not currently supported by workflow-sdk", descriptor.runEnv.type)
108
119
  }
109
120
 
110
121
  _binPackageCallOptions := func(runOptions, variables, descriptor, softPackage) {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * A builder for executing commands.
3
3
  */
4
+
4
5
  ll := import("@platforma-sdk/workflow-tengo:ll")
5
6
  assets := import("@platforma-sdk/workflow-tengo:assets")
6
7
  smart := import("@platforma-sdk/workflow-tengo:smart")
@@ -186,7 +187,7 @@ builder := func() {
186
187
  ll.assert(
187
188
  is_int(time),
188
189
  "cache time must be an integer. " +
189
- "Did you forget to import a standard tengo library 'time'?")
190
+ "Did you forget to import a standard tengo library 'times'?")
190
191
  cache = time
191
192
  return self
192
193
  },
@@ -1,3 +1,7 @@
1
+ /**
2
+ * A library for working with platforma packages
3
+ */
4
+
1
5
  ll := import("@platforma-sdk/workflow-tengo:ll")
2
6
  smart := import("@platforma-sdk/workflow-tengo:smart")
3
7
  workdir := import("@platforma-sdk/workflow-tengo:workdir")
@@ -1,4 +1,6 @@
1
- /** A library that creates RunCommand resource. */
1
+ /**
2
+ * A library that creates RunCommand resource.
3
+ */
2
4
 
3
5
  ll := import("@platforma-sdk/workflow-tengo:ll")
4
6
  maps := import("@platforma-sdk/workflow-tengo:maps")
@@ -1,3 +1,7 @@
1
+ /**
2
+ * A library for run environments creation and bootstrapping.
3
+ */
4
+
1
5
  ll := import("@platforma-sdk/workflow-tengo:ll")
2
6
  smart := import("@platforma-sdk/workflow-tengo:smart")
3
7
  oop := import("@platforma-sdk/workflow-tengo:oop")
@@ -171,7 +175,7 @@ pythonVenv := func() {
171
175
  ll.assert(
172
176
  is_int(time),
173
177
  "cache time must be an integer. " +
174
- "Did you forget to import a standard tengo library 'time'?")
178
+ "Did you forget to import a standard tengo library 'times'?")
175
179
  cache = time
176
180
  return self
177
181
  },
@@ -192,7 +196,7 @@ pythonVenv := func() {
192
196
 
193
197
  validation.assertJsonSchema(pyVenvInputs, pythonVenvInputSchema, "incomplete python runenv configuration")
194
198
 
195
- tpl := render.create(assets.importTemplate("@platforma-sdk/workflow-tengo:exec.create-python-venv"), pyVenvInputs)
199
+ tpl := render.create(assets.importTemplate("@platforma-sdk/workflow-tengo:exec.python.create-venv"), pyVenvInputs)
196
200
 
197
201
  self := undefined
198
202
  self = ll.toStrict(oop.inherit(tpl, {
@@ -159,10 +159,11 @@ purifySpec := func(spec) {
159
159
 
160
160
  newAxes := []
161
161
  for ax in spec.axes {
162
- newAxes = append(newAxes, {
162
+ newAxes = append(newAxes, objects.deleteUndefined({
163
163
  column: ax.column,
164
+ preProcess: ax.preProcess,
164
165
  spec: { type: ax.spec.type }
165
- })
166
+ }))
166
167
  }
167
168
  newSpec.axes = newAxes
168
169
 
@@ -170,6 +171,7 @@ purifySpec := func(spec) {
170
171
  for col in spec.columns {
171
172
  newCols = append(newCols, objects.deleteUndefined({
172
173
  column: col.column,
174
+ preProcess: col.preProcess,
173
175
  id: col.id,
174
176
  allowNA: col.allowNA,
175
177
  spec: { valueType: col.spec.valueType }
@@ -12,6 +12,7 @@ util := import("@platforma-sdk/workflow-tengo:pframes.util")
12
12
  ll := import("@platforma-sdk/workflow-tengo:ll")
13
13
  assets := import("@platforma-sdk/workflow-tengo:assets")
14
14
 
15
+ transposeXsvSw := assets.importSoftware("@milaboratories/software-small-binaries:table-converter")
15
16
  pfconvSw := assets.importSoftware("@milaboratories/software-pframes-conv:main")
16
17
 
17
18
  /**
@@ -60,7 +61,22 @@ getColumnSpec := func(axesSpec, col) {
60
61
  * @param xsvFile: reference - a reference to a file
61
62
  * @param xsvType: string - either csv or tsv
62
63
  * @param spec: object - xsv conversion specification
63
- * @param ops: dict - additional params (internal)
64
+ * @param ops: object - additional options
65
+ * {
66
+ * dataOnly: boolean - set to true to completely skip creation of specs
67
+ * transpose: object - if specified, then the input table will be transposed
68
+ * {
69
+ * separator: string - (optional) use separator instead of inferring from the file extension
70
+ * pAxisIdx: index - (optional) the index of the primary axis (column in the input xsv); default 0
71
+ * pAxisName: string - (optional) the name of the primary axis (column name in the input xsv); default undefined
72
+ * pAxisSearch: regex - (optional) the regex pattern of the name of the primary axis (column name in the input xsv); default undefined
73
+ * pAxisNameOverride: string - (optional) override primary axis header in the output; default undefined
74
+ * sAxisSearch: string - (optional) regex to filter secondary axis columns in the input table;
75
+ * sAxisName: string - (optional) the name of the secondary axis (column name in the output xsv); default "Metric"
76
+ * valueName: string - (optional) the name of the value column; default "Value"
77
+ * separatorOverride: string - (optional) specify separator in the output (optional)
78
+ * }
79
+ * }
64
80
  * @return map: reference - a reference to a map resource storing imported data.
65
81
  */
66
82
  importFile := func(xsvFile, xsvType, spec, ...ops) {
@@ -70,6 +86,58 @@ importFile := func(xsvFile, xsvType, spec, ...ops) {
70
86
 
71
87
  xsvFileName := "file." + xsvType
72
88
 
89
+ ops := renderOps({ dataOnly: false }, ops...)
90
+
91
+ if ops.transpose != undefined {
92
+
93
+ tops := ops.transpose
94
+
95
+ transposedFileName := "fileTransposed." + xsvType
96
+
97
+ // convert csv to p-frame and read resulting data
98
+ transposeXsv := exec.builder().
99
+ software(transposeXsvSw).
100
+ printErrStreamToStdout().
101
+ inLightQueue()
102
+
103
+ if (tops.separator != undefined) {
104
+ transposeXsv = transposeXsv.arg("-input-separator").arg(tops.separator)
105
+ }
106
+ if (tops.pAxisIdx != undefined) {
107
+ transposeXsv = transposeXsv.arg("-sample-column-i").arg("" + tops.pAxisIdx) // always convert to string
108
+ }
109
+ if (tops.pAxisName != undefined) {
110
+ transposeXsv = transposeXsv.arg("-sample-column-name").arg(tops.pAxisName)
111
+ }
112
+ if (tops.pAxisSearch != undefined) {
113
+ transposeXsv = transposeXsv.arg("-sample-column-search").arg(tops.pAxisSearch)
114
+ }
115
+ if (tops.pAxisNameOverride != undefined) {
116
+ transposeXsv = transposeXsv.arg("-sample-label").arg(tops.pAxisNameOverride)
117
+ }
118
+ if (tops.sAxisSearch != undefined) {
119
+ transposeXsv = transposeXsv.arg("-metric-columns-search").arg(tops.sAxisSearch)
120
+ }
121
+ if (tops.sAxisName != undefined) {
122
+ transposeXsv = transposeXsv.arg("-metric-label").arg(tops.sAxisName)
123
+ }
124
+ if (tops.valueName != undefined) {
125
+ transposeXsv = transposeXsv.arg("-value-label").arg(tops.valueName)
126
+ }
127
+ if (tops.separatorOverride != undefined) {
128
+ transposeXsv = transposeXsv.arg("-separator").arg(tops.separatorOverride)
129
+ }
130
+
131
+ transposeXsv = transposeXsv.
132
+ arg(xsvFileName).
133
+ arg(transposedFileName).
134
+ addFile(xsvFileName, xsvFile).
135
+ saveFile(transposedFileName).
136
+ run()
137
+
138
+ xsvFile = transposeXsv.getFile(transposedFileName)
139
+ }
140
+
73
141
  // import p-frame from directory tpl
74
142
  importDirTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:pframes.import-dir")
75
143
 
@@ -90,8 +158,6 @@ importFile := func(xsvFile, xsvType, spec, ...ops) {
90
158
  processWorkdir("pf", importDirTpl, pureSpec).
91
159
  run()
92
160
 
93
- ops := renderOps({ dataOnly: false }, ops...)
94
-
95
161
  // p-columns data
96
162
  pf := pfconv.getProcessorResult("pf")
97
163
  if ops.dataOnly {
@@ -125,6 +191,18 @@ importFile := func(xsvFile, xsvType, spec, ...ops) {
125
191
  * with "spec" + "data" fields in nested maps
126
192
  * additionalAxesSpec: AxisSpec[] - array of additional axes spec to prepend to
127
193
  * each column spec
194
+ * transpose: object - if specified, then the input table will be transposed
195
+ * {
196
+ * separator: string - (optional) use separator instead of inferring from the file extension
197
+ * pAxisIdx: index - (optional) the index of the primary axis (column in the input xsv); default 0
198
+ * pAxisName: string - (optional) the name of the primary axis (column name in the input xsv); default undefined
199
+ * pAxisSearch: regex - (optional) the regex pattern of the name of the primary axis (column name in the input xsv); default undefined
200
+ * pAxisNameOverride: string - (optional) override primary axis header in the output; default undefined
201
+ * sAxisSearch: string - (optional) regex to filter secondary axis columns in the input table;
202
+ * sAxisName: string - (optional) the name of the secondary axis (column name in the output xsv); default "Metric"
203
+ * valueName: string - (optional) the name of the value column; default "Value"
204
+ * separatorOverride: string - (optional) specify separator in the output (optional)
205
+ * }
128
206
  * }
129
207
  * @return map: reference - a reference to a map resource storing imported data.
130
208
  */
@@ -135,7 +213,8 @@ importFileMap := func(xsvMap, xsvType, spec, ...ops) {
135
213
  ops := renderOps({
136
214
  dataOnly: false,
137
215
  splitDataAndSpec: false,
138
- additionalAxesSpec: []
216
+ additionalAxesSpec: [],
217
+ transpose: undefined
139
218
  }, ops...)
140
219
 
141
220
  // spec without any metadata (for caching purposes)
@@ -147,7 +226,7 @@ importFileMap := func(xsvMap, xsvType, spec, ...ops) {
147
226
  xsvMap: xsvMap,
148
227
  xsvType: xsvType,
149
228
  spec: pureSpec,
150
- ops: { dataOnly: true }
229
+ ops: { dataOnly: true, transpose: ops.transpose }
151
230
  })
152
231
 
153
232
  if ops.dataOnly && ops.splitDataAndSpec {
@@ -170,7 +249,7 @@ importFileMap := func(xsvMap, xsvType, spec, ...ops) {
170
249
  result[id + ".spec"] = columnsSpec[id]
171
250
  }
172
251
  }
173
-
252
+
174
253
  return result
175
254
  }
176
255
 
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/workflow-tengo",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "description": "Tengo SDK library",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,8 @@
16
16
  "./dist/**/*"
17
17
  ],
18
18
  "dependencies": {
19
- "@milaboratories/software-pframes-conv": "^1.5.10"
19
+ "@milaboratories/software-pframes-conv": "^1.6.0",
20
+ "@milaboratories/software-small-binaries": "^1.11.2"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@platforma-sdk/tengo-builder": "^1.14.13"