File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-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 ;
@@ -360,4 +361,38 @@ impl HWIClient {
360361 status. into ( )
361362 } )
362363 }
364+
365+ /// Get installed version of hwilib. Returns None if not found, or if version couldn't be known
366+ pub fn get_version ( ) -> Option < String > {
367+ match || -> Result < String , Error > {
368+ Python :: with_gil ( |py| {
369+ Ok ( PyModule :: import ( py, "hwilib" ) ?
370+ . getattr ( "__version__" ) ?
371+ . to_string ( ) )
372+ } )
373+ } ( ) {
374+ Ok ( s) => Some ( s) ,
375+ Err ( _) => None ,
376+ }
377+ }
378+
379+ /// Install hwi for the current user via pip. If no version is specified, the default version from pip will be installed.
380+ pub fn install_hwilib ( version : Option < & str > ) -> Result < ( ) , Error > {
381+ let hwi_with_version = match version {
382+ Some ( ver) => "hwi==" . to_owned ( ) + ver,
383+ None => "hwi" . to_owned ( ) ,
384+ } ;
385+ let output = Command :: new ( "pip" )
386+ . args ( vec ! [ "install" , "--user" , hwi_with_version. as_str( ) ] )
387+ . output ( ) ?;
388+ if output. status . success ( ) {
389+ Ok ( ( ) )
390+ } else {
391+ Err ( Error :: HWIError (
392+ std:: str:: from_utf8 ( & output. stderr )
393+ . expect ( "Non UTF-8 error while installing" )
394+ . to_string ( ) ,
395+ ) )
396+ }
397+ }
363398}
Original file line number Diff line number Diff line change @@ -304,6 +304,11 @@ mod tests {
304304 break ;
305305 }
306306 }
307+ #[ test]
308+ #[ serial]
309+ fn test_get_version ( ) {
310+ HWIClient :: get_version ( ) . unwrap ( ) ;
311+ }
307312
308313 #[ test]
309314 #[ serial]
@@ -320,4 +325,10 @@ mod tests {
320325 client. wipe_device ( ) . unwrap ( ) ;
321326 }
322327 }
328+ #[ test]
329+ #[ serial]
330+ #[ ignore]
331+ fn test_install_hwi ( ) {
332+ HWIClient :: install_hwilib ( Some ( "2.1.1" ) ) . unwrap ( ) ;
333+ }
323334}
You can’t perform that action at this time.
0 commit comments