1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use std::collections::BTreeSet;
use tracing::debug;
use uv_normalize::PackageName;
/// Minimal view of a package used to apply install filters.
#[derive(Debug, Clone, Copy)]
pub struct InstallTarget<'a> {
/// The package name.
pub name: &'a PackageName,
/// Whether the package refers to a local source (path, directory, editable, etc.).
pub is_local: bool,
}
#[derive(Debug, Clone, Default)]
pub struct InstallOptions {
/// Omit the project itself from the resolution.
pub no_install_project: bool,
/// Include only the project itself in the resolution.
pub only_install_project: bool,
/// Omit all workspace members (including the project itself) from the resolution.
pub no_install_workspace: bool,
/// Include only workspace members (including the project itself) in the resolution.
pub only_install_workspace: bool,
/// Omit all local packages from the resolution.
pub no_install_local: bool,
/// Include only local packages in the resolution.
pub only_install_local: bool,
/// Omit the specified packages from the resolution.
pub no_install_package: Vec<PackageName>,
/// Include only the specified packages in the resolution.
pub only_install_package: Vec<PackageName>,
}
impl InstallOptions {
#[allow(clippy::fn_params_excessive_bools)]
pub fn new(
no_install_project: bool,
only_install_project: bool,
no_install_workspace: bool,
only_install_workspace: bool,
no_install_local: bool,
only_install_local: bool,
no_install_package: Vec<PackageName>,
only_install_package: Vec<PackageName>,
) -> Self {
Self {
no_install_project,
only_install_project,
no_install_workspace,
only_install_workspace,
no_install_local,
only_install_local,
no_install_package,
only_install_package,
}
}
/// Returns `true` if a package passes the install filters.
pub fn include_package(
&self,
target: InstallTarget<'_>,
project_name: Option<&PackageName>,
members: &BTreeSet<PackageName>,
) -> bool {
let package_name = target.name;
// If `--only-install-package` is set, only include specified packages.
if !self.only_install_package.is_empty() {
if self.only_install_package.contains(package_name) {
return true;
}
debug!("Omitting `{package_name}` from resolution due to `--only-install-package`");
return false;
}
// If `--only-install-local` is set, only include local packages.
if self.only_install_local {
if target.is_local {
return true;
}
debug!("Omitting `{package_name}` from resolution due to `--only-install-local`");
return false;
}
// If `--only-install-workspace` is set, only include the project and workspace members.
if self.only_install_workspace {
// Check if it's the project itself
if let Some(project_name) = project_name {
if package_name == project_name {
return true;
}
}
// Check if it's a workspace member
if members.contains(package_name) {
return true;
}
// Otherwise, exclude it
debug!("Omitting `{package_name}` from resolution due to `--only-install-workspace`");
return false;
}
// If `--only-install-project` is set, only include the project itself.
if self.only_install_project {
if let Some(project_name) = project_name {
if package_name == project_name {
return true;
}
}
debug!("Omitting `{package_name}` from resolution due to `--only-install-project`");
return false;
}
// If `--no-install-project` is set, remove the project itself.
if self.no_install_project {
if let Some(project_name) = project_name {
if package_name == project_name {
debug!(
"Omitting `{package_name}` from resolution due to `--no-install-project`"
);
return false;
}
}
}
// If `--no-install-workspace` is set, remove the project and any workspace members.
if self.no_install_workspace {
// In some cases, the project root might be omitted from the list of workspace members
// encoded in the lockfile. (But we already checked this above if `--no-install-project`
// is set.)
if !self.no_install_project {
if let Some(project_name) = project_name {
if package_name == project_name {
debug!(
"Omitting `{package_name}` from resolution due to `--no-install-workspace`"
);
return false;
}
}
}
if members.contains(package_name) {
debug!("Omitting `{package_name}` from resolution due to `--no-install-workspace`");
return false;
}
}
// If `--no-install-local` is set, remove local packages.
if self.no_install_local {
if target.is_local {
debug!("Omitting `{package_name}` from resolution due to `--no-install-local`");
return false;
}
}
// If `--no-install-package` is provided, remove the requested packages.
if self.no_install_package.contains(package_name) {
debug!("Omitting `{package_name}` from resolution due to `--no-install-package`");
return false;
}
true
}
}