Skip to main content

uv_types/
requirements.rs

1use uv_distribution_types::{Requirement, Resolution};
2use uv_normalize::{ExtraName, PackageName};
3use uv_pep440::Version;
4
5use crate::HashStrategy;
6
7/// A resolved set of requirements, along with the hash policy discovered while resolving them.
8#[derive(Debug, Clone)]
9pub struct ResolvedRequirements {
10    /// The resolved distributions to install.
11    resolution: Resolution,
12    /// The hash policy to apply when installing the resolution.
13    hasher: HashStrategy,
14}
15
16impl ResolvedRequirements {
17    /// Instantiate a [`ResolvedRequirements`] with the given [`Resolution`] and [`HashStrategy`].
18    pub fn new(resolution: Resolution, hasher: HashStrategy) -> Self {
19        Self { resolution, hasher }
20    }
21
22    /// Return the resolved distributions to install.
23    pub fn resolution(&self) -> &Resolution {
24        &self.resolution
25    }
26
27    /// Return the hash policy to apply when installing the resolution.
28    pub fn hasher(&self) -> &HashStrategy {
29        &self.hasher
30    }
31}
32
33/// A set of requirements as requested by a parent requirement.
34///
35/// For example, given `flask[dotenv]`, the `RequestedRequirements` would include the `dotenv`
36/// extra, along with all of the requirements that are included in the `flask` distribution
37/// including their unevaluated markers.
38#[derive(Debug, Clone)]
39pub struct RequestedRequirements {
40    /// The package that requested the requirements.
41    package: PackageName,
42    /// The version of the package that requested the requirements.
43    version: Version,
44    /// The set of extras included on the originating requirement.
45    extras: Box<[ExtraName]>,
46    /// The set of requirements that were requested by the originating requirement.
47    requirements: Box<[Requirement]>,
48    /// Whether the dependencies were direct or transitive.
49    direct: bool,
50}
51
52impl RequestedRequirements {
53    /// Instantiate a [`RequestedRequirements`] with the given `extras` and `requirements`.
54    pub fn new(
55        package: PackageName,
56        version: Version,
57        extras: Box<[ExtraName]>,
58        requirements: Box<[Requirement]>,
59        direct: bool,
60    ) -> Self {
61        Self {
62            package,
63            version,
64            extras,
65            requirements,
66            direct,
67        }
68    }
69
70    /// Return the package that requested the requirements.
71    pub fn package(&self) -> &PackageName {
72        &self.package
73    }
74
75    /// Return the package version that requested the requirements.
76    pub fn version(&self) -> &Version {
77        &self.version
78    }
79
80    /// Return the extras that were included on the originating requirement.
81    pub fn extras(&self) -> &[ExtraName] {
82        &self.extras
83    }
84
85    /// Return the requirements that were included on the originating requirement.
86    pub fn requirements(&self) -> &[Requirement] {
87        &self.requirements
88    }
89
90    /// Return whether the dependencies were direct or transitive.
91    pub fn direct(&self) -> bool {
92        self.direct
93    }
94}