File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed 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,35 @@ impl HWIClient {
360361 status. into ( )
361362 } )
362363 }
364+
365+ /// Get installed version of hwilib
366+ pub fn get_version ( ) -> Result < String , Error > {
367+ Python :: with_gil ( |py| {
368+ Ok ( PyModule :: import ( py, "hwilib" ) ?
369+ . getattr ( "__version__" ) ?
370+ . to_string ( ) )
371+ } )
372+ }
373+
374+ /// Install hwi for the current user via pip
375+ /// # Arguments
376+ /// * `version` - the version of hwi to be installed. Installs default version from pip if not specified
377+ pub fn install_hwilib ( version : Option < & str > ) -> Result < ( ) , Error > {
378+ let hwi_with_version = match version {
379+ Some ( ver) => "hwi==" . to_owned ( ) + ver,
380+ None => "hwi" . to_owned ( ) ,
381+ } ;
382+ let output = Command :: new ( "pip" )
383+ . args ( vec ! [ "install" , "--user" , hwi_with_version. as_str( ) ] )
384+ . output ( ) ?;
385+ if output. status . success ( ) {
386+ Ok ( ( ) )
387+ } else {
388+ Err ( Error :: HWIError (
389+ std:: str:: from_utf8 ( & output. stderr )
390+ . expect ( "Unknown Error while installing" )
391+ . to_string ( ) ,
392+ ) )
393+ }
394+ }
363395}
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