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 @@ -244,6 +244,11 @@ mod tests {
244244 break ;
245245 }
246246 }
247+ #[ test]
248+ #[ serial]
249+ fn test_get_version ( ) {
250+ HWIClient :: get_version ( ) . unwrap ( ) ;
251+ }
247252
248253 #[ test]
249254 #[ serial]
@@ -260,4 +265,10 @@ mod tests {
260265 client. wipe_device ( ) . unwrap ( ) ;
261266 }
262267 }
268+ #[ test]
269+ #[ serial]
270+ #[ ignore]
271+ fn test_install_hwi ( ) {
272+ HWIClient :: install_hwilib ( Some ( "2.1.1" ) ) . unwrap ( ) ;
273+ }
263274}
You can’t perform that action at this time.
0 commit comments