Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lazToum committed Dec 3, 2024
1 parent 0ee2d36 commit f406e22
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 133 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
id-token: write

jobs:
build:
all:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
Expand All @@ -23,12 +23,11 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install python on windows
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
update-environment: true
if: matrix.os == 'windows-latest'
- name: Display Python version
run: python --version
- run: corepack enable
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## v0.1.2

- Updated @waldiez/react
- Added a minimum waldiez/py version check
- Dependencies update

## v0.1.1

- Added monaco editor assets to the build
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "waldiez-vscode",
"displayName": "Waldiez",
"description": "A Waldiez vscode extension",
"version": "0.1.1",
"version": "0.1.2",
"engines": {
"vscode": "^1.95.0"
},
Expand Down Expand Up @@ -143,24 +143,24 @@
"@types/node": "22.10.1",
"@types/react-dom": "^18.3.1",
"@types/sinon": "^17.0.3",
"@types/source-map-support": "^0",
"@types/source-map-support": "^0.5.10",
"@types/tar-stream": "^3.1.3",
"@types/vscode": "^1.95.0",
"@types/vscode-webview": "^1.57.5",
"@types/webpack-env": "^1.18.5",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"@vscode/vsce": "^3.2.1",
"@waldiez/react": "^0.1.15",
"@waldiez/react": "^0.1.16",
"babel-loader": "^9.2.1",
"css-loader": "^7.1.2",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"mini-css-extract-plugin": "^2.9.2",
"mocha": "^11.0.0",
"mocha": "^11.0.1",
"nanoid": "^5.0.9",
"nyc": "^17.1.0",
"pre-commit": "^1.2.2",
Expand All @@ -181,10 +181,10 @@
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0",
"typescript-eslint": "^8.17.0",
"vsce": "^2.15.0",
"vscode-test": "^1.6.1",
"webpack": "^5.96.1",
"webpack": "^5.97.0",
"webpack-cli": "^5.1.4"
},
"pre-commit": [
Expand Down
148 changes: 100 additions & 48 deletions src/host/flow/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { traceError, traceInfo, traceLog, traceWarn } from '../log/logging';
import { spawn } from 'child_process';
import { spawn, spawnSync } from 'child_process';
import * as vscode from 'vscode';

const MINIMUM_REQUIRED_WALDIEZ_PY_VERSION = '0.1.12';

/**
* Ensures that the `waldiez` Python module is available in the current Python environment.
*
Expand All @@ -22,62 +24,112 @@ export const ensureWaldiezPy = (
return;
}

// Check if the `waldiez` module is already installed
const check = spawn(executable, ['-m', 'waldiez', '--version']);
check.on('exit', code => {
if (code === 0) {
// If the module is found, resolve the promise
resolve();
try {
const result = spawnSync(executable, [
'-m',
'waldiez',
'--version'
]);
// check if the waldiez module is installed and the version is at least the minimum required
if (result.status === 0) {
const commandOutput = result.stdout.toString().trim();
const version = commandOutput.match(/(\d+\.\d+\.\d+)/)?.[0];
if (!version) {
traceError('Failed to parse waldiez version');
return installWaldiezPy(executable);
}
if (isVersionOK(version)) {
traceInfo(`Found Waldiez Python module version ${version}`);
resolve();
return;
}
traceWarn(
`Waldiez Python module version ${version} found, but version ${MINIMUM_REQUIRED_WALDIEZ_PY_VERSION} or higher is required. Updating...`
);
return installWaldiezPy(executable);
} else {
// If the module is not found, attempt to install it
vscode.window.showInformationMessage(
traceWarn(
'Waldiez Python module not found in the current Python environment. Installing...'
);
return installWaldiezPy(executable);
}
} catch (error) {
traceError('Failed to check waldiez version:', error);
return installWaldiezPy(executable);
}
});
};

const install = spawn(executable, [
'-m',
'pip',
'install',
'waldiez'
]);
const installWaldiezPy = (executable: string) => {
return new Promise<void>((resolve, reject) => {
vscode.window.showInformationMessage(
'Waldiez Python module not found in the current Python environment. Installing...'
);
// we might want to update this below
// to use --user flag (but we first need to check if we are in a virtual environment)
// if so, the --user will raise an error
const install = spawn(executable, [
'-m',
'pip',
'install',
'--break-system-packages',
`waldiez>=${MINIMUM_REQUIRED_WALDIEZ_PY_VERSION}`
]);

// Log standard output during the installation process
install.stdout.on('data', data => {
traceLog(data.toString());
});
// Log standard output during the installation process
install.stdout.on('data', data => {
traceLog(data.toString());
});

// Log and categorize standard error during the installation process
install.stderr.on('data', data => {
const dataString = data.toString();
if (dataString.startsWith('WARNING')) {
traceWarn(dataString);
return;
}
if (dataString.startsWith('ERROR')) {
traceError(dataString);
return;
}
if (dataString.startsWith('INFO')) {
traceInfo(dataString);
return;
}
traceError(dataString);
});
// Log and categorize standard error during the installation process
install.stderr.on('data', data => {
const dataString = data.toString();
if (dataString.startsWith('WARNING')) {
traceWarn(dataString);
return;
}
if (dataString.startsWith('ERROR')) {
traceError(dataString);
return;
}
if (dataString.startsWith('INFO')) {
traceInfo(dataString);
return;
}
traceError(dataString);
});

// Handle installation completion
install.on('exit', code => {
if (code === 0) {
// Resolve the promise if the installation succeeds
resolve();
} else {
// Reject the promise if the installation fails
vscode.window.showErrorMessage(
'Failed to install Waldiez Python module. Please check your Python environment.'
);
reject();
}
});
// Handle installation completion
install.on('exit', code => {
if (code === 0) {
// Resolve the promise if the installation succeeds
resolve();
} else {
// Reject the promise if the installation fails
vscode.window.showErrorMessage(
'Failed to install Waldiez Python module. Please check your Python environment.'
);
reject();
}
});
});
};

const isVersionOK = (version: string): boolean => {
try {
const [major, minor, patch] = version.split('.').map(Number);
const [requiredMajor, requiredMinor, requiredPatch] =
MINIMUM_REQUIRED_WALDIEZ_PY_VERSION.split('.').map(Number);
return (
major > requiredMajor ||
(major === requiredMajor && minor > requiredMinor) ||
(major === requiredMajor &&
minor === requiredMinor &&
patch >= requiredPatch)
);
} catch (error) {
traceError('Failed to parse waldiez version:', error);
return false;
}
};
7 changes: 4 additions & 3 deletions src/host/flow/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ export class FlowConverter extends vscode.Disposable {
const toRun = [
'-m',
'waldiez',
'--force',
'--export',
'convert',
'--file',
`${resource.fsPath}`,
'--output',
`${outputFile}`,
`${resource.fsPath}`
'--force'
];
traceVerbose(`Converting ${resource.fsPath} to ${outputFile}`);

Expand Down
2 changes: 2 additions & 0 deletions src/host/flow/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class FlowRunner extends vscode.Disposable {
const cmdArgs = [
'-m',
'waldiez',
'run',
'--file',
`${resource.fsPath}`,
'--output',
`${outputPy}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PythonExtension } from '@vscode/python-extension';
import { spawnSync } from 'child_process';
import * as vscode from 'vscode';

export async function waitForPythonEnvironments(): Promise<void> {
export async function beforeTests(): Promise<void> {
await vscode.extensions.getExtension('ms-python.python')?.activate();
const api = await PythonExtension.api();
const maxRetries = 10; // Maximum retries to wait for environments
Expand All @@ -29,9 +29,20 @@ export async function waitForPythonEnvironments(): Promise<void> {
})[0];
if (highestVersion) {
const executable = highestVersion.path;
spawnSync(executable, ['-m', 'pip', 'install', 'waldiez'], {
stdio: 'pipe'
});
spawnSync(
executable,
[
'-m',
'pip',
'install',
'--upgrade',
'--break-system-packages',
'waldiez'
],
{
stdio: 'pipe'
}
);
}
console.log(`Discovered ${api.environments.known.length} environments`);
}
13 changes: 9 additions & 4 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { waitForPythonEnvironments } from '../waitForPythonEnvironments';
import { beforeTests } from './beforeTests';
import { glob } from 'glob';
import Mocha from 'mocha';
import path from 'path';
Expand Down Expand Up @@ -41,10 +41,11 @@ export async function run(): Promise<void> {
color: true,
bail: true,
fullTrace: true,
timeout: 60000
timeout: 300000
});
// Wait for Python environments to be ready
await waitForPythonEnvironments();
// and install waldiez python package
await beforeTests();

const nyc = setupCoverage();

Expand All @@ -60,7 +61,7 @@ export async function run(): Promise<void> {
});

files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

let success = true;
try {
await new Promise<void>((resolve, reject) => {
mocha.run(failures =>
Expand All @@ -71,7 +72,11 @@ export async function run(): Promise<void> {
});
} catch (err) {
console.error(err);
success = false;
} finally {
if (!success) {
process.exit(1);
}
if (nyc) {
nyc.writeCoverageFile();
await nyc.report();
Expand Down
Loading

0 comments on commit f406e22

Please sign in to comment.