FIX refactored switches and output parsing
Removed inlined switches to a separate function for both explicit installs and all installs and added a match statement to parse the outputs accordingly. Signed-off-by: innocentzero <isfarulhaque@proton.me>
This commit is contained in:
@@ -38,18 +38,21 @@ impl Backend for Python {
|
|||||||
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
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(){
|
||||||
extract_pacdef_packages_pipx(output)
|
"pip" => extract_pacdef_packages(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()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
|
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
let output = run_pip_command(
|
let output = run_pip_command(&mut cmd, self.get_switches_explicit())?;
|
||||||
&mut cmd,
|
match self.get_binary(){
|
||||||
&["list", "--format", "json", "--not-required", "--user"],
|
"pip" => extract_pacdef_packages(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()),
|
||||||
extract_pacdef_packages_pipx(output)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_dependency(&self, _packages: &[Package]) -> Result<ExitStatus> {
|
fn make_dependency(&self, _packages: &[Package]) -> Result<ExitStatus> {
|
||||||
@@ -74,7 +77,14 @@ impl Python {
|
|||||||
|
|
||||||
fn get_switches_runtime(&self) -> Switches {
|
fn get_switches_runtime(&self) -> Switches {
|
||||||
match self.get_binary() {
|
match self.get_binary() {
|
||||||
"pip" => &["list", "--format", "json", "--user"],
|
"pip" => &["list", "--format", "json", "--not-required", "--user"],
|
||||||
|
"pipx" => &["list", "--json"],
|
||||||
|
_ => panic!("Cannot use {} for package management in python. Please use a valid package manager like pip or pipx", self.get_binary()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn get_switches_explicit(&self) -> Switches {
|
||||||
|
match self.get_binary() {
|
||||||
|
"pip" => &["list", "--format", "json", "--user", ""],
|
||||||
"pipx" => &["list", "--json"],
|
"pipx" => &["list", "--json"],
|
||||||
_ => 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()),
|
||||||
}
|
}
|
||||||
@@ -97,11 +107,25 @@ fn extract_pacdef_packages_pipx(value: Value) -> Result<HashSet<Package>> {
|
|||||||
.as_object()
|
.as_object()
|
||||||
.context("getting inner json object")?
|
.context("getting inner json object")?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, _)| {
|
.map(|(name, _)| Package::from(name.as_str()))
|
||||||
println!("{name}");
|
|
||||||
Package::from(name.as_str())
|
|
||||||
})
|
|
||||||
// .map(|(name, _)| Package::from(name.as_str()))
|
|
||||||
.collect();
|
.collect();
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fn extract_pacdef_packages_deps(value: Value) -> Result<HashSet<Package>> {
|
||||||
|
// let mut alldeps: HashSet<Package> = HashSet::new();
|
||||||
|
//
|
||||||
|
// value["venvs"]
|
||||||
|
// .as_object()
|
||||||
|
// .context("getting inner json object")?
|
||||||
|
// .iter()
|
||||||
|
// .map(|(_, deps_obj)| {
|
||||||
|
// let deps = deps_obj["metadata"]["main_package"]["apps_paths_of_dependencies"]
|
||||||
|
// .as_object()
|
||||||
|
// .iter()
|
||||||
|
// .map(|(name, _)| Package::from(name))
|
||||||
|
// .collect();
|
||||||
|
// alldeps.extend(&deps);
|
||||||
|
// });
|
||||||
|
// Ok(alldeps)
|
||||||
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user