From 35b6bff5de363433a31378edddfd0b09bbfe7e08 Mon Sep 17 00:00:00 2001 From: Allemand Instable <68656923+code-instable@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:16:32 +0200 Subject: [PATCH 1/3] override radian python version to be same as in py_conf (+) function: set_radian_python_version_override (~) generate_wrapped_pkgs (+) added `py_conf` and `flag_py_conf` as arguments (+) added string format '%s' bellow the packages TODO: remove whitespaces and empty line when there is no py_conf --- R/rix.R | 4 +++- R/rix_helpers.R | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/R/rix.R b/R/rix.R index 293c2464..38b6a754 100644 --- a/R/rix.R +++ b/R/rix.R @@ -461,7 +461,9 @@ for more details." attrib, flag_git_archive, flag_rpkgs, - flag_local_r_pkgs + flag_local_r_pkgs, + py_conf, + flag_py_conf ), generate_shell( flag_git_archive, diff --git a/R/rix_helpers.R b/R/rix_helpers.R index 99fb811a..e5d30faf 100644 --- a/R/rix_helpers.R +++ b/R/rix_helpers.R @@ -425,7 +425,9 @@ generate_wrapped_pkgs <- function( attrib, flag_git_archive, flag_rpkgs, - flag_local_r_pkgs + flag_local_r_pkgs, + py_conf, + flag_py_conf ) { if (flag_rpkgs == "") { return(NULL) @@ -434,12 +436,15 @@ generate_wrapped_pkgs <- function( " wrapped_pkgs = pkgs.%s.override { packages = [ %s %s %s ]; + %s }; ", attrib[ide], flag_git_archive, flag_rpkgs, - flag_local_r_pkgs + flag_local_r_pkgs, + set_radian_python_version_override(py_conf, flag_py_conf ) + ) } else { NULL @@ -533,3 +538,15 @@ generate_set_reticulate <- function(py_conf, flag_py_conf) { paste0('RETICULATE_PYTHON = "${pkgs.', py_version, '}/bin/python";\n') } } + +set_radian_python_version_override <- function(py_conf, flag_py_conf){ + if (flag_py_conf == "") { + "" + } else { + py_version <- paste0( + "python", + gsub("\\.", "", py_conf$py_version) + ) + paste0('radian = pkgs.', py_version, 'Packages.radian;\n') + } +} From 493eac54aaa7f41a57cfbae9cfb74623b82a91fe Mon Sep 17 00:00:00 2001 From: Allemand Instable <68656923+code-instable@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:11:42 +0200 Subject: [PATCH 2/3] update function name to match other helpers --- R/rix_helpers.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/rix_helpers.R b/R/rix_helpers.R index e5d30faf..24e5ddd9 100644 --- a/R/rix_helpers.R +++ b/R/rix_helpers.R @@ -443,7 +443,7 @@ generate_wrapped_pkgs <- function( flag_git_archive, flag_rpkgs, flag_local_r_pkgs, - set_radian_python_version_override(py_conf, flag_py_conf ) + generate_radian_python_version_override(py_conf, flag_py_conf ) ) } else { @@ -539,7 +539,7 @@ generate_set_reticulate <- function(py_conf, flag_py_conf) { } } -set_radian_python_version_override <- function(py_conf, flag_py_conf){ +generate_radian_python_version_override <- function(py_conf, flag_py_conf){ if (flag_py_conf == "") { "" } else { From c8dc7ef074b593352710fd945873244f9e5d152a Mon Sep 17 00:00:00 2001 From: Allemand Instable <68656923+code-instable@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:12:39 +0200 Subject: [PATCH 3/3] add documentation --- R/rix_helpers.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/rix_helpers.R b/R/rix_helpers.R index 24e5ddd9..74ce824a 100644 --- a/R/rix_helpers.R +++ b/R/rix_helpers.R @@ -419,6 +419,11 @@ generate_locale_variables <- function() { #' @param flag_git_archive Character, are there R packages from GitHub at all? #' @param flag_rpkgs Character, are there any R packages at all? #' @param flag_local_r_pkgs Character, are there any local R packages at all? +#' @param py_conf List. A list of two elements, `py_version` and `py_conf`. +#' `py_version` must be of the form `"3.12"` for Python 3.12 and `py_conf` +#' must be an atomic vector of packages names, for example +#' `py_conf = c("polars", "plotnine", "great-tables")`. +#' @param flag_py_conf Character, are there any Python packages at all? #' @noRd generate_wrapped_pkgs <- function( ide, @@ -539,6 +544,13 @@ generate_set_reticulate <- function(py_conf, flag_py_conf) { } } +#' generate_radian_python_version_override Helper to set radian's python version to the same as the one from the python user-config in order to avoid reticulate falling back to radian's undesired python version +#' @param py_conf List. A list of two elements, `py_version` and `py_conf`. +#' `py_version` must be of the form `"3.12"` for Python 3.12 and `py_conf` +#' must be an atomic vector of packages names, for example +#' `py_conf = c("polars", "plotnine", "great-tables")`. +#' @param flag_py_conf Character, are there any Python packages at all? +#' @noRd generate_radian_python_version_override <- function(py_conf, flag_py_conf){ if (flag_py_conf == "") { ""