From f6ed3a064a426064754fb17733006699b9c29f4f Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Sun, 10 Nov 2024 04:37:19 +0000 Subject: [PATCH 1/2] updated uv path determinatino with uv v0.5.0 installing to ~/.local/bin/ instead of ~/.cargo/bin. --- DESCRIPTION | 2 +- R/add_footnotes.R | 6 +----- R/add_plots.R | 6 +----- R/initialize_python.R | 10 +++++----- R/remove_bookmarks.R | 6 +----- R/remove_magic_strings.R | 7 +------ R/remove_tables_figures_footnotes.R | 10 +++------- R/utils.R | 22 ++++++++++++++++++++++ _pkgdown.yml | 13 +++++-------- man/build_report.Rd | 2 +- man/reportifyr.Rd | 2 +- 11 files changed, 42 insertions(+), 44 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4751034..55774f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: reportifyr Title: Create reproducible reports with quarto and word -Version: 0.2.1 +Version: 0.2.2 Authors@R: c( person("Jacob", "Dumbleton", , "jacob@a2-ai.com", role = c("aut", "cre")), person("Matthew", "Smith", , "matthews@a2-ai.com", role = "aut"), diff --git a/R/add_footnotes.R b/R/add_footnotes.R index 2f9bad5..edc88fc 100644 --- a/R/add_footnotes.R +++ b/R/add_footnotes.R @@ -122,11 +122,7 @@ add_footnotes <- function(docx_in, stop("Create virtual environment with initialize_python") } - uv_path <- normalizePath("~/.cargo/bin/uv", mustWork = FALSE) - if (!file.exists(uv_path)) { - log4r::error(.le$logger, "uv not found. Please install with initialize_python") - stop("Please install uv with initialize_python") - } + uv_path <- get_uv_path() log4r::debug(.le$logger, "Running figure footnotes script") fig_results <- tryCatch({ diff --git a/R/add_plots.R b/R/add_plots.R index 652feb4..f36b7b8 100644 --- a/R/add_plots.R +++ b/R/add_plots.R @@ -98,11 +98,7 @@ add_plots <- function(docx_in, stop("Create virtual environment with initialize_python") } - uv_path <- normalizePath("~/.cargo/bin/uv", mustWork = FALSE) - if (!file.exists(uv_path)) { - log4r::error(.le$logger, "uv not found. Please install with initialize_python") - stop("Please install uv with initialize_python") - } + uv_path <- get_uv_path() log4r::debug(.le$logger, "Running add plots script") result <- tryCatch({ diff --git a/R/initialize_python.R b/R/initialize_python.R index 0ec991c..de495ff 100644 --- a/R/initialize_python.R +++ b/R/initialize_python.R @@ -38,18 +38,18 @@ initialize_python <- function() { args <- c(args, getOption("python.version")) log4r::info(.le$logger, paste0("Using specified python version: ", getOption("python.version"))) } - - uv_path <- normalizePath("~/.cargo/bin/uv", mustWork = FALSE) + + uv_path <- get_uv_path() if (!dir.exists(file.path(args[[1]], ".venv"))) { log4r::debug(.le$logger, "Creating new virtual environment") - + result <- processx::run( command = cmd, args = args ) log4r::info(.le$logger, paste("Virtual environment created at: ", file.path(args[[1]], ".venv"))) - + args_name <- c("venv_dir", "python-docx.version", "pyyaml.version", "python.version") pyvers <- get_py_version(getOption("venv_dir")) if (!is.null(pyvers)) { @@ -59,7 +59,7 @@ initialize_python <- function() { args <- c(args, "") log4r::warn(.le$logger, "Python version could not be detected") } - + message(paste( "Creating python virtual environment with the following settings:\n", paste0("\t", args_name, ": ", args, collapse = "\n") diff --git a/R/remove_bookmarks.R b/R/remove_bookmarks.R index 731b2c3..a000ea3 100644 --- a/R/remove_bookmarks.R +++ b/R/remove_bookmarks.R @@ -108,11 +108,7 @@ remove_bookmarks <- function(docx_in, stop("Create virtual environment with initialize_python") } - uv_path <- normalizePath("~/.cargo/bin/uv", mustWork = FALSE) - if (!file.exists(uv_path)) { - log4r::error(.le$logger, "uv not found. Please install with initialize_python") - stop("Please install uv with initialize_python") - } + uv_path <- get_uv_path() script <- system.file("scripts/remove_bookmarks.py", package = "reportifyr") args <- c("run", script, "-i", docx_in, "-o", docx_out) diff --git a/R/remove_magic_strings.R b/R/remove_magic_strings.R index 01180a5..fe0f571 100644 --- a/R/remove_magic_strings.R +++ b/R/remove_magic_strings.R @@ -77,7 +77,6 @@ remove_magic_strings <- function(docx_in, docx_out) { stop(paste("The file must be a docx file not:", tools::file_ext(docx_out))) } - if (interactive()) { log4r::info(.le$logger, "Prompting user for confirmation to remove bookmarks.") continue <- readline("This will remove magic strings from the document. This severs link between the document and reportifyr. Are you sure you want to continue? [Y/n]\n") @@ -107,11 +106,7 @@ remove_magic_strings <- function(docx_in, docx_out) { stop("Create virtual environment with initialize_python") } - uv_path <- normalizePath("~/.cargo/bin/uv", mustWork = FALSE) - if (!file.exists(uv_path)) { - log4r::error(.le$logger, "uv not found. Please install with initialize_python") - stop("Please install uv with initialize_python") - } + uv_path <- get_uv_path() script <- system.file("scripts/remove_magic_strings.py", package = "reportifyr") args <- c("run", script, "-i", docx_in, "-o", docx_out) diff --git a/R/remove_tables_figures_footnotes.R b/R/remove_tables_figures_footnotes.R index 8134f98..78d8078 100644 --- a/R/remove_tables_figures_footnotes.R +++ b/R/remove_tables_figures_footnotes.R @@ -53,13 +53,9 @@ remove_tables_figures_footnotes <- function(docx_in, log4r::error(.le$logger, "Virtual environment not found. Please initialize with initialize_python.") stop("Create virtual environment with initialize_python") } - - uv_path <- normalizePath("~/.cargo/bin/uv", mustWork = FALSE) - if (!file.exists(uv_path)) { - log4r::error(.le$logger, "uv not found. Please install with initialize_python") - stop("Please install uv with initialize_python") - } - + + uv_path <- get_uv_path() + notes_script <- system.file("scripts/remove_footnotes.py", package = "reportifyr") notes_args <- c("run", notes_script, "-i", docx_in, "-o", docx_out) diff --git a/R/utils.R b/R/utils.R index ee232d1..a30932b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -106,3 +106,25 @@ get_packages <- function() { return(pkgs_metadata) } + + +#' Gets the path to uv -- pre v0.5.0 installed to /.cargo/bin post v0.5.0 to /.local/bin +#' +#' @return path to uv +#' +#' @keywords internal +#' @noRd +get_uv_path <- function() { + uv_paths <- c(normalizePath("~/.local/bin/uv", mustWork = FALSE), + normalizePath("~/.cargo/bin/uv", mustWork = FALSE)) + + # Find the first existing path, preferring ~/.local/bin/uv + uv_path <- uv_paths[file.exists(uv_paths)][1] + + if (is.null(uv_path)) { + log4r::error(.le$logger, "uv not found. Please install with initialize_python") + stop("Please install uv with initialize_python") + } else { + return(uv_path) + } +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 5582f20..3f713af 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,12 +1,10 @@ url: https://a2-ai.github.io/reportifyr/ - template: bootstrap: 5 bslib: - bg: "#FFFFFF" - fg: "#63666A" - primary: "#1E63AF" - + bg: '#FFFFFF' + fg: '#63666A' + primary: '#1E63AF' navbar: title: reportifyr bg: primary @@ -41,7 +39,6 @@ navbar: github: icon: fa-github fa-lg href: https://github.com/a2-ai/reportifyr - reference: - title: Set-up Functions contents: @@ -77,5 +74,5 @@ reference: - validate_object - toggle_logger - title: Reportifyr Summary - contents: - - reportifyr + contents: reportifyr + diff --git a/man/build_report.Rd b/man/build_report.Rd index 06431e0..3d2b8b3 100644 --- a/man/build_report.Rd +++ b/man/build_report.Rd @@ -6,7 +6,7 @@ \usage{ build_report( docx_in, - docx_out, + docx_out = NULL, figures_path, tables_path, standard_footnotes_yaml = NULL, diff --git a/man/reportifyr.Rd b/man/reportifyr.Rd index 58e8811..3f5fae4 100644 --- a/man/reportifyr.Rd +++ b/man/reportifyr.Rd @@ -117,7 +117,7 @@ Authors: Other contributors: \itemize{ - \item Fenando Carreno \email{fernando.o.carreno@gsk.com} [contributor] + \item Fernando Carreno \email{fernando.o.carreno@gsk.com} [contributor] \item Kashyap Patel \email{kashyap.x.patel@gsk.com} [contributor] \item Maxwell Chirehwa \email{maxwell.t.chirehwa@gsk.com} [contributor] \item Wesley Cummings \email{wes@a2-ai.com} [contributor] From 8f5819afe9a92817abce1cc7a8ee5f07b3cda50a Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Mon, 11 Nov 2024 00:00:23 +0000 Subject: [PATCH 2/2] pin uv version 0.5.1 installation. --- R/initialize_python.R | 7 +++++++ R/zzz.R | 11 +++++++++-- inst/scripts/uv_setup.sh | 15 ++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/R/initialize_python.R b/R/initialize_python.R index de495ff..6cdc912 100644 --- a/R/initialize_python.R +++ b/R/initialize_python.R @@ -34,6 +34,13 @@ initialize_python <- function() { log4r::info(.le$logger, "Using default pyyaml version: 6.0.2") } + if (!is.null(getOption("uv.version"))) { + args <- c(args, getOption("uv.version")) + } else { + args <- c(args, "0.5.1") + log4r::info(.le$logger, "Using default uv version: 0.5.1") + } + if (!is.null(getOption("python.version"))) { args <- c(args, getOption("python.version")) log4r::info(.le$logger, paste0("Using specified python version: ", getOption("python.version"))) diff --git a/R/zzz.R b/R/zzz.R index b74f7f0..e2d2edb 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -29,11 +29,18 @@ reportifyr_options_message <- function() { set_options <- c(set_options, paste("venv_dir:", root)) } # NICE TO HAVES - pyversion <- getOption("python_version") + uvversion <- getOption("uv.version") + if (is.null(uvversion)) { + optional_options <- c(optional_options, "options('uv.version') is not set. Default is 0.5.1") + } else { + set_options <- c(set_options, paste("uv.version:", uvversion)) + } + + pyversion <- getOption("python.version") if (is.null(pyversion)) { optional_options <- c(optional_options, "options('python.version') is not set. Default is system version") } else { - set_options <- c(set_options, paste("python_version:", pyversion)) + set_options <- c(set_options, paste("python.version:", pyversion)) } docx_vers <- getOption("python-docx.version") diff --git a/inst/scripts/uv_setup.sh b/inst/scripts/uv_setup.sh index a932538..1f432c3 100755 --- a/inst/scripts/uv_setup.sh +++ b/inst/scripts/uv_setup.sh @@ -1,11 +1,11 @@ #!/bin/bash -# uv_setup.sh venv_directiory python-docx_version pyyaml_version python_version +# uv_setup.sh venv_directory python-docx_version pyyaml_version uv_version [python_version] -#check if uv is installed. +# Check if uv is installed. if ! command -v uv &> /dev/null; then - echo "'uv' is not installed. Installing..." - curl -LsSf https://astral.sh/uv/install.sh | sh + echo "'uv' is not installed. Installing version $4..." + curl --proto '=https' --tlsv1.2 -LsSf "https://github.com/astral-sh/uv/releases/download/$4/uv-installer.sh" | sh fi if [[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]]; then @@ -21,10 +21,10 @@ source $HOME/.bashrc if [ ! -d "$1/.venv" ]; then echo "Creating venv at $1/.venv" - if [ -n "$4" ]; then - uv venv "$1/.venv" --python="$4" # Use the version provided in $4 + if [ -n "$5" ]; then + uv venv "$1/.venv" --python="$5" # Use the Python version provided in $5 else - uv venv "$1/.venv" # Default version + uv venv "$1/.venv" # Default version if $5 is not provided fi fi @@ -39,6 +39,7 @@ if ! python -c "import docx" &> /dev/null; then fi fi +# Check if pyyaml is installed, install it if not if ! python -c "import yaml" &> /dev/null; then if [ -n "$3" ]; then uv pip install "pyyaml==$3"