feat(pipx support): Fully supports pipx features
Now able to support packages installed via pipx with the exception of packages that do not provide a binary themselves. Install those explicitly via `pipx install --include-deps <package>`. Signed-off-by: innocentzero <isfarulhaque@proton.me>
This commit is contained in:
@@ -40,7 +40,18 @@ impl Backend for Python {
|
|||||||
let output = run_pip_command(&mut cmd, self.get_switches_runtime())?;
|
let output = run_pip_command(&mut cmd, self.get_switches_runtime())?;
|
||||||
match self.get_binary(){
|
match self.get_binary(){
|
||||||
"pip" => extract_pacdef_packages(output),
|
"pip" => extract_pacdef_packages(output),
|
||||||
"pipx" => extract_pacdef_packages_pipx(output),
|
"pipx" => {
|
||||||
|
let packs = extract_pacdef_packages_pipx(&output);
|
||||||
|
let deps = extract_pacdef_packages_deps(&output);
|
||||||
|
match (packs, deps) {
|
||||||
|
(Ok(mut pack), Ok(deps)) => {
|
||||||
|
pack.extend(deps.into_iter());
|
||||||
|
Ok(pack)
|
||||||
|
}
|
||||||
|
(Ok(pack), Err(_)) => Ok(pack),
|
||||||
|
(Err(pack), _) => Err(pack),
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => panic!("Cannot use {} for package management in python. Please use a valid package manager like pip or pipx", self.get_binary()),
|
_ => panic!("Cannot use {} for package management in python. Please use a valid package manager like pip or pipx", self.get_binary()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +61,7 @@ impl Backend for Python {
|
|||||||
let output = run_pip_command(&mut cmd, self.get_switches_explicit())?;
|
let output = run_pip_command(&mut cmd, self.get_switches_explicit())?;
|
||||||
match self.get_binary(){
|
match self.get_binary(){
|
||||||
"pip" => extract_pacdef_packages(output),
|
"pip" => extract_pacdef_packages(output),
|
||||||
"pipx" => extract_pacdef_packages_pipx(output),
|
"pipx" => extract_pacdef_packages_pipx(&output),
|
||||||
_ => panic!("Cannot use {} for package management in python. Please use a valid package manager like pip or pipx", self.get_binary()),
|
_ => panic!("Cannot use {} for package management in python. Please use a valid package manager like pip or pipx", self.get_binary()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,7 +113,7 @@ fn extract_pacdef_packages(value: Value) -> Result<HashSet<Package>> {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_pacdef_packages_pipx(value: Value) -> Result<HashSet<Package>> {
|
fn extract_pacdef_packages_pipx(value: &Value) -> Result<HashSet<Package>> {
|
||||||
let result = value["venvs"]
|
let result = value["venvs"]
|
||||||
.as_object()
|
.as_object()
|
||||||
.context("getting inner json object")?
|
.context("getting inner json object")?
|
||||||
@@ -112,20 +123,23 @@ fn extract_pacdef_packages_pipx(value: Value) -> Result<HashSet<Package>> {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn extract_pacdef_packages_deps(value: Value) -> Result<HashSet<Package>> {
|
fn extract_pacdef_packages_deps(value: &Value) -> Result<HashSet<Package>> {
|
||||||
// let mut alldeps: HashSet<Package> = HashSet::new();
|
let mut alldeps: HashSet<Package> = HashSet::new();
|
||||||
//
|
let _ = value["venvs"]
|
||||||
// value["venvs"]
|
.as_object()
|
||||||
// .as_object()
|
.context("getting inner json object")?
|
||||||
// .context("getting inner json object")?
|
.iter()
|
||||||
// .iter()
|
.map(|(_, deps_obj)| -> Result<()> {
|
||||||
// .map(|(_, deps_obj)| {
|
let deps: HashSet<Package> = deps_obj["metadata"]["main_package"]
|
||||||
// let deps = deps_obj["metadata"]["main_package"]["apps_paths_of_dependencies"]
|
["apps_paths_of_dependencies"]
|
||||||
// .as_object()
|
.as_object()
|
||||||
// .iter()
|
.context("getting inner dependencies")?
|
||||||
// .map(|(name, _)| Package::from(name))
|
.iter()
|
||||||
// .collect();
|
.map(|(name, _)| Package::from(name.as_str()))
|
||||||
// alldeps.extend(&deps);
|
.collect();
|
||||||
// });
|
|
||||||
// Ok(alldeps)
|
alldeps.extend(deps);
|
||||||
// }
|
Ok(())
|
||||||
|
});
|
||||||
|
Ok(alldeps)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user