mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-26 18:09:33 +00:00
* feat: add basic commands for communicating with keycard * initialize changes * reorganization * add script file for easier wallet access * update commands * fixes * fixed load for non continuous run * Updates for signatures with keycard * fix BIP-340 signatures for fixed sized messages * fmt * refactor and add pin support to program facades * fix unit test * fixes * Revert "fixes" This reverts commit 41f34f4ff4145b7abb60fd9bec168ae4b60f23b4. * fixes * fixes * Removed privacy keycard calls * Revert "Removed privacy keycard calls" This reverts commit d70ef505a1f40b87159099761f5fce5a31e3f17b. * Add domain separators * Removed privacy txs for keycard * CI fixes * CI fixes * addressed some comments * fix ci * ci fixes * fix integration test issue and updated keycard firmware * addressed more comments * fixed deny * remove keycard-py * fixed from earlier merge * add hash_message tests * add test * fix deny * CI fixes * fixed integration tests * Update public.rs * update artifacts * ci and comments * addressed comments * comment fixes * fixes from merging main * first round of comments * Revert "Merge branch 'main' into marvin/keycard-commands" This reverts commit 3fce53f663a3996938dddf77680854570063ca21, reversing changes made to e7b42a5177641455a8917bd2e29db20afd9690e5. * python comments * addressed comments * compile error fixed * fix artifacts * fix main merge error * adjust signer logic workflow * fmt * merge main and shift keycard tests * deny fix * artifacts fix * remove keycard scripts from root * tps fix * fmt
64 lines
2.1 KiB
Rust
64 lines
2.1 KiB
Rust
use std::{env, path::PathBuf};
|
|
|
|
use pyo3::{prelude::*, types::PyList};
|
|
|
|
/// Adds the project's `python/` directory and venv site-packages to Python's sys.path.
|
|
pub fn add_python_path(py: Python<'_>) -> PyResult<()> {
|
|
let current_dir = env::current_dir().expect("Failed to get current working directory");
|
|
|
|
let python_base = env::var("VIRTUAL_ENV")
|
|
.ok()
|
|
.and_then(|v| PathBuf::from(v).parent().map(PathBuf::from))
|
|
.unwrap_or_else(|| current_dir.clone());
|
|
|
|
let mut paths_to_add: Vec<PathBuf> = vec![
|
|
python_base.join("keycard_wallet").join("python"),
|
|
python_base
|
|
.join("keycard_wallet")
|
|
.join("python")
|
|
.join("keycard-py"),
|
|
];
|
|
|
|
// If a virtualenv is active, add its site-packages so that dependencies
|
|
// installed in the venv (e.g. smartcard, ecdsa) are importable by the
|
|
// pyo3 embedded interpreter, which does not inherit sys.path from the
|
|
// shell's `python3` executable.
|
|
if let Ok(venv) = env::var("VIRTUAL_ENV") {
|
|
let lib = PathBuf::from(&venv).join("lib");
|
|
if let Ok(entries) = std::fs::read_dir(&lib) {
|
|
for entry in entries.flatten() {
|
|
let site_packages = entry.path().join("site-packages");
|
|
if site_packages.exists() {
|
|
paths_to_add.push(site_packages);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Sanity check — warns early if a path doesn't exist
|
|
for path in &paths_to_add {
|
|
if !path.exists() {
|
|
log::info!("Warning: Python path does not exist: {}", path.display());
|
|
}
|
|
}
|
|
|
|
let sys = PyModule::import(py, "sys")?;
|
|
let binding = sys.getattr("path")?;
|
|
let sys_path = binding.downcast::<PyList>()?;
|
|
|
|
for path in &paths_to_add {
|
|
let path_str = path.to_str().expect("Invalid path");
|
|
|
|
// Avoid duplicating the path
|
|
let already_present = sys_path
|
|
.iter()
|
|
.any(|p| p.extract::<&str>().map(|s| s == path_str).unwrap_or(false));
|
|
|
|
if !already_present {
|
|
sys_path.insert(0, path_str)?;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|