File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 11hwi >= 2.1.1 ,< 3
22protobuf == 3.20.1
3+ requests >= 2.27.1
Original file line number Diff line number Diff line change 11use std:: ops:: Deref ;
2+ use std:: process:: Command ;
23
34use bitcoin:: consensus:: encode:: serialize;
45use bitcoin:: util:: bip32:: DerivationPath ;
@@ -362,4 +363,37 @@ impl HWIClient {
362363 status. into ( )
363364 } )
364365 }
366+
367+ /// Get the installed version of hwilib. Returns None if hwi is not installed.
368+ pub fn get_version ( ) -> Option < String > {
369+ Python :: with_gil ( |py| {
370+ Some (
371+ PyModule :: import ( py, "hwilib" )
372+ . ok ( ) ?
373+ . getattr ( "__version__" )
374+ . expect ( "Should have a __version__" )
375+ . to_string ( ) ,
376+ )
377+ } )
378+ }
379+
380+ /// Install hwi for the current user via pip. If no version is specified, the default version from pip will be installed.
381+ pub fn install_hwilib ( version : Option < & str > ) -> Result < ( ) , Error > {
382+ let hwi_with_version = match version {
383+ Some ( ver) => "hwi==" . to_owned ( ) + ver,
384+ None => "hwi" . to_owned ( ) ,
385+ } ;
386+ let output = Command :: new ( "pip" )
387+ . args ( vec ! [ "install" , "--user" , hwi_with_version. as_str( ) ] )
388+ . output ( ) ?;
389+ if output. status . success ( ) {
390+ Ok ( ( ) )
391+ } else {
392+ Err ( Error :: HWIError (
393+ std:: str:: from_utf8 ( & output. stderr )
394+ . expect ( "Non UTF-8 error while installing" )
395+ . to_string ( ) ,
396+ ) )
397+ }
398+ }
365399}
Original file line number Diff line number Diff line change @@ -306,6 +306,11 @@ mod tests {
306306 break ;
307307 }
308308 }
309+ #[ test]
310+ #[ serial]
311+ fn test_get_version ( ) {
312+ HWIClient :: get_version ( ) . unwrap ( ) ;
313+ }
309314
310315 #[ test]
311316 #[ serial]
@@ -322,4 +327,10 @@ mod tests {
322327 client. wipe_device ( ) . unwrap ( ) ;
323328 }
324329 }
330+ #[ test]
331+ #[ serial]
332+ #[ ignore]
333+ fn test_install_hwi ( ) {
334+ HWIClient :: install_hwilib ( Some ( "2.1.1" ) ) . unwrap ( ) ;
335+ }
325336}
You can’t perform that action at this time.
0 commit comments