Module deps

Module deps 

Source
Expand description

Dependency parsing and resolution utilities for Arch Linux packages.

This module provides a comprehensive set of functions and types for working with Arch Linux package dependencies, including parsing, version comparison, package querying, dependency resolution, and reverse dependency analysis.

§Features

This module is enabled with the deps feature flag:

[dependencies]
arch-toolkit = { version = "0.1.2", features = ["deps"] }

Some functions require the aur feature for AUR integration:

[dependencies]
arch-toolkit = { version = "0.1.2", features = ["deps", "aur"] }

§Overview

The deps module provides:

  • Parsing: Parse dependency specifications, pacman output, .SRCINFO files, and PKGBUILD files
  • Version Comparison: Compare package versions using pacman-compatible algorithms
  • Package Querying: Query installed packages, upgradable packages, and package versions
  • Dependency Resolution: Resolve dependencies for packages from official repos, AUR, or local packages
  • Reverse Dependency Analysis: Find all packages that depend on a given package

All functions gracefully degrade when pacman is unavailable, returning empty sets or None as appropriate rather than failing.

§Examples

§Parsing Dependency Specifications

use arch_toolkit::deps::parse_dep_spec;

let spec = parse_dep_spec("python>=3.12");
assert_eq!(spec.name, "python");
assert_eq!(spec.version_req, ">=3.12");

§Parsing .SRCINFO Files

use arch_toolkit::deps::parse_srcinfo;

let srcinfo_content = r#"
pkgbase = my-package
pkgname = my-package
pkgver = 1.0.0
pkgrel = 1
depends = glibc
depends = python>=3.10
"#;

let data = parse_srcinfo(srcinfo_content);
assert_eq!(data.pkgname, "my-package");
assert!(data.depends.contains(&"glibc".to_string()));

§Parsing PKGBUILD Files

use arch_toolkit::deps::parse_pkgbuild_deps;

let pkgbuild = r#"
depends=('glibc' 'python>=3.10')
makedepends=('rust' 'cargo')
"#;

let (deps, makedeps, checkdeps, optdeps) = parse_pkgbuild_deps(pkgbuild);
assert!(deps.contains(&"glibc".to_string()));

§Version Comparison

use arch_toolkit::deps::version_satisfies;

assert!(version_satisfies("2.0", ">=1.5"));
assert!(!version_satisfies("1.0", ">=1.5"));

§Querying Installed Packages

use arch_toolkit::deps::get_installed_packages;

let installed = get_installed_packages().unwrap();
println!("Found {} installed packages", installed.len());

§Dependency Resolution

use arch_toolkit::deps::DependencyResolver;
use arch_toolkit::{PackageRef, PackageSource};

let resolver = DependencyResolver::new();
let packages = vec![
    PackageRef {
        name: "firefox".into(),
        version: "121.0".into(),
        source: PackageSource::Official {
            repo: "extra".into(),
            arch: "x86_64".into(),
        },
    },
];

let result = resolver.resolve(&packages).unwrap();
println!("Found {} dependencies", result.dependencies.len());

§Reverse Dependency Analysis

use arch_toolkit::deps::ReverseDependencyAnalyzer;
use arch_toolkit::{PackageRef, PackageSource};

let analyzer = ReverseDependencyAnalyzer::new();
let packages = vec![
    PackageRef {
        name: "qt5-base".into(),
        version: "5.15.10".into(),
        source: PackageSource::Official {
            repo: "extra".into(),
            arch: "x86_64".into(),
        },
    },
];

let report = analyzer.analyze(&packages).unwrap();
println!("{} packages would be affected", report.dependents.len());

§Fetching .SRCINFO from AUR (requires aur feature)

use arch_toolkit::deps::fetch_srcinfo;
use reqwest::Client;

let client = Client::new();
let srcinfo = fetch_srcinfo(&client, "yay").await?;
let data = arch_toolkit::deps::parse_srcinfo(&srcinfo);
println!("Package: {}", data.pkgname);

§Example Programs

See the following example programs for more comprehensive usage:

Re-exports§

pub use crate::types::dependency::DependencyResolution;
pub use crate::types::dependency::ResolverConfig;
pub use crate::types::dependency::ReverseDependencyReport;
pub use crate::types::dependency::ReverseDependencySummary;

Structs§

DependencyResolver
Dependency resolver for batch package operations.
ReverseDependencyAnalyzer
Reverse dependency analyzer for removal operations.

Functions§

batch_fetch_official_deps
What: Batch fetch dependency lists for multiple official packages using pacman -Si.
compare_versions
What: Compare two version strings using pacman-compatible algorithm.
determine_dependency_source
What: Infer the origin repository for a dependency currently under analysis.
determine_status
What: Evaluate a dependency’s installation status relative to required versions.
extract_major_component
What: Extract the leading numeric component from a version string.
fetch_package_conflicts
What: Fetch conflicts for a package from pacman or AUR sources.
fetch_srcinfo
What: Fetch .SRCINFO content for an AUR package using async HTTP.
get_available_version
What: Query the repositories for the latest available version of a package.
get_installed_packages
What: Enumerate all currently installed packages on the system.
get_installed_required_by
What: Get the list of installed packages that depend on a package.
get_installed_version
What: Retrieve the locally installed version of a package.
get_provided_packages
What: Build an empty provides set (for API compatibility).
get_upgradable_packages
What: Collect names of packages that have upgrades available via pacman.
has_installed_required_by
What: Check if a package has any installed packages in its “Required By” field.
is_major_version_bump
What: Determine whether a new version constitutes a major version bump.
is_package_installed_or_provided
What: Check if a package is installed or provided by an installed package.
is_system_package
What: Identify whether a dependency belongs to a curated list of critical system packages.
parse_dep_spec
What: Split a dependency specification into name and version requirement.
parse_pacman_si_conflicts
What: Extract conflict specifications from pacman -Si “Conflicts With” field.
parse_pacman_si_deps
What: Extract dependency specifications from pacman -Si “Depends On” field.
parse_pkgbuild_conflicts
What: Parse conflicts from PKGBUILD content.
parse_pkgbuild_deps
What: Parse dependencies from PKGBUILD content.
parse_srcinfo
What: Parse full .SRCINFO content into structured data.
parse_srcinfo_conflicts
What: Parse conflicts from .SRCINFO content.
parse_srcinfo_deps
What: Parse dependencies from .SRCINFO content.
version_satisfies
What: Check if a version satisfies a version requirement.