-
Notifications
You must be signed in to change notification settings - Fork 400
feat(pixi_api): Implement task support for WorkspaceContext #4667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4fc75b3
feat(pixi_api): Implement list_tasks, simplify pixi_api module structure
haecker-felix 830f8ab
Drop no longer needed crate visibility
haecker-felix f81d84e
feat(pixi_api): Implement remove_tasks
haecker-felix 2e85fd0
chore: Expose workspace field, rename workspace_context -> workspace_ctx
haecker-felix 976ef68
feat(pixi_api): Implement add_task
haecker-felix a850f3b
feat(pixi_api): Implement alias_task
haecker-felix 2fcd810
Replace print leftover with interface
haecker-felix db6dc52
Merge branch 'main' into pixi_api_tasks
haecker-felix 72c915c
Reexport pixi_manifest / rattler_conda_types as well
haecker-felix f0fce2f
Make task serializable
haecker-felix e179001
Return workspace reference instead of cloning
haecker-felix 789d5c2
reference workspace instead of cloning it
haecker-felix 83af6c0
Add a new workspace_mut method to WorkspaceContext
haecker-felix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| pub mod workspace; | ||
|
|
||
| pub mod context; | ||
| pub mod interface; | ||
| mod context; | ||
| pub use context::WorkspaceContext; | ||
|
|
||
| mod interface; | ||
| pub use interface::Interface; | ||
|
|
||
| // Reexport for pixi_api consumers | ||
| pub use pixi_core as core; | ||
| pub use pixi_manifest as manifest; | ||
| pub use rattler_conda_types; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| pub mod init; | ||
| pub mod reinstall; | ||
| pub(crate) mod init; | ||
| pub use init::{GitAttributes, InitOptions, ManifestFormat}; | ||
|
|
||
| pub(crate) mod reinstall; | ||
| pub use reinstall::ReinstallOptions; | ||
|
|
||
| pub(crate) mod task; | ||
|
|
||
| #[allow(clippy::module_inception)] | ||
| pub mod workspace; | ||
| pub(crate) mod workspace; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| use std::collections::{HashMap, HashSet}; | ||
|
|
||
| use fancy_display::FancyDisplay; | ||
| use miette::IntoDiagnostic; | ||
| use pixi_core::{ | ||
| Workspace, | ||
| workspace::{Environment, virtual_packages::verify_current_platform_can_run_environment}, | ||
| }; | ||
| use pixi_manifest::{EnvironmentName, FeatureName, Task, TaskName}; | ||
| use rattler_conda_types::Platform; | ||
|
|
||
| use crate::interface::Interface; | ||
|
|
||
| pub async fn list_tasks<I: Interface>( | ||
| _interface: &I, | ||
| workspace: Workspace, | ||
| environment: Option<EnvironmentName>, | ||
| ) -> miette::Result<HashMap<EnvironmentName, HashMap<TaskName, Task>>> { | ||
| let explicit_environment = environment | ||
| .map(|n| { | ||
| workspace | ||
| .environment(&n) | ||
| .ok_or_else(|| miette::miette!("unknown environment '{n}'")) | ||
| }) | ||
| .transpose()?; | ||
|
|
||
| let lockfile = workspace.load_lock_file().await.ok(); | ||
|
|
||
| let env_task_map: HashMap<Environment, HashSet<TaskName>> = | ||
| if let Some(explicit_environment) = explicit_environment { | ||
| HashMap::from([( | ||
| explicit_environment.clone(), | ||
| explicit_environment.get_filtered_tasks(), | ||
| )]) | ||
| } else { | ||
| workspace | ||
| .environments() | ||
| .iter() | ||
| .filter_map(|env| { | ||
| if verify_current_platform_can_run_environment(env, lockfile.as_ref()).is_ok() { | ||
| Some((env.clone(), env.get_filtered_tasks())) | ||
| } else { | ||
| None | ||
| } | ||
| }) | ||
| .collect() | ||
| }; | ||
|
|
||
| Ok(env_task_map | ||
| .into_iter() | ||
| .map(|(env, task_names)| { | ||
| let env_name = env.name().clone(); | ||
| let best_platform = env.best_platform(); | ||
| let task_map = task_names | ||
| .into_iter() | ||
| .flat_map(|task_name| { | ||
| env.task(&task_name, Some(best_platform)) | ||
| .ok() | ||
| .map(|task| (task_name, task.clone())) | ||
| }) | ||
| .collect(); | ||
| (env_name, task_map) | ||
| }) | ||
| .collect()) | ||
| } | ||
|
|
||
| pub async fn add_task<I: Interface>( | ||
| interface: &I, | ||
| workspace: Workspace, | ||
| name: TaskName, | ||
| task: Task, | ||
| feature: FeatureName, | ||
| platform: Option<Platform>, | ||
| ) -> miette::Result<()> { | ||
| let mut workspace = workspace.modify()?; | ||
|
|
||
| workspace | ||
| .manifest() | ||
| .add_task(name.clone(), task.clone(), platform, &feature)?; | ||
| workspace.save().await.into_diagnostic()?; | ||
|
|
||
| interface | ||
| .success(&format!( | ||
| "Added task `{}`: {}", | ||
| name.fancy_display().bold(), | ||
| task, | ||
| )) | ||
| .await; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn alias_task<I: Interface>( | ||
| interface: &I, | ||
| workspace: Workspace, | ||
| name: TaskName, | ||
| task: Task, | ||
| platform: Option<Platform>, | ||
| ) -> miette::Result<()> { | ||
| let mut workspace = workspace.modify()?; | ||
|
|
||
| workspace | ||
| .manifest() | ||
| .add_task(name.clone(), task.clone(), platform, &FeatureName::DEFAULT)?; | ||
| workspace.save().await.into_diagnostic()?; | ||
|
|
||
| interface | ||
| .success(&format!( | ||
| "Added alias `{}`: {}", | ||
| name.fancy_display().bold(), | ||
| task, | ||
| )) | ||
| .await; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn remove_tasks<I: Interface>( | ||
| interface: &I, | ||
| workspace: Workspace, | ||
| names: Vec<TaskName>, | ||
| platform: Option<Platform>, | ||
| feature: FeatureName, | ||
| ) -> miette::Result<()> { | ||
| let mut workspace = workspace.modify()?; | ||
| let mut to_remove = Vec::new(); | ||
|
|
||
| for name in names.iter() { | ||
| if let Some(platform) = platform { | ||
| if !workspace | ||
| .workspace() | ||
| .workspace | ||
| .value | ||
| .tasks(Some(platform), &feature)? | ||
| .contains_key(name) | ||
| { | ||
| interface | ||
| .error(&format!( | ||
| "Task '{}' does not exist on {}", | ||
| name.fancy_display().bold(), | ||
| console::style(platform.as_str()).bold(), | ||
| )) | ||
| .await; | ||
| continue; | ||
| } | ||
| } else if !workspace | ||
| .workspace() | ||
| .workspace | ||
| .value | ||
| .tasks(None, &feature)? | ||
| .contains_key(name) | ||
| { | ||
| interface | ||
| .error(&format!( | ||
| "Task `{}` does not exist for the `{}` feature", | ||
| name.fancy_display().bold(), | ||
| console::style(&feature).bold(), | ||
| )) | ||
| .await; | ||
| continue; | ||
| } | ||
|
|
||
| // Safe to remove | ||
| to_remove.push((name, platform)); | ||
| } | ||
|
|
||
| let mut removed = Vec::with_capacity(to_remove.len()); | ||
| for (name, platform) in to_remove { | ||
| workspace | ||
| .manifest() | ||
| .remove_task(name.clone(), platform, &feature)?; | ||
| removed.push(name); | ||
| } | ||
|
|
||
| workspace.save().await.into_diagnostic()?; | ||
|
|
||
| for name in removed { | ||
| interface | ||
| .success(&format!("Removed task `{}` ", name.fancy_display().bold())) | ||
| .await; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.