Skip to content

Commit

Permalink
misc: add WIP code here
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed Nov 28, 2024
1 parent 7787729 commit cb0bf4b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 35 deletions.
42 changes: 36 additions & 6 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jsonrpc-core = "18.0.0"

url = "2.5.3"

fs_extra = "1.3.0"

rattler-build = { git = "https://github.com/prefix-dev/rattler-build", branch = "main", default-features = false }

rattler_conda_types = { version = "0.29.1", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions crates/pixi-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jsonrpc-stdio-server = { workspace = true }
jsonrpc-http-server = { workspace = true }
jsonrpc-core = { workspace = true }
log = "0.4.22"
fs_extra = { workspace = true}
tracing-test = "0.2.5"
tracing = "0.1.41"
130 changes: 101 additions & 29 deletions crates/pixi-build/src/bin/pixi-build-python/python.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::{

Check warning on line 1 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
borrow::Cow, collections::BTreeMap, path::{Path, PathBuf}, str::FromStr, sync::Arc
};

use chrono::Utc;
use indexmap::IndexMap;
use miette::{Context, IntoDiagnostic};
use pixi_build_backend::{
dependencies::MatchspecExtractor,
Expand Down Expand Up @@ -102,24 +100,14 @@ impl PythonBuildBackend {
channel_config: &ChannelConfig,

Check warning on line 100 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
) -> miette::Result<(Requirements, Installer)> {
let mut requirements = Requirements::default();
let default_features = [self.manifest.default_feature()];

// Get all different feature types
let run_dependencies = Dependencies::from(
default_features
.iter()
.filter_map(|f| f.dependencies(SpecType::Run, Some(host_platform))),
);
let mut host_dependencies = Dependencies::from(
default_features
.iter()
.filter_map(|f| f.dependencies(SpecType::Host, Some(host_platform))),
);
let build_dependencies = Dependencies::from(
default_features
.iter()
.filter_map(|f| f.dependencies(SpecType::Build, Some(host_platform))),
);
let package = self.manifest.package.clone().ok_or_else(|| miette::miette!("manifest {} does not contains [package] section", self.manifest.path.display()))?;

let default_features = package.targets.default();

let run_dependencies = default_features.run_dependencies().cloned().unwrap_or_else(|| IndexMap::new());
let build_dependencies = default_features.build_dependencies().cloned().unwrap_or_else(|| IndexMap::new());
let mut host_dependencies = default_features.host_dependencies().cloned().unwrap_or_else(|| IndexMap::new());


// Determine the installer to use
let installer = if host_dependencies.contains_key("uv")
Expand All @@ -141,9 +129,7 @@ impl PythonBuildBackend {

Check warning on line 129 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
if let Some(run_requirements) = run_dependencies.get(pkg_name) {
// Copy the run requirements to the host requirements.
for req in run_requirements {
host_dependencies.insert(PackageName::from_str(pkg_name).unwrap(), req.clone());
}
host_dependencies.insert(PackageName::from_str(pkg_name).unwrap(), run_requirements.clone());
} else {
host_dependencies.insert(
PackageName::from_str(pkg_name).unwrap(),
Expand All @@ -152,25 +138,44 @@ impl PythonBuildBackend {
}
}

let mut build_deps = Dependencies::default();

Check warning on line 141 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
let mut run_deps = Dependencies::default();
let mut host_deps = Dependencies::default();

for build_dep in build_dependencies.iter(){
build_deps.insert(build_dep.0.clone(), build_dep.1.clone());
}

for run_dep in run_dependencies.iter(){

Check warning on line 149 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
run_deps.insert(run_dep.0.clone(), run_dep.1.clone());
}

for host_dep in host_dependencies.iter(){

Check warning on line 153 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
host_deps.insert(host_dep.0.clone(), host_dep.1.clone());
}


Check warning on line 157 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs

requirements.build = MatchspecExtractor::new(channel_config.clone())
.with_ignore_self(true)
.extract(build_dependencies)?
.extract(build_deps)?
.into_iter()
.map(Dependency::Spec)
.collect();
requirements.host = MatchspecExtractor::new(channel_config.clone())
.with_ignore_self(true)
.extract(host_dependencies)?
.extract(host_deps)?
.into_iter()
.map(Dependency::Spec)
.collect();
requirements.run = MatchspecExtractor::new(channel_config.clone())
.with_ignore_self(true)
.extract(run_dependencies)?
.extract(run_deps)?
.into_iter()
.map(Dependency::Spec)
.collect();

eprintln!("requirements: {:?}", requirements);
Ok((requirements, installer))
}

Expand Down Expand Up @@ -247,7 +252,7 @@ impl PythonBuildBackend {
// dynamic_linking: Default::default(),
// always_copy_files: Default::default(),
// always_include_files: Default::default(),
// merge_build_and_host_envs: false,
merge_build_and_host_envs: true,
// variant: Default::default(),
// prefix_detection: Default::default(),
// post_process: vec![],
Expand Down Expand Up @@ -569,3 +574,70 @@ impl ProtocolFactory for PythonBuildBackendFactory {
Ok((instance, InitializeResult { capabilities }))
}

Check warning on line 575 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
}


#[cfg(test)]
mod tests {
use std::{fs, path::PathBuf, str::FromStr};
use fs_extra;
use pixi_build_backend::protocol::{Protocol, ProtocolFactory};
use pixi_build_types::{procedures::{conda_build::CondaBuildParams, initialize::InitializeParams}, ChannelConfiguration, FrontendCapabilities};
use rattler_build::console_utils::LoggingOutputHandler;
use tempfile::tempdir;
use tracing_test::traced_test;
use url::Url;

Check warning on line 589 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
use crate::python::PythonBuildBackend;



#[tokio::test]
async fn test_python_respect_host_dependencies() {
// get cargo manifest dir
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let boltons_folder = manifest_dir.join("../../tests/examples/boltons");

let tmp_project = tempdir().unwrap();
let boltons_tmp_project = tmp_project.path();

// copy boltons example to boltons_tmp_project

let _ = std::fs::create_dir_all(&boltons_tmp_project);

Check warning on line 605 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/pixi-build-backends/pixi-build-backends/crates/pixi-build/src/bin/pixi-build-python/python.rs
let mut copy_options = fs_extra::dir::CopyOptions::new().copy_inside(false);


let _ = fs_extra::dir::copy(&boltons_folder, &boltons_tmp_project, &copy_options).unwrap();



let factory = PythonBuildBackend::factory(LoggingOutputHandler::default())
.initialize(InitializeParams {
manifest_path: boltons_tmp_project.join("boltons").join("pixi.toml"),
capabilities: FrontendCapabilities {},
cache_directory: None,
})
.await
.unwrap();

let current_dir = tempdir().unwrap();

let result = factory
.0
.build_conda(CondaBuildParams {
build_platform_virtual_packages: None,
host_platform: None,
channel_base_urls: None,
channel_configuration: ChannelConfiguration {
base_url: Url::from_str("https://fast.prefix.dev").unwrap(),
},
outputs: None,
work_directory: current_dir.into_path(),
})
.await
.unwrap();

eprintln!("{:?}", result);
// assert_eq!(result.packages[0].name, "boltons-with-extra");
}

}

0 comments on commit cb0bf4b

Please sign in to comment.