Skip to content

Commit d137602

Browse files
committed
builtin some utils py pkgs
1 parent 2473c85 commit d137602

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
88.5 KB
Binary file not shown.

src/extension.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,54 @@ function postLaunchHook(extensionCtx: vscode.ExtensionContext) {
358358
ResInstaller.instance()
359359
.refreshExternalToolsIndex()
360360
.catch(err => GlobalEvent.log_warn(err));
361+
362+
// check py pkgs
363+
checkAndInstallBuiltPyPkgs()
364+
.catch(err => GlobalEvent.log_warn(err));
361365
}
362366

363367
//////////////////////////////////////////////////
364368
// internal vsc-commands funcs
365369
//////////////////////////////////////////////////
366370

371+
async function checkAndInstallBuiltPyPkgs() {
372+
373+
if (platform.osType() != 'win32')
374+
return;
375+
376+
const resManager = ResManager.instance();
377+
const py3 = resManager.getPython3();
378+
379+
const builtin_pkgs: { [name: string]: string } = {
380+
'pyserial': 'pyserial-3.5-py2.py3-none-any.whl'
381+
};
382+
383+
for (const name in builtin_pkgs) {
384+
// check:
385+
// .\python3.exe -m pip show intelhex
386+
ChildProcess.exec(`"${py3}" -m pip show ${name}`, (err, stdout) => {
387+
if (!err) {
388+
const lines = stdout.split(/\r\n|\n/);
389+
const installed = lines.some(line => /^Version:\s+/.test(line));
390+
if (installed)
391+
return;
392+
}
393+
// install
394+
// .\python3 -m pip --no-cache-dir install %*
395+
GlobalEvent.log_info(`Installing python package: ${builtin_pkgs[name]} ...`);
396+
const pkgFullPath = NodePath.join(resManager.getAppDataDir().path, builtin_pkgs[name]);
397+
ChildProcess.exec(`"${py3}" -m pip install "${pkgFullPath}"`, (err) => {
398+
if (!err) {
399+
GlobalEvent.log_info(`Done.`);
400+
} else {
401+
GlobalEvent.log_warn(`Fail to install python package: ${builtin_pkgs[name]}`);
402+
GlobalEvent.log_warn(err);
403+
}
404+
});
405+
});
406+
}
407+
}
408+
367409
function ShowUUID() {
368410
vscode.window.showInputBox({
369411
value: platform.GetUUID()

0 commit comments

Comments
 (0)