Skip to main content

uv_types/
requirements.rs

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