Skip to content

Commit 075bd07

Browse files
committed
Refactor: move workspace registry to core
This allows for adding a new type of `DiscoverStart` that uses the workspace registry to find the pixi manifest.
1 parent 3593bef commit 075bd07

11 files changed

Lines changed: 44 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pixi_api/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ rattler_repodata_gateway = { workspace = true, features = [
3939
regex = { workspace = true }
4040
same-file = { workspace = true }
4141
serde = { workspace = true, features = ["derive"] }
42-
serde_ignored = { workspace = true }
4342
strsim = { workspace = true }
4443
tempfile = { workspace = true }
4544
tokio = { workspace = true, features = ["fs"] }
46-
toml_edit = { workspace = true, features = ["serde"] }
4745
tracing = { workspace = true }
4846
url = { workspace = true }
4947
uv-normalize = { workspace = true }

crates/pixi_api/src/workspace/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ pub(crate) mod task;
1818
#[allow(clippy::module_inception)]
1919
pub(crate) mod workspace;
2020
pub use workspace::channel::ChannelOptions;
21-
22-
pub(crate) mod registry;
23-
pub use registry::WorkspaceRegistry;

crates/pixi_cli/src/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use pixi_api::workspace::WorkspaceRegistry;
21
use pixi_consts::consts;
32
use pixi_core::WorkspaceLocator;
3+
use pixi_core::workspace::WorkspaceRegistry;
44
use pixi_manifest::EnvironmentName;
55
use std::path::PathBuf;
66
use std::time::Duration;

crates/pixi_cli/src/cli_config.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use indexmap::IndexSet;
55
use itertools::Itertools;
66
use miette::IntoDiagnostic;
77
use pep508_rs::Requirement;
8-
use pixi_api::workspace::WorkspaceRegistry;
98
use pixi_build_frontend::BackendOverride;
109
use pixi_config::Config;
1110
use pixi_consts::consts;
@@ -48,12 +47,7 @@ impl WorkspaceConfig {
4847
if let Some(manifest_path) = &self.manifest_path {
4948
DiscoveryStart::ExplicitManifest(manifest_path.clone())
5049
} else if let Some(workspace) = &self.workspace {
51-
let workspace_registry =
52-
WorkspaceRegistry::load().expect("Unable to load workspace registry");
53-
let path = workspace_registry
54-
.named_workspace(workspace)
55-
.expect("Unable to find workspace");
56-
DiscoveryStart::ExplicitManifest(path)
50+
DiscoveryStart::WorkspaceRegistry(workspace.clone())
5751
} else {
5852
DiscoveryStart::CurrentDir
5953
}

crates/pixi_cli/src/workspace/register.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::path::PathBuf;
44
use crate::cli_config::WorkspaceConfig;
55
use clap::Parser;
66
use miette::IntoDiagnostic;
7-
use pixi_api::workspace::WorkspaceRegistry;
87
use pixi_core::WorkspaceLocator;
8+
use pixi_core::workspace::WorkspaceRegistry;
99

1010
/// Commands to manage the registry of workspaces. Default command will add a new workspace
1111
#[derive(Parser, Debug, Clone)]

crates/pixi_core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ rattler_solve = { workspace = true }
6868
rattler_virtual_packages = { workspace = true }
6969
rstest = { workspace = true }
7070
serde = { workspace = true }
71+
serde_ignored = { workspace = true }
7172
serde_json = { workspace = true }
7273
tabwriter = { workspace = true }
7374
tempfile = { workspace = true }

crates/pixi_core/src/workspace/discovery.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use pixi_manifest::{
1010
use thiserror::Error;
1111

1212
use crate::workspace::Workspace;
13+
use crate::workspace::WorkspaceRegistry;
1314

1415
/// Defines where the search for the workspace should start.
1516
#[derive(Debug, Clone, Default)]
@@ -30,6 +31,11 @@ pub enum DiscoveryStart {
3031
///
3132
/// If no manifest is found at the given path the search will abort.
3233
ExplicitManifest(PathBuf),
34+
35+
/// Search by name in the workspace registry.
36+
///
37+
/// If the name is not found in the registry, abort.
38+
WorkspaceRegistry(String),
3339
}
3440

3541
impl DiscoveryStart {
@@ -39,6 +45,14 @@ impl DiscoveryStart {
3945
DiscoveryStart::CurrentDir => std::env::current_dir(),
4046
DiscoveryStart::SearchRoot(path) => Ok(path.clone()),
4147
DiscoveryStart::ExplicitManifest(path) => Ok(path.clone()),
48+
DiscoveryStart::WorkspaceRegistry(name) => {
49+
let registry = WorkspaceRegistry::load()
50+
.map_err(|_| WorkspaceLocatorError::MissingRegistry())?;
51+
let path = registry
52+
.named_workspace(name)
53+
.map_err(|_| WorkspaceLocatorError::MissingWorkspace(name.clone()))?;
54+
Ok(path)
55+
}
4256
}
4357
}
4458
}
@@ -97,6 +111,19 @@ pub enum WorkspaceLocatorError {
97111
#[error(transparent)]
98112
#[diagnostic(transparent)]
99113
ExplicitManifestError(#[from] ExplicitManifestError),
114+
115+
#[error("unable to load the workspace registry")]
116+
MissingRegistry(),
117+
118+
#[error("could not find workspace '{}'", .0)]
119+
MissingWorkspace(String),
120+
}
121+
122+
impl From<WorkspaceLocatorError> for std::io::Error {
123+
fn from(err: WorkspaceLocatorError) -> Self {
124+
// Create a new std::io::Error, using Other kind and the source error
125+
std::io::Error::other(err)
126+
}
100127
}
101128

102129
impl WorkspaceLocator {
@@ -160,6 +187,14 @@ impl WorkspaceLocator {
160187
std::env::current_dir().map_err(WorkspaceLocatorError::CurrentDir)?,
161188
),
162189
DiscoveryStart::SearchRoot(path) => pixi_manifest::DiscoveryStart::SearchRoot(path),
190+
DiscoveryStart::WorkspaceRegistry(name) => {
191+
let registry = WorkspaceRegistry::load()
192+
.map_err(|_| WorkspaceLocatorError::MissingRegistry())?;
193+
let path = registry
194+
.named_workspace(&name)
195+
.map_err(|_| WorkspaceLocatorError::MissingWorkspace(name.clone()))?;
196+
pixi_manifest::DiscoveryStart::ExplicitManifest(path)
197+
}
163198
};
164199

165200
let discovery_source = discovery_start.root().to_path_buf();

crates/pixi_core/src/workspace/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod environment;
33
pub mod errors;
44
pub mod grouped_environment;
55
mod has_project_ref;
6+
pub mod registry;
67
mod repodata;
78
mod solve_group;
89
pub mod virtual_packages;
@@ -58,6 +59,7 @@ use rattler_lock::{LockFile, LockedPackageRef};
5859
use rattler_networking::{LazyClient, s3_middleware};
5960
use rattler_repodata_gateway::Gateway;
6061
use rattler_virtual_packages::{VirtualPackageOverrides, VirtualPackages};
62+
pub use registry::WorkspaceRegistry;
6163
pub use solve_group::SolveGroup;
6264
use tokio::sync::Semaphore;
6365
use url::Url;

crates/pixi_api/src/workspace/registry/mod.rs renamed to crates/pixi_core/src/workspace/registry.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use std::collections::HashMap;
2-
3-
use miette::{Context, IntoDiagnostic};
4-
use serde::{Deserialize, Serialize};
5-
62
use std::path::PathBuf;
73

4+
use miette::{Context, IntoDiagnostic};
85
use pixi_config::pixi_home;
96
use pixi_consts::consts;
7+
use serde::{Deserialize, Serialize};
108

119
/// Returns the path to the workspace registry file
1210
pub fn workspace_registry_path() -> Option<PathBuf> {
@@ -161,7 +159,6 @@ mod tests {
161159
assert_eq!(result.unwrap(), path);
162160
}
163161

164-
165162
#[test]
166163
fn test_named_workspace_not_found() {
167164
let registry = WorkspaceRegistry::default();

0 commit comments

Comments
 (0)