Skip to content

Commit

Permalink
Python binary name based on OS
Browse files Browse the repository at this point in the history
  • Loading branch information
DavesCodeMusings committed May 19, 2023
1 parent 17f406e commit f3318d6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ MAJOR = mpremote major
MINOR = mpremote minor
PATCH = extension version

## 0.4.4 Release Notes
Fix to use py.exe only on Windows and python on all other OS.

## 0.4.3 Release Notes
Logo change.

Expand Down
28 changes: 18 additions & 10 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ const path = require('path')
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
// Assume this is a Windows system, but adjust if not.
let PYTHON_BIN = 'py.exe'
console.debug('Operating System:', process.platform)
if (process.platform != 'win32') { // win32 is returned for 64-bit OS as well
PYTHON_BIN = 'python'
}
console.debug('Using Python executable:', PYTHON_BIN)

// Python and the esptool module must be installed for this to work.
try {
let pythonVersion = childProcess.execSync('py --version').toString().split('\r\n')[0].split(' ')[1]
let pythonVersion = childProcess.execSync(`${PYTHON_BIN} --version`).toString().split('\r\n')[0].split(' ')[1]
console.debug('Python version:', pythonVersion)
}
catch (ex) {
vscode.window.showErrorMessage('Python is not installed or could not be run as py.exe', ex)
vscode.window.showErrorMessage(`Python is not installed or could not be run as ${PYTHON_BIN}`, ex)
}

try {
let mpremoteVersion = childProcess.execSync('py -m mpremote version').toString().split('\r\n')[0].split(' ')[1]
let mpremoteVersion = childProcess.execSync(`${PYTHON_BIN} -m mpremote version`).toString().split('\r\n')[0].split(' ')[1]
console.debug('mpremote version:', mpremoteVersion)
}
catch (ex) {
Expand Down Expand Up @@ -64,14 +72,14 @@ function activate(context) {
}

let devsCommand = vscode.commands.registerCommand('mpremote.devs', () => {
term.sendText('py.exe -m mpremote devs')
term.sendText(`${PYTHON_BIN} -m mpremote devs`)
})

context.subscriptions.push(devsCommand)

let listFilesCommand = vscode.commands.registerCommand('mpremote.ls', async () => {
let port = await getDevicePort()
term.sendText(`py.exe -m mpremote connect ${port} fs ls`)
term.sendText(`${PYTHON_BIN} -m mpremote connect ${port} fs ls`)
})

context.subscriptions.push(listFilesCommand)
Expand All @@ -87,7 +95,7 @@ function activate(context) {
let remoteFile = path.basename(localFile)
console.debug('Local file:', localFile)
console.debug('Remote file:', remoteFile)
term.sendText(`py.exe -m mpremote connect ${port} fs cp ${localFile} :${remoteFile}`)
term.sendText(`${PYTHON_BIN} -m mpremote connect ${port} fs cp ${localFile} :${remoteFile}`)
}
}
else {
Expand All @@ -99,7 +107,7 @@ function activate(context) {

let replCommand = vscode.commands.registerCommand('mpremote.repl', async () => {
let port = await getDevicePort()
term.sendText(`py.exe -m mpremote connect ${port} repl`)
term.sendText(`${PYTHON_BIN} -m mpremote connect ${port} repl`)
})

context.subscriptions.push(replCommand)
Expand All @@ -111,7 +119,7 @@ function activate(context) {
}
if (vscode.window.activeTextEditor.document.uri.fsPath) {
let port = await getDevicePort()
term.sendText(`py.exe -m mpremote connect ${port} run ${vscode.window.activeTextEditor.document.uri.fsPath}`)
term.sendText(`${PYTHON_BIN} -m mpremote connect ${port} run ${vscode.window.activeTextEditor.document.uri.fsPath}`)
}
}
else {
Expand All @@ -127,13 +135,13 @@ function activate(context) {
title: "Package Name"
}
let pkg = await vscode.window.showInputBox(options)
term.sendText(`py.exe -m mpremote connect ${port} mip install ${pkg}`)
term.sendText(`${PYTHON_BIN} -m mpremote connect ${port} mip install ${pkg}`)
})

context.subscriptions.push(mipInstallCommand)

let disconnectCommand = vscode.commands.registerCommand('mpremote.disconnect', () => {
term.sendText('py.exe -m mpremote disconnect')
term.sendText(`${PYTHON_BIN} -m mpremote disconnect`)
})

context.subscriptions.push(disconnectCommand)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Command palette access for MicroPython mpremote",
"icon": "images/snake.png",
"publisher": "DavesCodeMusings",
"version": "0.4.3",
"version": "0.4.4",
"engines": {
"vscode": "^1.73.0"
},
Expand Down

0 comments on commit f3318d6

Please sign in to comment.