Skip to content

Commit

Permalink
Add editable option
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Dec 10, 2024
1 parent 2b69582 commit d06d646
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions crates/pixi-build/src/bin/pixi-build-python/build_script.j2
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{% set PYTHON="%PYTHON%" if build_platform == "windows" else "$PYTHON" -%}
{% set SRC_DIR="%SRC_DIR%" if build_platform == "windows" else "$SRC_DIR" -%}
{% set SRC_DIR = editable if editable is not none else ("%SRC_DIR%" if build_platform == "windows" else "$SRC_DIR") -%}
{% set EDITABLE_OPTION = " --editable" if editable is not none else "" -%}
{% set COMMON_OPTIONS = "-vv --no-deps --no-build-isolation" + EDITABLE_OPTION -%}

{% if installer == "uv" -%}
uv pip install --python {{ PYTHON }} -vv --no-deps --no-build-isolation {{ SRC_DIR }}
uv pip install --python {{ PYTHON }} {{ COMMON_OPTIONS }} {{ SRC_DIR }}
{% else %}
{{ PYTHON }} -m pip install -vv --ignore-installed --no-deps --no-build-isolation {{ SRC_DIR }}
{{ PYTHON }} -m pip install --ignore-installed {{ COMMON_OPTIONS }} {{ SRC_DIR }}
{% endif -%}

{% if build_platform == "windows" -%}
Expand Down
3 changes: 3 additions & 0 deletions crates/pixi-build/src/bin/pixi-build-python/build_script.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::path::PathBuf;

use minijinja::Environment;
use serde::Serialize;

#[derive(Serialize)]
pub struct BuildScriptContext {
pub installer: Installer,
pub build_platform: BuildPlatform,
pub editable: Option<PathBuf>,
}

#[derive(Default, Serialize)]
Expand Down
57 changes: 34 additions & 23 deletions crates/pixi-build/src/bin/pixi-build-python/python.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use std::{
borrow::Cow,
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
};

use chrono::Utc;
use itertools::Itertools;
use jsonrpc_core::serde_json;
Expand Down Expand Up @@ -48,6 +40,13 @@ use rattler_conda_types::{
use rattler_package_streaming::write::CompressionLevel;
use rattler_virtual_packages::VirtualPackageOverrides;
use reqwest::Url;
use std::{
borrow::Cow,
collections::BTreeMap,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
};

use crate::{
build_script::{BuildPlatform, BuildScriptContext, Installer},
Expand Down Expand Up @@ -183,6 +182,7 @@ impl PythonBuildBackend {
&self,
host_platform: Platform,
channel_config: &ChannelConfig,
editable: Option<PathBuf>,
) -> miette::Result<Recipe> {
let manifest_root = self
.manifest
Expand Down Expand Up @@ -230,18 +230,14 @@ impl PythonBuildBackend {
} else {
BuildPlatform::Unix
},
editable: editable.clone(),
}
.render();

Ok(Recipe {
schema_version: 1,
package: Package {
version: package.version.clone().into(),
name,
},
context: Default::default(),
cache: None,
source: vec![Source::Path(PathSource {
let source = if editable.is_some() {
Vec::new()
} else {
Vec::from([Source::Path(PathSource {
// TODO: How can we use a git source?
path: manifest_root.to_path_buf(),
sha256: None,
Expand All @@ -250,7 +246,18 @@ impl PythonBuildBackend {
target_directory: None,
file_name: None,
use_gitignore: true,
})],
})])
};

Ok(Recipe {
schema_version: 1,
package: Package {
version: package.version.clone().into(),
name,
},
context: Default::default(),
cache: None,
source,
build: Build {
number: build_number,
string: Default::default(),
Expand Down Expand Up @@ -468,7 +475,7 @@ impl Protocol for PythonBuildBackend {
}

// TODO: Determine how and if we can determine this from the manifest.
let recipe = self.recipe(host_platform, &channel_config)?;
let recipe = self.recipe(host_platform, &channel_config, None)?;
let output = Output {
build_configuration: self
.build_configuration(
Expand Down Expand Up @@ -561,9 +568,13 @@ impl Protocol for PythonBuildBackend {
miette::bail!("the project does not support the target platform ({host_platform})");
}

todo!("Do something with params.editable");
//todo!("Do something with params.editable");

let recipe = self.recipe(host_platform, &channel_config)?;
let recipe = self.recipe(
host_platform,
&channel_config,
params.editable.map(|p| p.into()),

Check failure on line 576 in crates/pixi-build/src/bin/pixi-build-python/python.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

useless conversion to the same type: `std::path::PathBuf`
)?;
let output = Output {
build_configuration: self
.build_configuration(&recipe, channels, None, None, &params.work_directory)
Expand Down Expand Up @@ -659,7 +670,7 @@ mod tests {

let channel_config = ChannelConfig::default_with_root_dir(tmp_dir.path().to_path_buf());
python_backend
.recipe(Platform::current(), &channel_config)
.recipe(Platform::current(), &channel_config, None)
.unwrap()
}

Expand Down Expand Up @@ -757,7 +768,7 @@ mod tests {

insta::assert_yaml_snapshot!(reqs);

let recipe = python_backend.recipe(host_platform, &channel_config);
let recipe = python_backend.recipe(host_platform, &channel_config, None);
insta::assert_yaml_snapshot!(recipe.unwrap(), {
".source[0].path" => "[ ... path ... ]",
".build.script" => "[ ... script ... ]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ mod tests {
outputs: None,
work_directory: current_dir.into_path(),
variant_configuration: None,
editable: false,
editable: None,
})
.await
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi-build/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async fn build(factory: impl ProtocolFactory, manifest_path: &Path) -> miette::R
outputs: None,
work_directory: work_dir.path().to_path_buf(),
variant_configuration: None,
editable: false,
editable: None,
})
.await?;

Expand Down

0 comments on commit d06d646

Please sign in to comment.