Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
13 changes: 9 additions & 4 deletions tools/vscode-extension/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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()
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If findPython() returns null (no Python found), this will cause pythonCommand to be null and the subsequent terminal.run() call will fail with an unclear error. Add validation to check if pythonCommand is null and provide a helpful error message.

Suggested change
const pythonCommand = await tools.findPython()
const pythonCommand = await tools.findPython()
if (!pythonCommand) {
throw new Error('Python executable not found. Please ensure Python is installed and available in your PATH.');
}

Copilot uses AI. Check for mistakes.

const pipCommand = path.join(
fullPath,
name,
(process.platform === 'win32') ? 'Scripts' : 'bin',
'pip'
)

Comment on lines +528 to +535
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Excellent improvement with missing error handling.

The changes properly use the enhanced Python detection and correctly handle platform-specific virtual environment structure. This addresses the core Windows compatibility issue mentioned in the PR.

Add error handling for when Python isn't found:

 async function createPythonEnv (fullPath, name, packages, requirementsFiles) {
   const pythonCommand = await tools.findPython()
+  if (!pythonCommand) {
+    throw new Error('Python executable not found. Please install Python first.')
+  }
   const pipCommand = path.join(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const pythonCommand = await tools.findPython()
const pipCommand = path.join(
fullPath,
name,
(process.platform === 'win32') ? 'Scripts' : 'bin',
'pip'
)
async function createPythonEnv (fullPath, name, packages, requirementsFiles) {
const pythonCommand = await tools.findPython()
+ if (!pythonCommand) {
+ throw new Error('Python executable not found. Please install Python first.')
+ }
const pipCommand = path.join(
fullPath,
name,
(process.platform === 'win32') ? 'Scripts' : 'bin',
'pip'
)
🤖 Prompt for AI Agents
In tools/vscode-extension/templates.js around lines 528 to 535, add error
handling for the case when the Python executable is not found by
tools.findPython(). Check if pythonCommand is undefined or null after the await
call, and if so, throw an error or return early with a clear message indicating
that Python was not found. This will prevent subsequent code from failing
silently or with unclear errors.

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
Expand Down
24 changes: 15 additions & 9 deletions tools/vscode-extension/tools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'

Check notice on line 1 in tools/vscode-extension/tools.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 7.06 to 6.42, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.

const vscode = require('vscode')
const util = require('node:util')
Expand Down Expand Up @@ -27,16 +27,20 @@
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
Expand Down Expand Up @@ -306,7 +310,7 @@
asset.browser_download_url.split('/').pop()
)
await downloader.downloadFile(asset.browser_download_url, filename)
await execFile('start', [filename])
await execFile('msiexec', ['/i', filename])
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The msiexec call lacks error handling and user interaction considerations. MSI installations typically require user interaction or administrative privileges. Consider adding the '/quiet' flag for silent installation or '/passive' for progress-only UI, and handle potential elevation requirements.

Suggested change
await execFile('msiexec', ['/i', filename])
try {
await execFile('msiexec', ['/i', filename, '/passive']);
} catch (error) {
vscode.window.showErrorMessage(
'Failed to install CMake. Please ensure you have administrative privileges and try again.'
);
throw error;
}

Copilot uses AI. Check for mistakes.

requiresReboot = true
break
case 'linux':
Expand Down Expand Up @@ -457,56 +461,56 @@
}
}

async function checkPython () {
async function findPython () {
switch (process.platform) {
case 'win32':
/*
* We cannot simply run 'python --version' here as Windows ships by
* default with fake (zero-byte) 'python' and 'python3' executables in its
* PATH. These files are actually links to UWP apps, implemented using a
* specific NTFS reparse tag. If Python is installed from the Microsoft
* Store they behave as if they were symlinks to the actual executables;
* if not, however, attempting to run them will result in the store
* popping up and prompting the user to install Python.
*
* A kludge is thus needed here in order to prevent this from happening.
* We'll first check for any UWP Python installations, then search PATH
* manually and skip the fake binaries if none was found. This ensures
* both UWP and non-UWP installs will be detected somewhat reliably.
*
* IMPORTANT: this assumes that the project's build system will also be
* able to detect and ignore the fake executables (rather than e.g.
* blindly executing 'python'). This is currently the case for the
* CMake-based templates.
*/
let hasUWPPython
try {
const result = await execFile('powershell', [
'-c',
'Get-AppxPackage -Name PythonSoftwareFoundation.Python.*'
])
hasUWPPython = (result.stdout.trim() !== '')
} catch (error) {
hasUWPPython = false
}
for (const command of ['python3', 'python', 'py']) {
const matches = await which(command, { all: true })
for (const fullPath of matches) {
const stats = await fs.stat(fullPath)
if (!stats.size && !hasUWPPython) {
continue
}
try {
await execFile(fullPath, ['--version'])
} catch (error) {
continue
}
return true
return fullPath
}
}
return false
return null
default:
return checkCommands(['python3', 'python'], ['--version'])
return await findCommand(['python3', 'python'], ['--version'])

Check notice on line 513 in tools/vscode-extension/tools.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Deep, Nested Complexity

checkPython is no longer above the threshold for nested complexity depth. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
}
}

Expand Down Expand Up @@ -606,7 +610,7 @@
'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',
Expand Down Expand Up @@ -702,6 +706,8 @@
globalStorageUri = uri
}

exports.findPython = findPython

exports.install = async (toInstall, force) => {
if (requiresReboot) {
return true
Expand Down
Loading