@@ -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 => / ^ V e r s i o n : \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+
367409function ShowUUID ( ) {
368410 vscode . window . showInputBox ( {
369411 value : platform . GetUUID ( )
0 commit comments