Skip to content
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

feat: move pixi build type conversions into its own crate #2866

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ zstd = { version = "0.13.2", default-features = false }

fancy_display = { path = "crates/fancy_display" }
pixi_build_frontend = { path = "crates/pixi_build_frontend" }
pixi_build_type_conversions = { path = "crates/pixi_build_type_conversions" }
pixi_build_types = { path = "crates/pixi_build_types" }
pixi_config = { path = "crates/pixi_config" }
pixi_consts = { path = "crates/pixi_consts" }
Expand Down
6 changes: 2 additions & 4 deletions crates/pixi_build_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ version = "0.1.0"
dashmap = { workspace = true }
fs-err = { workspace = true, features = ["tokio"] }
futures = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
jsonrpsee = { workspace = true, features = ["client"] }
miette = { workspace = true, features = ["fancy", "serde"] }
pixi_build_type_conversions = { workspace = true }
pixi_build_types = { path = "../pixi_build_types" }
pixi_config = { workspace = true }
pixi_consts = { workspace = true }
pixi_manifest = { workspace = true }
Expand Down Expand Up @@ -44,9 +45,6 @@ url = "2.5.4"
which = { workspace = true }


pixi_build_types = { path = "../pixi_build_types" }


[dev-dependencies]
bytes = { workspace = true }
insta = { workspace = true, features = ["yaml", "filters", "json"] }
Expand Down
2 changes: 0 additions & 2 deletions crates/pixi_build_frontend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod backend_override;
mod build_frontend;
mod into_build_types;
mod jsonrpc;
pub mod protocol;
mod protocols;
Expand All @@ -25,7 +24,6 @@ use url::Url;
pub use crate::protocol::Protocol;

pub use backend_override::BackendOverride;
pub use into_build_types::to_project_model_v1;
pub use protocol_builder::EnabledProtocols;

/// A backend communication protocol that can run in the same process.
Expand Down
7 changes: 3 additions & 4 deletions crates/pixi_build_frontend/src/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use jsonrpsee::{
},
types::ErrorCode,
};
use pixi_build_type_conversions::to_project_model_v1;
use pixi_manifest::PackageManifest;

use crate::{
jsonrpc::{stdio_transport, RpcParams},
to_project_model_v1,
tool::Tool,
CondaBuildReporter, CondaMetadataReporter,
};
Expand All @@ -31,7 +31,7 @@ use pixi_build_types::{
conda_metadata::{CondaMetadataParams, CondaMetadataResult},
initialize::{InitializeParams, InitializeResult},
},
BackendCapabilities, FrontendCapabilities, VersionedProjectModel,
BackendCapabilities, FrontendCapabilities,
};
use stderr::{stderr_null, stderr_stream};
use thiserror::Error;
Expand Down Expand Up @@ -228,8 +228,7 @@ impl JsonRPCBuildProtocol {
})?;

// TODO: select the correct protocol version based on the capabilities
let project_model = package_manifest
.map(|manifest| VersionedProjectModel::V1(to_project_model_v1(manifest)));
let project_model = package_manifest.map(to_project_model_v1);
// Invoke the initialize method on the backend to establish the connection.
let _result: InitializeResult = client
.request(
Expand Down
22 changes: 22 additions & 0 deletions crates/pixi_build_type_conversions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
authors.workspace = true
description = "Conversions from pixi manifest types into build build protocol types"
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "pixi_build_type_conversions"
readme.workspace = true
repository.workspace = true
version = "0.1.0"

[dependencies]
indexmap = { workspace = true }
pixi_build_types = { workspace = true }
pixi_manifest = { workspace = true }
pixi_spec = { workspace = true }
rattler_conda_types = { workspace = true }
serde_json = { workspace = true }

[dev-dependencies]
insta = { workspace = true, features = ["json"] }
rstest = { workspace = true }
3 changes: 3 additions & 0 deletions crates/pixi_build_type_conversions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod project_model;

pub use project_model::to_project_model_v1;
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ fn to_targets_v1(targets: &Targets<PackageTarget>) -> pbt::TargetsV1 {
}

/// Converts a [`PackageManifest`] to a [`pbt::ProjectModelV1`].
pub fn to_project_model_v1(manifest: &PackageManifest) -> pbt::ProjectModelV1 {
pbt::ProjectModelV1 {
pub fn to_project_model_v1(manifest: &PackageManifest) -> pbt::VersionedProjectModel {
let project = pbt::ProjectModelV1 {
name: manifest.package.name.clone(),
version: manifest.package.version.clone(),
description: manifest.package.description.clone(),
Expand All @@ -122,7 +122,8 @@ pub fn to_project_model_v1(manifest: &PackageManifest) -> pbt::ProjectModelV1 {
documentation: manifest.package.documentation.clone(),
configuration: serde_json::Value::Null,
targets: to_targets_v1(&manifest.targets),
}
};
pbt::VersionedProjectModel::V1(project)
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
source: crates/pixi_build_type_conversions/src/project_model.rs
expression: project_model
---
{
"version": "1",
"name": "python_bindings",
"version": "0.1.0",
"description": null,
"authors": null,
"license": null,
"license_file": null,
"readme": null,
"homepage": null,
"repository": null,
"documentation": null,
"configuration": null,
"targets": {
"default_target": {
"host_dependencies": {
"cmake": {
"detailedVersion": {
"version": ">=3.20,<3.27",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
},
"nanobind": {
"detailedVersion": {
"version": ">=2.4.0,<2.5.0",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
},
"python_abi": {
"detailedVersion": {
"version": ">=3.12,<3.13",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
},
"build_dependencies": {},
"run_dependencies": {
"python": {
"detailedVersion": {
"version": ">=3.12,<3.13",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
}
},
"targets": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: crates/pixi_build_type_conversions/src/project_model.rs
expression: project_model
---
{
"version": "1",
"name": "rich_example",
"version": "0.1.0",
"description": null,
"authors": null,
"license": null,
"license_file": null,
"readme": null,
"homepage": null,
"repository": null,
"documentation": null,
"configuration": null,
"targets": {
"default_target": {
"host_dependencies": {
"hatchling": {
"detailedVersion": {
"version": "==1.26.3",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
},
"build_dependencies": {},
"run_dependencies": {
"rich": {
"detailedVersion": {
"version": ">=13.9.4,<14",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
}
},
"targets": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: crates/pixi_build_type_conversions/src/project_model.rs
expression: project_model
---
{
"version": "1",
"name": "rich_example",
"version": "0.1.0",
"description": null,
"authors": null,
"license": null,
"license_file": null,
"readme": null,
"homepage": null,
"repository": null,
"documentation": null,
"configuration": null,
"targets": {
"default_target": {
"host_dependencies": {
"hatchling": {
"detailedVersion": {
"version": "==1.26.3",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
},
"build_dependencies": {},
"run_dependencies": {
"rich": {
"detailedVersion": {
"version": ">=13.9.4,<14",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
}
},
"targets": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
source: crates/pixi_build_type_conversions/src/project_model.rs
expression: project_model
---
{
"version": "1",
"name": "boltons",
"version": "0.1.0",
"description": "Add a short description here",
"authors": [
"nichmor <[email protected]>"
],
"license": null,
"license_file": null,
"readme": null,
"homepage": null,
"repository": null,
"documentation": null,
"configuration": null,
"targets": {
"default_target": {
"host_dependencies": {
"hatchling": {
"detailedVersion": {
"version": "*",
"build": null,
"build_number": null,
"file_name": null,
"channel": null,
"subdir": null,
"md5": null,
"sha256": null
}
}
},
"build_dependencies": {},
"run_dependencies": {}
},
"targets": {}
}
}
Loading
Loading