Skip to content

Commit

Permalink
refactor: pass pipeline name for runner execution (#946)
Browse files Browse the repository at this point in the history
- pipeline name is now passed to execution to allow execution of
multiple pipelines
  • Loading branch information
WinPlay02 authored Mar 7, 2024
1 parent c25d147 commit f8b7064
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
18 changes: 6 additions & 12 deletions packages/safe-ds-lang/src/language/runner/safe-ds-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { BasicSourceMapConsumer, SourceMapConsumer } from 'source-map';
import treeKill from 'tree-kill';
import { SafeDsAnnotations } from '../builtins/safe-ds-annotations.js';
import { SafeDsPythonGenerator } from '../generation/safe-ds-python-generator.js';
import { isSdsModule, isSdsPipeline } from '../generated/ast.js';
import { getModuleMembers } from '../helpers/nodeProperties.js';
import { isSdsModule } from '../generated/ast.js';
import semver from 'semver';

// Most of the functionality cannot be tested automatically as a functioning runner setup would always be required
Expand Down Expand Up @@ -281,13 +280,15 @@ export class SafeDsRunner {
* Execute a Safe-DS pipeline on the python runner.
* If a valid target placeholder is provided, the pipeline is only executed partially, to calculate the result of the placeholder.
*
* @param pipelineDocument Document containing the main Safe-DS pipeline to execute.
* @param id A unique id that is used in further communication with this pipeline.
* @param pipelineDocument Document containing the main Safe-DS pipeline to execute.
* @param pipelineName Name of the pipeline that should be run
* @param targetPlaceholder The name of the target placeholder, used to do partial execution. If no value or undefined is provided, the entire pipeline is run.
*/
public async executePipeline(
pipelineDocument: LangiumDocument,
id: string,
pipelineDocument: LangiumDocument,
pipelineName: string,
targetPlaceholder: string | undefined = undefined,
) {
if (!this.isPythonServerAvailable()) {
Expand All @@ -305,13 +306,6 @@ export class SafeDsRunner {
// Pipeline / Module name handling
const mainPythonModuleName = this.annotations.getPythonModule(node);
const mainPackage = mainPythonModuleName === undefined ? node.name.split('.') : [mainPythonModuleName];
const firstPipeline = getModuleMembers(node).find(isSdsPipeline);
if (firstPipeline === undefined) {
this.logging.outputError('Cannot execute: no pipeline found');
this.logging.displayError('The current file cannot be executed, as no pipeline could be found.');
return;
}
const mainPipelineName = this.annotations.getPythonName(firstPipeline) || firstPipeline.name;
const mainModuleName = this.getMainModuleName(pipelineDocument);
// Code generation
const [codeMap, lastGeneratedSources] = this.generateCodeForRunner(pipelineDocument, targetPlaceholder);
Expand All @@ -330,7 +324,7 @@ export class SafeDsRunner {
main: {
modulepath: mainPackage.join('.'),
module: mainModuleName,
pipeline: mainPipelineName,
pipeline: pipelineName,
},
}),
);
Expand Down
17 changes: 13 additions & 4 deletions packages/safe-ds-vscode/src/extension/mainClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'node:path';
import * as vscode from 'vscode';
import type { LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node.js';
import { LanguageClient, TransportKind } from 'vscode-languageclient/node.js';
import { ast, createSafeDsServices, messages, SafeDsServices } from '@safe-ds/lang';
import { ast, createSafeDsServices, getModuleMembers, messages, SafeDsServices } from '@safe-ds/lang';
import { NodeFileSystem } from 'langium/node';
import { getSafeDSOutputChannel, initializeLog, logError, logOutput, printOutputMessage } from './output.js';
import crypto from 'crypto';
Expand Down Expand Up @@ -335,8 +335,6 @@ const runPipelineFile = async function (filePath: vscode.Uri | undefined, pipeli
return;
}
// Run it
printOutputMessage(`Launching Pipeline (${pipelineId}): ${pipelinePath}`);

let mainDocument;
if (!services.shared.workspace.LangiumDocuments.hasDocument(pipelinePath)) {
mainDocument = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(pipelinePath);
Expand All @@ -348,7 +346,18 @@ const runPipelineFile = async function (filePath: vscode.Uri | undefined, pipeli
} else {
mainDocument = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(pipelinePath);
}
await services.runtime.Runner.executePipeline(mainDocument, pipelineId);

const firstPipeline = getModuleMembers(<ast.SdsModule>mainDocument.parseResult.value).find(ast.isSdsPipeline);
if (firstPipeline === undefined) {
logError('Cannot execute: no pipeline found');
vscode.window.showErrorMessage('The current file cannot be executed, as no pipeline could be found.');
return;
}
const mainPipelineName = services.builtins.Annotations.getPythonName(firstPipeline) || firstPipeline.name;

printOutputMessage(`Launching Pipeline (${pipelineId}): ${pipelinePath} - ${mainPipelineName}`);

await services.runtime.Runner.executePipeline(pipelineId, mainDocument, mainPipelineName);
};

const commandRunPipelineFile = async function (filePath: vscode.Uri | undefined) {
Expand Down

0 comments on commit f8b7064

Please sign in to comment.