diff --git a/tools/vscode-extension/package.json b/tools/vscode-extension/package.json index d706b597c..f771a7f9a 100644 --- a/tools/vscode-extension/package.json +++ b/tools/vscode-extension/package.json @@ -2,7 +2,7 @@ "name": "psx-dev", "displayName": "PSX.Dev", "description": "PlayStation 1 development made easy", - "version": "0.3.9", + "version": "0.3.10", "engines": { "vscode": "^1.75.0" }, diff --git a/tools/vscode-extension/templates.js b/tools/vscode-extension/templates.js index f9e6436d6..499c29e15 100644 --- a/tools/vscode-extension/templates.js +++ b/tools/vscode-extension/templates.js @@ -4,6 +4,7 @@ const path = require('node:path') const fs = require('fs-extra') const Mustache = require('mustache') const { simpleGit } = require('simple-git') +const tools = require('./tools.js') const terminal = require('./terminal.js') const progressNotification = require('./progressnotification.js') @@ -524,13 +525,17 @@ async function createGitRepository (fullPath, template, progressReporter) { } async function createPythonEnv (fullPath, name, packages, requirementsFiles) { - // On Windows "python" and "python3" are aliased to a script that opens the - // Microsoft Store by default, so the "py" launcher is invoked instead. - const pythonCommand = (process.platform === 'win32') ? 'py' : 'python3' + const pythonCommand = await tools.findPython() + const pipCommand = path.join( + fullPath, + name, + (process.platform === 'win32') ? 'Scripts' : 'bin', + 'pip' + ) + await terminal.run(pythonCommand, ['-m', 'venv', name], { cwd: fullPath }) - const pipCommand = path.join(fullPath, name, 'bin', 'pip') if (packages && packages.length) { await terminal.run(pipCommand, ['install', ...packages], { cwd: fullPath diff --git a/tools/vscode-extension/tools.js b/tools/vscode-extension/tools.js index d2149de5c..973d0d15e 100644 --- a/tools/vscode-extension/tools.js +++ b/tools/vscode-extension/tools.js @@ -27,16 +27,20 @@ async function checkInstalled (name) { return tools[name].installed } -async function checkCommands (commands, args) { +async function findCommand (commands, args) { for (const command of commands) { try { await execFile(command, args) } catch (error) { continue } - return true + return command } - return false + return null +} + +async function checkCommands (commands, args) { + return (await findCommand(commands, args)) !== null } let mipsInstalling = false @@ -306,7 +310,7 @@ async function installCMake () { asset.browser_download_url.split('/').pop() ) await downloader.downloadFile(asset.browser_download_url, filename) - await execFile('start', [filename]) + await execFile('msiexec', ['/i', filename]) requiresReboot = true break case 'linux': @@ -457,7 +461,7 @@ async function installPython () { } } -async function checkPython () { +async function findPython () { switch (process.platform) { case 'win32': /* @@ -501,12 +505,12 @@ async function checkPython () { } catch (error) { continue } - return true + return fullPath } } - return false + return null default: - return checkCommands(['python3', 'python'], ['--version']) + return await findCommand(['python3', 'python'], ['--version']) } } @@ -606,7 +610,7 @@ const tools = { 'Python language runtime, required to run some project templates\' scripts', homepage: 'https://python.org/', install: installPython, - check: checkPython + check: async () => (await findPython()) !== null }, clangd: { type: 'extension', @@ -702,6 +706,8 @@ exports.setGlobalStorageUri = (uri) => { globalStorageUri = uri } +exports.findPython = findPython + exports.install = async (toInstall, force) => { if (requiresReboot) { return true