Skip to content

Commit 79e0837

Browse files
Merge #34: Add build script
589c3cf Add functions for checking and installing hwi (wszdexdrf) Pull request description: I believe this should be all that is needed. I don't think we can install OS-level dependencies. For udev rules, it is possible but then we would have to duplicate/include_str the `install_udev_rules()` function in `build.rs` ACKs for top commit: danielabrozzoni: utACK 589c3cf Tree-SHA512: e7738f38f2d566ee2d62dc1152baa5c3d4c4415e61244b7c626b51d1dd8ad68871bece16fabc898ed8d25c2008354f4477de4e0bb4f96052621534c5642be17c
2 parents 48bc75d + 589c3cf commit 79e0837

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
hwi>=2.1.1,<3
22
protobuf==3.20.1
3+
requests>=2.27.1

src/interface.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::ops::Deref;
2+
use std::process::Command;
23

34
use bitcoin::consensus::encode::serialize;
45
use 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
}

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)