From 83378a3187f27226476630273b1b1c4445c306c5 Mon Sep 17 00:00:00 2001 From: WinPlay02 Date: Sat, 17 Feb 2024 09:58:40 +0100 Subject: [PATCH] feat: check the runner version to be compatible (#888) ### Summary of Changes - check the runner version to be compatible before starting the runner Closes #880 --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> --- docs/README.md | 2 +- package-lock.json | 1 + packages/safe-ds-lang/package.json | 1 + .../src/language/runner/safe-ds-runner.ts | 16 +++++++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index ce4852166..6389468c5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,7 +15,7 @@ Safely develop Data Science programs with a statically checked domain specific l 2. To _execute_ Safe-DS programs, the [Safe-DS Runner](https://github.com/Safe-DS/Runner) has to be installed and configured additionally: 1. Install [Python](https://www.python.org/) (3.11 or 3.12). - 2. Run `pip install safe-ds-runner` in a command line to download the latest Runner version + 2. Run `pip install "safe-ds-runner>=0.6.0,<0.7.0"` in a command line to download the latest matching Runner version from [PyPI](https://pypi.org/project/safe-ds-runner/). 3. If the Visual Studio Code extension cannot start the runner, adjust the setting `safe-ds.runner.command`. Enter the absolute path to the Runner executable, as seen in the image below. diff --git a/package-lock.json b/package-lock.json index 9a0e0e777..933eb69e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14452,6 +14452,7 @@ "chevrotain": "^11.0.3", "glob": "^10.3.10", "langium": "^2.1.3", + "semver": "^7.6.0", "source-map": "^0.7.4", "tree-kill": "^1.2.2", "vscode-languageserver": "^9.0.1", diff --git a/packages/safe-ds-lang/package.json b/packages/safe-ds-lang/package.json index 4414ab9ab..f5432d113 100644 --- a/packages/safe-ds-lang/package.json +++ b/packages/safe-ds-lang/package.json @@ -46,6 +46,7 @@ "chevrotain": "^11.0.3", "glob": "^10.3.10", "langium": "^2.1.3", + "semver": "^7.6.0", "source-map": "^0.7.4", "tree-kill": "^1.2.2", "vscode-languageserver": "^9.0.1", diff --git a/packages/safe-ds-lang/src/language/runner/safe-ds-runner.ts b/packages/safe-ds-lang/src/language/runner/safe-ds-runner.ts index 4d422d0e9..83ceec10c 100644 --- a/packages/safe-ds-lang/src/language/runner/safe-ds-runner.ts +++ b/packages/safe-ds-lang/src/language/runner/safe-ds-runner.ts @@ -17,8 +17,12 @@ 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 semver from 'semver'; // Most of the functionality cannot be tested automatically as a functioning runner setup would always be required + +const SUPPORTED_VERSION_RANGE = '>=0.6.0 <0.7.0'; + export class SafeDsRunner { private readonly annotations: SafeDsAnnotations; private readonly generator: SafeDsPythonGenerator; @@ -85,7 +89,17 @@ export class SafeDsRunner { try { const pythonServerTest = child_process.spawn(runnerCommand, [...runnerCommandParts, '-V']); const versionString = await this.getPythonServerVersion(pythonServerTest); - this.logging.outputInfo(`Using safe-ds-runner version: ${versionString}`); + if (!semver.satisfies(versionString, SUPPORTED_VERSION_RANGE)) { + this.logging.outputError( + `Installed runner version ${versionString} does not meet requirements: ${SUPPORTED_VERSION_RANGE}`, + ); + this.logging.displayError( + `The installed runner version ${versionString} is not compatible with this version of the extension. The installed version should match these requirements: ${SUPPORTED_VERSION_RANGE}. Please update to a matching version.`, + ); + return; + } else { + this.logging.outputInfo(`Using safe-ds-runner version: ${versionString}`); + } } catch (error) { this.logging.outputError(`Could not start runner: ${error}`); this.logging.displayError('The runner process could not be started.');