Skip to content

VS Code extension: fix CMake installation and Python venv setup on Windows #1948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spicyjpeg
Copy link
Contributor

Fix for the createPythonEnv() function in the PSX.Dev VS Code extension, which is currently broken on Windows due to it not taking into account the "fake" Python executables that redirect to the Microsoft Store as well as virtual environments having a slightly different file structure depending on the platform. I have also fixed installCMake() and bumped the extension's version number to 0.3.10.

I haven't yet tested these changes on a Windows machine so please review before merging.

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

Walkthrough

The changes update the VSCode extension version, refactor command and Python executable detection logic, and adjust how Python environments are created. The new logic finds the actual Python executable path rather than relying on platform-specific command strings, and updates the CMake installer invocation method on Windows.

Changes

Cohort / File(s) Change Summary
VSCode Extension Version Bump
tools/vscode-extension/package.json
Incremented the extension version from 0.3.9 to 0.3.10; no other modifications.
Python Environment Creation Logic
tools/vscode-extension/templates.js
Changed Python executable detection to use new tools.findPython(); adjusted pip path logic; updated internal flow for creating Python environments.
Command and Python Detection Refactor
tools/vscode-extension/tools.js
Refactored command detection: split checkCommands into findCommand (returns first valid command) and a new checkCommands (returns boolean). Renamed and updated Python detection function (checkPythonfindPython), now returns executable path or null. Updated CMake installer invocation on Windows. Exported findPython.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Extension
    participant Tools Module

    User->>Extension: Initiate Python environment creation
    Extension->>Tools Module: Call findPython()
    Tools Module-->>Extension: Return Python executable path or null
    Extension->>Extension: Compute pip path based on Python executable
    Extension->>Extension: Create virtual environment
    Extension->>Extension: Install packages with pip
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In burrows deep, I sniff and find
The Python path, not left behind!
A version hop, a tidy sweep—
Commands refactored, changes neat.
With every hop, the code grows bright,
This bunny’s work feels just right! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tools/vscode-extension/tools.js (1)

464-515: Excellent Windows Python detection logic with minor improvement needed.

The comprehensive approach to handling Windows' fake Python executables is well-implemented and documented. The UWP detection and path filtering logic properly addresses the Microsoft Store redirect issue.

Consider adding error handling around fs.stat() call:

        for (const fullPath of matches) {
-          const stats = await fs.stat(fullPath)
+          let stats
+          try {
+            stats = await fs.stat(fullPath)
+          } catch (error) {
+            continue
+          }
          if (!stats.size && !hasUWPPython) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1f0293 and f4d353c.

📒 Files selected for processing (3)
  • tools/vscode-extension/package.json (1 hunks)
  • tools/vscode-extension/templates.js (2 hunks)
  • tools/vscode-extension/tools.js (6 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeScene Cloud Delta Analysis (main)
tools/vscode-extension/tools.js

[notice] 464-513: ✅ 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.


[notice] 464-513: ✅ 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.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build-openbios
  • GitHub Check: aur-build
  • GitHub Check: cross-arm64
  • GitHub Check: coverage
  • GitHub Check: build
  • GitHub Check: asan
  • GitHub Check: toolchain
  • GitHub Check: macos-build-and-test-toolchain
🔇 Additional comments (15)
tools/vscode-extension/tools.js (10)

30-44: LGTM! Clean refactoring improves code modularity.

The separation of checkCommands into findCommand and checkCommands is well-designed. findCommand returns the actual command that works (or null), while checkCommands maintains the boolean interface for backward compatibility.


313-313: Improved CMake installer invocation on Windows.

Using msiexec /i directly is more reliable than using start with the MSI file, as it ensures proper MSI execution and better error handling.


464-515: Excellent Windows Python detection logic with comprehensive UWP handling.

The implementation correctly addresses the Windows-specific issue with fake Python executables that redirect to the Microsoft Store. The approach is well-documented and handles both UWP and traditional Python installations.

Key strengths:

  • Checks for UWP Python installations first using PowerShell
  • Uses which to find all executable paths, not just the first one
  • Validates file size to detect fake executables when UWP Python isn't present
  • Tests actual execution with --version to ensure the executable works
  • Falls back to the simpler findCommand approach on non-Windows platforms

613-613: Proper integration with new findPython function.

The Python tool's check function correctly uses the new async findPython() and converts the result to a boolean by checking for null.


709-709: Necessary export for cross-module usage.

Exporting findPython allows templates.js to use the enhanced Python detection logic.


30-40: LGTM! Clean refactor separating command finding from boolean checking.

The new findCommand function properly extracts the logic for finding the first working command from a list, returning the command string or null. This separation of concerns improves code reusability.


42-44: LGTM! Maintains backward compatibility while leveraging the refactor.

The updated checkCommands function correctly wraps findCommand to preserve the boolean return interface expected by existing callers.


313-313: LGTM! Proper fix for Windows MSI installation.

Using msiexec /i instead of start is the correct way to programmatically install MSI packages on Windows. This ensures the installer runs properly rather than just opening the file.


613-613: LGTM! Proper integration with the refactored findPython function.

The check property correctly adapts to use the new findPython function, converting its path return value to the expected boolean result.


709-709: LGTM! Necessary export for cross-module integration.

Exporting findPython allows other modules like templates.js to use the enhanced Python detection logic.

tools/vscode-extension/templates.js (3)

7-7: Proper import for enhanced Python detection.

Adding the tools import enables access to the improved findPython function.


528-535: Excellent improvement to Python environment creation.

The changes significantly improve Windows compatibility:

  • Dynamic Python detection: Uses await tools.findPython() instead of hardcoded platform-specific commands
  • Cross-platform pip path: Correctly handles the difference between Windows (Scripts) and Unix-like systems (bin) for the pip executable location
  • Better integration: Leverages the robust Python detection logic from tools.js

This addresses the core issue mentioned in the PR objectives where createPythonEnv() was broken on Windows.


7-7: LGTM! Required import for the enhanced Python detection.

The import of the tools module provides access to the findPython function needed by createPythonEnv.

tools/vscode-extension/package.json (2)

5-5: Appropriate version bump for bug fixes and improvements.

The version increment from 0.3.9 to 0.3.10 correctly reflects the Windows compatibility fixes and improvements made to the Python environment setup and CMake installation.


5-5: LGTM! Appropriate patch version bump for bug fixes.

The version increment from 0.3.9 to 0.3.10 correctly follows semantic versioning for the Windows compatibility fixes in this PR.

Comment on lines +528 to +535
const pythonCommand = await tools.findPython()
const pipCommand = path.join(
fullPath,
name,
(process.platform === 'win32') ? 'Scripts' : 'bin',
'pip'
)

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.

@nicolasnoble nicolasnoble requested a review from Copilot August 3, 2025 05:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes critical Windows compatibility issues in the PSX.Dev VS Code extension by addressing Python executable detection and virtual environment setup that were broken due to Windows-specific behavior, along with fixing CMake installation.

  • Refactored Python detection to avoid Windows Store redirects and properly locate real Python executables
  • Fixed virtual environment pip path resolution to account for Windows using 'Scripts' directory instead of 'bin'
  • Updated CMake installation to use msiexec instead of start command for proper Windows installation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tools/vscode-extension/tools.js Refactored command checking functions and fixed Python detection logic for Windows compatibility
tools/vscode-extension/templates.js Updated Python virtual environment creation to use proper directory structure and Python executable detection
tools/vscode-extension/package.json Bumped version number to 0.3.10

@@ -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])
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.

// 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.

@nicolasnoble
Copy link
Member

I haven't had time to try this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants