Skip to content

Commit fdf70dd

Browse files
authored
look for site packages using the 'site' module as a fallback (#68)
Signed-off-by: karthik2804 <karthik.ganeshram@fermyon.com>
1 parent 4ed31e3 commit fdf70dd

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/command.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct Componentize {
5757
/// directory will be searched for a `site-packages` subdirectory, which will be appended to the path as a
5858
/// convenience for `venv` users. Alternatively, if `pipenv` is in `$PATH` and `pipenv --venv` produces a
5959
/// non-empty result, it will be searched for a `site-packages` subdirectory, which will likewise be appended.
60+
/// If the previous options fail, the `site` module in python will be used to get the `site-packages`
6061
#[arg(short = 'p', long, default_value = ".")]
6162
pub python_path: Vec<String>,
6263

@@ -156,7 +157,18 @@ fn find_site_packages() -> Result<Option<PathBuf>> {
156157
}
157158
} else {
158159
// `pipenv` is in `$PATH`, but this app does not appear to be using it
159-
None
160+
// Get site packages location using the `site` module in python
161+
match process::Command::new("python3")
162+
.args(["-c", "import site; print(site.getsitepackages()[0])"])
163+
.output()
164+
{
165+
Ok(output) => {
166+
let path =
167+
Path::new(str::from_utf8(&output.stdout)?.trim()).to_path_buf();
168+
Some(path)
169+
}
170+
Err(_) => None,
171+
}
160172
}
161173
}
162174
Err(_) => {

0 commit comments

Comments
 (0)