- This is a bump of stack overflow question.
I am using compile time inline-python and would like to use python v-env for building and testing.
Referring that a python v-env is activated by the following shell script, I believe it should be done by prepending the location of v-env/bin
to the existing PATH
for compile time and reverting on the competition.
...
VIRTUAL_ENV="/Users/<some-path>/<cargo-project>/venv"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
...
Would it be a good way to go for the purpose? If so, how am I supposed to do this?
--- EDIT 23.02.13-1. This is necessary because when I print out the path and import the path like below with a test, they direct system root python.
#[cfg(test)]
mod tests {
use std::env;
use ct_python::ct_python;
static python_bin: &'static str = ct_python! {
import sys
print('"' + "{}".format(sys.executable) + '"')
};
static python_path: &'static str = ct_python! {
import sys
print('"' + "{}".format(sys.path) + '"')
};
#[test]
fn venv_test() {
match env::var("VIRTUAL_ENV") {
Ok(v) => println!("{}", v),
Err(e) => println!("{}", e)
}
}
#[test]
fn path_print_test() {
println!("bin: {}", python_bin);
println!("path: {}", python_path);
}
}
output:
running 1 test
bin: /Users/<username>/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/rustc
path: ['/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages', '/opt/homebrew/opt/python-tk@3.10/libexec']
test signal_proc::tests::path_print_test ... ok
I believe the output of the sys.path
should be ./venv/bin
in order to use arbitrary python libraries and it has to be "prepending" of PATH only for the cargo.