From 5d1646503aa615d6d552b54f9ce80143fb46ae94 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 16 Jul 2026 10:55:48 +0700 Subject: [PATCH] python: Add pyprojectpath and pipflags --- src/cook/cook_build.rs | 15 ++++++++++++--- src/cook/script.rs | 8 ++++++-- src/recipe.rs | 4 ++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index a5bc44907..2b45f79f4 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -390,13 +390,22 @@ pub fn build( "DYNAMIC_INIT\n{}cookbook_meson", flags_fn("COOKBOOK_MESON_FLAGS", mesonflags), ), - BuildKind::Python { legacysetup } => format!( - "DYNAMIC_INIT\n{}cookbook_python", + BuildKind::Python { + pyprojectpath, + legacysetup, + pipflags, + } => format!( + "DYNAMIC_INIT\n{}{}{}cookbook_python", if *legacysetup { "COOKBOOK_PYTHON_LEGACY_SETUP=1\n" } else { "" - } + }, + pyprojectpath + .as_ref() + .map(|s| format!("COOKBOOK_PYTHON_PYPROJECT_PATH={s}\n")) + .unwrap_or("".into()), + flags_fn("COOKBOOK_PYTHON_PIP_FLAGS", pipflags), ), BuildKind::Custom { script } => script.clone(), BuildKind::Remote => unreachable!(), diff --git a/src/cook/script.rs b/src/cook/script.rs index 009d449e6..5a1433e65 100644 --- a/src/cook/script.rs +++ b/src/cook/script.rs @@ -359,6 +359,9 @@ function PYTHON_INIT { export PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}${COOKBOOK_SYSROOT}/usr/lib/${COOKBOOK_PYTHON_V}/site-packages" export _PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__${SYSTEM}_${ARCH}-${OS}" } +COOKBOOK_PYTHON_PIP_FLAGS=( + --ignore-installed --no-index --no-build-isolation +) function cookbook_python { PYTHON_INIT # no way to do out-of-tree build: https://github.com/pypa/setuptools/issues/3237 @@ -366,8 +369,9 @@ function cookbook_python { if [ -n "${COOKBOOK_PYTHON_LEGACY_SETUP}" ]; then python3 ./source/setup.py install fi - "${COOKBOOK_PYTHON}" -m pip install --prefix="${COOKBOOK_STAGE}/usr" "./source" \ - --ignore-installed --no-index --no-build-isolation "$@" + "${COOKBOOK_PYTHON}" -m pip install --prefix="${COOKBOOK_STAGE}/usr" \ + "./source${COOKBOOK_PYTHON_PYPROJECT_PATH:+/$COOKBOOK_PYTHON_PYPROJECT_PATH}" \ + "${COOKBOOK_PYTHON_PIP_FLAGS[@]}" "$@" rsync -av "${COOKBOOK_BUILD}/${COOKBOOK_STAGE}/usr/" "${COOKBOOK_STAGE}/usr" } "#; diff --git a/src/recipe.rs b/src/recipe.rs index 5c9c0323f..408944da7 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -106,6 +106,10 @@ pub enum BuildKind { /// Will build and install using python pip #[serde(rename = "python")] Python { + #[serde(default)] + pyprojectpath: Option, + #[serde(default)] + pipflags: Vec, /// Some recipes need to run setup.py, /// other does not allow running setup.py. /// This defaults to not run setup.py, but if build result in error,