Skip to content

Commit 09aa904

Browse files
VSC-1770 add constraint in pytest install step (#1686)
* add constraint in pytest install step * fix issue with workspace folder
1 parent 49d573a commit 09aa904

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/espIdf/unitTest/adapter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ export class UnitTest {
8585
if (!workspaceFolderUri) {
8686
return;
8787
}
88+
let workspaceFolder = workspace.getWorkspaceFolder(workspaceFolderUri);
89+
if (!workspaceFolder) {
90+
return;
91+
}
8892
this.unitTestAppUri = await configurePyTestUnitApp(
89-
workspaceFolderUri,
93+
workspaceFolder.uri,
9094
this.testComponents,
9195
cancelToken
9296
);

src/espIdf/unitTest/configure.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ESP } from "../../config";
2121
import { join } from "path";
2222
import { copy, pathExists, readFile, writeFile } from "fs-extra";
2323
import { readParameter, readSerialPort } from "../../idfConfiguration";
24-
import { startPythonReqsProcess } from "../../utils";
24+
import { getEspIdfFromCMake, startPythonReqsProcess } from "../../utils";
2525
import { runTaskForCommand } from "./testExecution";
2626
import { buildCommand } from "../../build/buildCmd";
2727
import { verifyCanFlash } from "../../flash/flashCmd";
@@ -48,7 +48,10 @@ export async function configurePyTestUnitApp(
4848
if (!doesUnitTestAppExists) {
4949
const unitTestFiles = await getFileList();
5050
const testComponents = await getTestComponents(unitTestFiles);
51-
unitTestAppUri = await copyTestAppProject(workspaceFolder, testComponents);
51+
unitTestAppUri = await copyTestAppProject(
52+
workspaceFolder,
53+
testComponents
54+
);
5255
await buildFlashTestApp(unitTestAppUri, cancelToken);
5356
}
5457
return unitTestAppUri;
@@ -132,6 +135,16 @@ export async function installPyTestPackages(
132135
cancelToken?: CancellationToken
133136
) {
134137
const idfPath = readParameter("idf.espIdfPath", workspaceFolder);
138+
const containerPath =
139+
process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME;
140+
const confToolsPath = readParameter(
141+
"idf.toolsPath",
142+
workspaceFolder
143+
) as string;
144+
const toolsPath =
145+
confToolsPath ||
146+
process.env.IDF_TOOLS_PATH ||
147+
join(containerPath, ".espressif");
135148
const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder);
136149
let requirementsPath = join(
137150
idfPath,
@@ -148,9 +161,27 @@ export async function installPyTestPackages(
148161
);
149162
}
150163

164+
const fullEspIdfVersion = await getEspIdfFromCMake(idfPath);
165+
const majorMinorMatches = fullEspIdfVersion.match(/([0-9]+\.[0-9]+).*/);
166+
const espIdfVersion =
167+
majorMinorMatches && majorMinorMatches.length > 0
168+
? majorMinorMatches[1]
169+
: "x.x";
170+
const constrainsFile = join(
171+
toolsPath,
172+
`espidf.constraints.v${espIdfVersion}.txt`
173+
);
174+
const constrainsFileExists = await pathExists(constrainsFile);
175+
let constraintArg = [];
176+
if (constrainsFileExists) {
177+
constraintArg = ["--constraint", constrainsFile];
178+
}
179+
151180
await runTaskForCommand(
152181
workspaceFolder,
153-
`"${pythonBinPath}" -m pip install --upgrade --no-warn-script-location -r "${requirementsPath}" --extra-index-url https://dl.espressif.com/pypi`,
182+
`"${pythonBinPath}" -m pip install --upgrade ${
183+
constraintArg && constraintArg.length > 0 ? constraintArg.join(" ") : ""
184+
} --no-warn-script-location -r "${requirementsPath}" --extra-index-url https://dl.espressif.com/pypi`,
154185
"Install Pytest",
155186
cancelToken
156187
);

0 commit comments

Comments
 (0)