Skip to content

Commit

Permalink
feat: add pixi project add system-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts committed Dec 24, 2024
1 parent a343eef commit 34ffee3
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 15 deletions.
1 change: 1 addition & 0 deletions crates/pixi_consts/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const ENVIRONMENTS_DIR: &str = "envs";
pub const SOLVE_GROUP_ENVIRONMENTS_DIR: &str = "solve-group-envs";
pub const PYPI_DEPENDENCIES: &str = "pypi-dependencies";
pub const DEPENDENCIES: &str = "dependencies";
pub const SYSTEM_REQUIREMENTS: &str = "system-requirements";
pub const TASK_CACHE_DIR: &str = "task-cache-v0";
pub const ACTIVATION_ENV_CACHE_DIR: &str = "activation-env-v0";
pub const PIXI_UV_INSTALLER: &str = "uv-pixi";
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_manifest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use preview::{KnownPreviewFeature, Preview, PreviewFeature};
pub use pypi::pypi_requirement::PyPiRequirement;
use rattler_conda_types::Platform;
pub use spec_type::SpecType;
pub use system_requirements::{LibCSystemRequirement, SystemRequirements};
pub use system_requirements::{LibCFamilyAndVersion, LibCSystemRequirement, SystemRequirements};
pub use target::{TargetSelector, Targets, WorkspaceTarget};
pub use task::{Task, TaskName};
use thiserror::Error;
Expand Down
34 changes: 32 additions & 2 deletions crates/pixi_manifest/src/manifests/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use crate::{
to_options,
toml::{ExternalWorkspaceProperties, TomlDocument, TomlManifest},
BuildSystem, DependencyOverwriteBehavior, Environment, EnvironmentName, Feature, FeatureName,
GetFeatureError, PrioritizedChannel, PypiDependencyLocation, SpecType, TargetSelector, Task,
TaskName, WorkspaceManifest, WorkspaceTarget,
GetFeatureError, PrioritizedChannel, PypiDependencyLocation, SpecType, SystemRequirements,
TargetSelector, Task, TaskName, WorkspaceManifest, WorkspaceTarget,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -667,6 +667,36 @@ impl Manifest {
Ok(())
}

/// Add a system requirement to the project
pub fn add_system_requirement(
&mut self,
system_requirements: SystemRequirements,
feature_name: &FeatureName,
) -> miette::Result<SystemRequirements> {
// Get the current system requirements
let current = match feature_name {
FeatureName::Default => &mut self.workspace.default_feature_mut().system_requirements,
FeatureName::Named(_) => {
&mut self
.get_or_insert_feature_mut(feature_name)
.system_requirements
}
};

// Replace the system requirements with the new ones
// All given requirements are replaced, all optional requirements are kept
let result = current.union(&system_requirements).into_diagnostic()?;

*current = result.clone();

// Update the TOML document
self.source
.add_system_requirements(&result, feature_name)
.into_diagnostic()?;

Ok(result)
}

/// Returns a mutable reference to a target, creating it if needed
pub fn get_or_insert_target_mut(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
channels = []
platforms = []

[environments]
foo = []
bar = ["not-default"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
[tool.pixi.project]
channels = []
platforms = []

[tool.pixi.environments]
foo = []
bar = ["not-default"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
channels = []
platforms = []

[system-requirements]
libc = { family = "glibc", version = "1.2" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
[tool.pixi.project]
channels = []
platforms = []

[tool.pixi.system-requirements]
libc = { family = "glibc", version = "1.2" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
channels = []
platforms = []

[system-requirements]
linux = "4.18"
cuda = "11.1"
macos = "13.0"
libc = "2.28"
archspec = "x86_64"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
[tool.pixi.project]
channels = []
platforms = []

[tool.pixi.system-requirements]
linux = "4.18"
cuda = "11.1"
macos = "13.0"
libc = "2.28"
archspec = "x86_64"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
channels = []
platforms = []

[system-requirements]
linux = "4.18"
cuda = "11.1"
macos = "13.0"
libc = { family = "glibc", version = "1.2" }
archspec = "x86_64"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
[tool.pixi.project]
channels = []
platforms = []

[tool.pixi.system-requirements]
linux = "4.18"
cuda = "11.1"
macos = "13.0"
libc = { family = "glibc", version = "1.2" }
archspec = "x86_64"
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
channels = []
platforms = []

[environments]
bar = ["default"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
---
source: crates/pixi_manifest/src/manifests/source.rs
expression: source.to_string()
snapshot_kind: text
---
[project]
name = "test"
[tool.pixi.project]
channels = []
platforms = []

[tool.pixi.environments]
bar = ["default"]
Loading

0 comments on commit 34ffee3

Please sign in to comment.