Skip to content

Commit d99e552

Browse files
committed
Back out workspace registry information in pixi global config
1 parent f6bd821 commit d99e552

4 files changed

Lines changed: 14 additions & 85 deletions

File tree

crates/pixi_cli/src/clean.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pixi_config::{self, Config};
1+
use pixi_api::workspace::WorkspaceRegistry;
22
use pixi_consts::consts;
33
use pixi_core::WorkspaceLocator;
44
use pixi_manifest::EnvironmentName;
@@ -229,37 +229,21 @@ async fn clean_cache(args: CacheArgs) -> miette::Result<()> {
229229
Ok(())
230230
}
231231

232-
fn global_config_write_path() -> miette::Result<PathBuf> {
233-
let mut global_locations = pixi_config::config_path_global();
234-
let mut to = global_locations
235-
.pop()
236-
.expect("should have at least one global config path");
237-
238-
for p in global_locations {
239-
if p.exists() {
240-
to = p;
241-
break;
242-
}
243-
}
244-
Ok(to)
245-
}
246-
247232
/// Clean disassociated workspaces from the workspace registry
248233
async fn clean_workspaces() -> miette::Result<()> {
249-
let mut config = Config::load_global();
250-
let to = global_config_write_path()?;
251-
let mut workspaces = config.named_workspaces.clone();
252-
253-
workspaces.retain(|key, val| {
254-
if val.exists() {
255-
true
256-
} else {
257-
eprintln!("{} {}", console::style("removed workspace").green(), key);
258-
false
259-
}
260-
});
261-
config.named_workspaces = workspaces;
262-
config.save(&to)?;
234+
let mut workspace_registry = WorkspaceRegistry::load()?;
235+
let workspace_map = workspace_registry.named_workspaces_map();
236+
237+
let names_to_remove: Vec<_> = workspace_map
238+
.iter()
239+
.filter(|(_, path)| !path.exists())
240+
.map(|(name, _)| name.clone())
241+
.collect();
242+
243+
for name in names_to_remove {
244+
workspace_registry.remove_workspace(&name).await?;
245+
eprintln!("{} {}", console::style("removed workspace").green(), name);
246+
}
263247
eprintln!(
264248
"{} Workspace registry cleaned",
265249
console::style(console::Emoji("✔ ", "")).green(),

crates/pixi_cli/src/workspace/register.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ pub enum Command {
5151
/// Remove a workspace from registry.
5252
#[clap(visible_alias = "rm")]
5353
Remove(RemoveArgs),
54-
// Prune disassociated workspaces from registry.
55-
// #[clap(visible_alias = "pr")]
56-
// Prune(PruneArgs),
5754
}
5855

5956
pub async fn execute(args: Args) -> miette::Result<()> {
@@ -87,24 +84,6 @@ pub async fn execute(args: Args) -> miette::Result<()> {
8784
&remove_args.name
8885
);
8986
}
90-
// Some(Command::Prune(_)) => {
91-
// let workspace_registry = WorkspaceRegistry::load().await?;
92-
// let workspaces = workspace_registry.named_workspaces_map();
93-
// workspaces.retain(|key, val| {
94-
// if val.exists() {
95-
// true
96-
// } else {
97-
// eprintln!("{} {}", console::style("removed workspace").green(), key);
98-
// false
99-
// }
100-
// });
101-
// config.named_workspaces = workspaces;
102-
// config.save(&to)?;
103-
// eprintln!(
104-
// "{} Workspace registry cleaned",
105-
// console::style(console::Emoji("✔ ", "")).green(),
106-
// );
107-
// }
10887
None => {
10988
let workspace = WorkspaceLocator::for_cli()
11089
.with_closest_package(false)

crates/pixi_config/src/lib.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,6 @@ pub struct Config {
811811
#[serde(skip_serializing_if = "Option::is_none")]
812812
pub tool_platform: Option<Platform>,
813813

814-
/// Mapping of a named workspaces to the path of their manifest file.
815-
#[serde(default)]
816-
#[serde(skip_serializing_if = "HashMap::is_empty")]
817-
pub named_workspaces: HashMap<String, PathBuf>,
818-
819814
//////////////////////
820815
// Deprecated fields //
821816
//////////////////////
@@ -851,7 +846,6 @@ impl Default for Config {
851846
proxy_config: ProxyConfig::default(),
852847
build: BuildConfig::default(),
853848
tool_platform: None,
854-
named_workspaces: HashMap::new(),
855849

856850
// Deprecated fields
857851
change_ps1: None,
@@ -1386,7 +1380,6 @@ impl Config {
13861380
"experimental",
13871381
"experimental.use-environment-activation-cache",
13881382
"mirrors",
1389-
"named-workspaces",
13901383
"pinning-strategy",
13911384
"proxy-config",
13921385
"proxy-config.http",
@@ -1463,11 +1456,6 @@ impl Config {
14631456
proxy_config: self.proxy_config.merge(other.proxy_config),
14641457
build: self.build.merge(other.build),
14651458
tool_platform: self.tool_platform.or(other.tool_platform),
1466-
named_workspaces: self
1467-
.named_workspaces
1468-
.into_iter()
1469-
.merge(other.named_workspaces)
1470-
.collect(),
14711459

14721460
// Deprecated fields that we can ignore as we handle them inside `shell.` field
14731461
change_ps1: None,
@@ -1591,19 +1579,6 @@ impl Config {
15911579
Ok(result)
15921580
}
15931581

1594-
/// Retrieve the value for the named-workspaces field.
1595-
pub fn named_workspaces_map(&self) -> &std::collections::HashMap<String, PathBuf> {
1596-
&self.named_workspaces
1597-
}
1598-
1599-
/// Retrieve the path to the manifest file for a named workspaces.
1600-
pub fn named_workspace(&self, name: &String) -> miette::Result<PathBuf> {
1601-
match self.named_workspaces.get(name) {
1602-
Some(path) => Ok(path.clone()),
1603-
None => Err(miette::diagnostic!("Named workspace '{}' not found", name).into()),
1604-
}
1605-
}
1606-
16071582
/// Modify this config with the given key and value
16081583
///
16091584
/// # Note
@@ -1679,13 +1654,6 @@ impl Config {
16791654
.transpose()
16801655
.into_diagnostic()?;
16811656
}
1682-
"named-workspaces" => {
1683-
self.named_workspaces = value
1684-
.map(|v| serde_json::de::from_str(&v))
1685-
.transpose()
1686-
.into_diagnostic()?
1687-
.unwrap_or_default();
1688-
}
16891657
key if key.starts_with("repodata-config") => {
16901658
if key == "repodata-config" {
16911659
self.repodata_config = value
@@ -2353,7 +2321,6 @@ UNUSED = "unused"
23532321
proxy_config: ProxyConfig::default(),
23542322
build: BuildConfig::default(),
23552323
tool_platform: None,
2356-
named_workspaces: HashMap::new(),
23572324
// Deprecated keys
23582325
change_ps1: None,
23592326
force_activate: None,

crates/pixi_consts/src/consts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub const CACHED_PACKAGES: &str = "pkgs";
4646
pub const CACHED_BUILD_BACKEND_METADATA: &str = "metadata";
4747
pub const CACHED_SOURCE_METADATA: &str = "source_metadata";
4848
pub const CACHED_SOURCE_BUILDS: &str = "pkgs";
49-
pub const DEFAULT_GLOBAL_WORKSPACE_DIR: &str = "workspaces";
5049
pub const WORKSPACES_REGISTRY: &str = "workspaces.toml";
5150

5251
/// The directory relative to the .pixi folder that stores build related caches.

0 commit comments

Comments
 (0)