Skip to content

Commit 91d302a

Browse files
feat(pixi_api): Implement package search (#4910)
1 parent 7a7e9de commit 91d302a

File tree

9 files changed

+419
-280
lines changed

9 files changed

+419
-280
lines changed

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pixi/tests/integration_rust/search_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ async fn test_search_multiple_versions() {
203203
.replace("\x1b[1m", "")
204204
.replace("\x1b[2m", "");
205205

206-
assert_eq!(result.len(), 1);
207-
assert_eq!(result[0].package_record.version.as_str(), "0.2.0");
208-
assert_eq!(result[0].package_record.build, "h60d57d3_1");
206+
let latest_package = result.last().expect("should have at least one result");
207+
assert_eq!(latest_package.package_record.version.as_str(), "0.2.0");
208+
assert_eq!(latest_package.package_record.build, "h60d57d3_1");
209209
let output = output
210210
.lines()
211211
// Filter out URL line since temporary directory name is random.

crates/pixi_api/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ readme.workspace = true
88
repository.workspace = true
99
version = "0.1.0"
1010

11+
[features]
12+
default = []
13+
native-tls = ["rattler_repodata_gateway/native-tls"]
14+
rustls-tls = ["rattler_repodata_gateway/rustls-tls"]
15+
1116
[dependencies]
1217
console = { workspace = true }
1318
dunce = { workspace = true }
@@ -25,8 +30,15 @@ pixi_pypi_spec = { workspace = true }
2530
pixi_spec = { workspace = true }
2631
pixi_utils = { workspace = true }
2732
rattler_conda_types = { workspace = true }
33+
rattler_lock = { workspace = true }
34+
rattler_repodata_gateway = { workspace = true, features = [
35+
"sparse",
36+
"gateway",
37+
] }
38+
regex = { workspace = true }
2839
same-file = { workspace = true }
2940
serde = { workspace = true, features = ["derive"] }
41+
strsim = { workspace = true }
3042
tempfile = { workspace = true }
3143
tokio = { workspace = true, features = ["fs"] }
3244
tracing = { workspace = true }

crates/pixi_api/src/context.rs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,49 @@ use pixi_manifest::{
99
};
1010
use pixi_pypi_spec::{PixiPypiSpec, PypiPackageName};
1111
use pixi_spec::PixiSpec;
12-
use rattler_conda_types::{PackageName, Platform};
12+
use rattler_conda_types::{Channel, MatchSpec, PackageName, Platform, RepoDataRecord};
1313

1414
use crate::interface::Interface;
1515
use crate::workspace::{InitOptions, ReinstallOptions};
1616

17+
pub struct DefaultContext<I: Interface> {
18+
interface: I,
19+
}
20+
21+
impl<I: Interface> DefaultContext<I> {
22+
pub fn new(interface: I) -> Self {
23+
Self { interface }
24+
}
25+
26+
/// Returns all matching package versions sorted by version
27+
pub async fn search_exact(
28+
&self,
29+
match_spec: MatchSpec,
30+
channels: IndexSet<Channel>,
31+
platform: Platform,
32+
) -> miette::Result<Option<Vec<RepoDataRecord>>> {
33+
crate::workspace::search::search_exact(
34+
&self.interface,
35+
None,
36+
match_spec,
37+
channels,
38+
platform,
39+
)
40+
.await
41+
}
42+
43+
/// Returns all matching packages with their latest versions
44+
pub async fn search_wildcard(
45+
&self,
46+
search: &str,
47+
channels: IndexSet<Channel>,
48+
platform: Platform,
49+
) -> miette::Result<Option<Vec<RepoDataRecord>>> {
50+
crate::workspace::search::search_wildcard(&self.interface, None, search, channels, platform)
51+
.await
52+
}
53+
}
54+
1755
pub struct WorkspaceContext<I: Interface> {
1856
interface: I,
1957
workspace: Workspace,
@@ -172,4 +210,38 @@ impl<I: Interface> WorkspaceContext<I> {
172210
)
173211
.await
174212
}
213+
214+
/// Returns all matching package versions sorted by version
215+
pub async fn search_exact(
216+
&self,
217+
match_spec: MatchSpec,
218+
channels: IndexSet<Channel>,
219+
platform: Platform,
220+
) -> miette::Result<Option<Vec<RepoDataRecord>>> {
221+
crate::workspace::search::search_exact(
222+
&self.interface,
223+
Some(&self.workspace),
224+
match_spec,
225+
channels,
226+
platform,
227+
)
228+
.await
229+
}
230+
231+
/// Returns all matching packages with their latest versions
232+
pub async fn search_wildcard(
233+
&self,
234+
search: &str,
235+
channels: IndexSet<Channel>,
236+
platform: Platform,
237+
) -> miette::Result<Option<Vec<RepoDataRecord>>> {
238+
crate::workspace::search::search_wildcard(
239+
&self.interface,
240+
Some(&self.workspace),
241+
search,
242+
channels,
243+
platform,
244+
)
245+
.await
246+
}
175247
}

crates/pixi_api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod workspace;
22

33
mod context;
4-
pub use context::WorkspaceContext;
4+
pub use context::{DefaultContext, WorkspaceContext};
55

66
mod interface;
77
pub use interface::Interface;

crates/pixi_api/src/workspace/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
//! This module contains everything which is related to a Pixi workspace.
2+
13
pub(crate) mod init;
24
pub use init::{GitAttributes, InitOptions, ManifestFormat};
35

46
pub(crate) mod reinstall;
57
pub use reinstall::ReinstallOptions;
68

9+
pub(crate) mod search;
10+
711
pub(crate) mod task;
812

913
#[allow(clippy::module_inception)]

0 commit comments

Comments
 (0)