Skip to content

Commit

Permalink
update getting system python
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 committed Aug 13, 2024
1 parent be02c24 commit cbc83a9
Show file tree
Hide file tree
Showing 6 changed files with 707 additions and 337 deletions.
4 changes: 2 additions & 2 deletions .github/actions/idf/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ENV CODE_VERSION="min"

ENV NVM_DIR /usr/local/nvm
RUN mkdir -p $NVM_DIR
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
ENV NODE_VERSION v16.16.0
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
ENV NODE_VERSION v18.19.1
RUN . "${NVM_DIR}/nvm.sh" && nvm install ${NODE_VERSION} && nvm use --delete-prefix ${NODE_VERSION}

ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/lib/node_modules
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ jobs:
with:
run: /ui-entrypoint.sh

- name: See if screenshots are generated
if: failure()
run: ls /github/workspace/test-resources/screenshots

- name: Upload screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: screenshots
path: test-resources/screenshots/*.png
path: /github/workspace/test-resources/screenshots
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@
"genLocalizationBundle": "npx @vscode/l10n-dev export --outDir ./l10n ./src",
"webpack": "webpack --mode production",
"ui-test": "yarn compile && extest setup-and-run -y -i -u -l DEBUG -o testFiles/testWorkspace/.vscode/settings.json 'out/ui-test/*-test.js'",
"ci-test": "yarn compile && extest setup-and-run './out/ui-test/*-test.js' -u -s test-resources -l DEBUG -o testFiles/testWorkspace/.vscode/settings.json"
"ci-test": "yarn compile && extest setup-and-run './out/ui-test/*-test.js' -u -s test-resources -o testFiles/testWorkspace/.vscode/settings.json -l DEBUG"
},
"devDependencies": {
"@babel/types": "^7.23.0",
Expand Down Expand Up @@ -2118,7 +2118,7 @@
"typescript": "^5.2.2",
"vite": "^4.5.3",
"vsce": "^2.6.7",
"vscode-extension-tester": "^7.0.0",
"vscode-extension-tester": "7.3.2",
"vue-hot-reload-api": "^2.3.2",
"vue-loader": "^17.2.2",
"vue-router": "^4.2.4",
Expand Down
15 changes: 6 additions & 9 deletions src/espIdf/debugAdapter/debugAdapterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class DebugAdapterManager extends EventEmitter {

private constructor(context: vscode.ExtensionContext) {
super();
this.configureWithDefaultValues(context.extensionPath);
this.configureWithDefaultValues(context.extensionUri);
OutputChannel.init();
this.chan = Buffer.alloc(0);
}
Expand All @@ -89,10 +89,7 @@ export class DebugAdapterManager extends EventEmitter {
if (this.isRunning()) {
return;
}
const workspace = PreCheck.isWorkspaceFolderOpen()
? vscode.workspace.workspaceFolders[0].uri.fsPath
: "";
if (!isBinInPath("openocd", workspace, this.env)) {
if (!isBinInPath("openocd", this.currentWorkspace.fsPath, this.env)) {
return reject(
new Error("Invalid OpenOCD bin path or access is denied for the user")
);
Expand Down Expand Up @@ -274,12 +271,12 @@ export class DebugAdapterManager extends EventEmitter {
return this.adapter && !this.adapter.killed;
}

private async configureWithDefaultValues(extensionPath: string) {
private async configureWithDefaultValues(extensionPath: vscode.Uri) {
this.currentWorkspace = PreCheck.isWorkspaceFolderOpen()
? vscode.workspace.workspaceFolders[0].uri
: undefined;
: extensionPath;
this.debugAdapterPath = path.join(
extensionPath,
extensionPath.fsPath,
"esp_debug_adapter",
"debug_adapter_main.py"
);
Expand All @@ -300,7 +297,7 @@ export class DebugAdapterManager extends EventEmitter {
this.target = idfTarget;
this.env = await appendIdfAndToolsToPath(this.currentWorkspace);
this.env.PYTHONPATH = path.join(
extensionPath,
extensionPath.fsPath,
"esp_debug_adapter",
"debug_adapter"
);
Expand Down
60 changes: 48 additions & 12 deletions src/pythonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Logger } from "./logger/logger";
import { delimiter, dirname, join, sep } from "path";
import { OutputChannel } from "./logger/outputChannel";
import { readParameter, writeParameter } from "./idfConfiguration";
import { ESP } from "./config";

export async function installEspIdfToolFromIdf(
espDir: string,
Expand Down Expand Up @@ -293,18 +294,53 @@ export async function getPythonPath(workspaceFolder: Uri) {
}

export async function getSystemPython(workspaceFolder: Uri) {
const pythonBinPath = readParameter("idf.pythonBinPath") as string;
const pythonCode = `import sys; print('{}'.format(sys.base_prefix))`;
const args = ["-c", pythonCode];
const pythonVersion = (
await utils.execChildProcess(pythonBinPath, args, workspaceFolder.fsPath)
).replace(/(\n|\r|\r\n)/gm, "");
const pyDir =
process.platform === "win32"
? ["Scripts", "python.exe"]
: ["bin", "python3"];
const sysPythonBinPath = join(pythonVersion, ...pyDir);
return sysPythonBinPath;
let pythonBinPath = readParameter(
"idf.pythonBinPath",
workspaceFolder
) as string;
const pythonBinPathExists = await pathExists(pythonBinPath);
if (pythonBinPathExists) {
const pythonCode = `import sys; print('{}'.format(sys.base_prefix))`;
const args = ["-c", pythonCode];
const workingDir =
workspaceFolder && workspaceFolder.fsPath
? workspaceFolder.fsPath
: __dirname;
const pythonVersion = (
await utils.execChildProcess(pythonBinPath, args, workingDir)
).replace(/(\n|\r|\r\n)/gm, "");
const pyDir =
process.platform === "win32"
? ["Scripts", "python.exe"]
: ["bin", "python3"];
const sysPythonBinPath = join(pythonVersion, ...pyDir);
return sysPythonBinPath;
}

if (process.platform !== "win32") {
const sysPythonBinPathList = await getUnixPythonList(__dirname);
return sysPythonBinPathList.length ? sysPythonBinPathList[0] : "python3";
} else {
const idfPathDir = readParameter("idf.espIdfPath", workspaceFolder);
const idfToolsDir = readParameter(
"idf.toolsPath",
workspaceFolder
) as string;
const idfVersion = await utils.getEspIdfFromCMake(idfPathDir);
const pythonVersionToUse =
idfVersion >= "5.0"
? ESP.URL.IDF_EMBED_PYTHON.VERSION
: ESP.URL.OLD_IDF_EMBED_PYTHON.VERSION;
const idfPyDestPath = join(
idfToolsDir,
"tools",
"idf-python",
pythonVersionToUse,
"Scripts",
"python.exe"
);
return idfPyDestPath;
}
}

export async function getPythonEnvPath(
Expand Down
Loading

0 comments on commit cbc83a9

Please sign in to comment.