Skip to content

Commit

Permalink
fix: use correct paths and module names to correctly execute Safe-DS …
Browse files Browse the repository at this point in the history
…files with spaces (#811)

Closes #810

### Summary of Changes

- fix: use correct paths and module names to correctly execute Safe-DS
files that contain spaces and fix access to source mappings for these
files

---------

Co-authored-by: megalinter-bot <[email protected]>
  • Loading branch information
WinPlay02 and megalinter-bot authored Dec 19, 2023
1 parent c9575e7 commit 191ef33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ export class SafeDsPythonGenerator {
}

private formatGeneratedFileName(baseName: string): string {
return `gen_${baseName.replaceAll('%2520', '_').replaceAll(/[ .-]/gu, '_').replaceAll(/\\W/gu, '')}`;
return `gen_${this.sanitizeModuleNameForPython(baseName)}`;
}

sanitizeModuleNameForPython(moduleName: string): string {
return moduleName.replaceAll('%2520', '_').replaceAll(/[ .-]/gu, '_').replaceAll(/\\W/gu, '');
}

private generateModule(module: SdsModule): CompositeGeneratorNode {
Expand Down
28 changes: 19 additions & 9 deletions packages/safe-ds-vscode/src/extension/pythonServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,15 @@ export const executePipeline = async function (services: SafeDsServices, pipelin
}
mainPipelineName = services.builtins.Annotations.getPythonName(firstPipeline) || firstPipeline.name;
if (pipelinePath.endsWith('.sdspipe')) {
mainModuleName = path.basename(pipelinePath, '.sdspipe').replaceAll('-', '_');
mainModuleName = services.generation.PythonGenerator.sanitizeModuleNameForPython(
path.basename(pipelinePath, '.sdspipe'),
);
} else if (pipelinePath.endsWith('.sdstest')) {
mainModuleName = path.basename(pipelinePath, '.sdstest').replaceAll('-', '_');
mainModuleName = services.generation.PythonGenerator.sanitizeModuleNameForPython(
path.basename(pipelinePath, '.sdstest'),
);
} else {
mainModuleName = path.basename(pipelinePath).replaceAll('-', '_');
mainModuleName = services.generation.PythonGenerator.sanitizeModuleNameForPython(path.basename(pipelinePath));
}
//
const generatedDocuments = services.generation.PythonGenerator.generate(document, {
Expand All @@ -297,17 +301,23 @@ export const executePipeline = async function (services: SafeDsServices, pipelin
let codeMap: ProgramCodeMap = {};
for (const generatedDocument of generatedDocuments) {
const fsPath = URI.parse(generatedDocument.uri).fsPath;
lastGeneratedSource.set(fsPath, generatedDocument.getText());
if (fsPath.endsWith('.map')) {
// exclude sourcemaps
continue;
}
const workspaceRelativeFilePath = path.relative(workspaceRoot, path.dirname(fsPath));
const sdsFileName = path.basename(fsPath);
const sdsNoExtFilename =
path.extname(sdsFileName).length > 0
? sdsFileName.substring(0, sdsFileName.length - path.extname(sdsFileName).length)
: sdsFileName;
const workspaceRelativeFilePath = path.relative(workspaceRoot, path.dirname(fsPath));

lastGeneratedSource.set(
path.join(workspaceRelativeFilePath, sdsFileName).replaceAll('\\', '/'),
generatedDocument.getText(),
);
// Check for sourcemaps after they are already added to the pipeline context
// This needs to happen after lastGeneratedSource.set, as errors would not get mapped otherwise
if (fsPath.endsWith('.map')) {
// exclude sourcemaps from sending to runner
continue;
}
let modulePath = workspaceRelativeFilePath.replaceAll('/', '.').replaceAll('\\', '.');
if (!codeMap.hasOwnProperty(modulePath)) {
codeMap[modulePath] = {};
Expand Down

0 comments on commit 191ef33

Please sign in to comment.