From d6eb7d4826527d2ef9379631ce1c858e53355c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 9 Mar 2025 16:33:58 +0100 Subject: [PATCH] docs: use uv to set up Python environment --- README.md | 4 ++-- init-env.sh | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6027e79..4b3f477 100644 --- a/README.md +++ b/README.md @@ -68,12 +68,12 @@ It supports initialising all environments or specific ones based on the provided ### Script Details - **Options**: - - `--what/-w`: Specify which environment(s) to initialise (`all`, `r`, `python`, `julia`). + - `--what/-w`: Specify which environment(s) to initialise (`all`, `r`, `python (uv)`, `julia`). - `--force/-f`: Force reinstallation of the specified environment(s). - `--help/-h`: Display help message and exit. - **Functionality**: The script installs necessary dependencies for R, Python, and Julia, inside environments. - For R, it sets up `renv` and installs required packages. - - For Python, it sets up a virtual environment and installs required libraries. + - For Python, it sets up uv and installs required libraries. - For Julia, it sets up an environment and installs required packages. ## Contributing diff --git a/init-env.sh b/init-env.sh index 4bb7249..bd80e38 100644 --- a/init-env.sh +++ b/init-env.sh @@ -5,7 +5,7 @@ show_help() { echo " --what/-w: Specify what to initialise (default: all)." echo " all: Initialise R (renv), Python (virtualenv), and Julia (project)." echo " r: Initialise R (renv)." - echo " python: Initialise Python (virtualenv)." + echo " python: Initialise Python (uv)." echo " julia: Initialise Julia (project)." echo " --force/-f: Force initialisation regardless of existing files." echo " --help/-h: Show this help message." @@ -13,8 +13,11 @@ show_help() { initialise_r() { if [ "$FORCE" = true ] || [ ! -f "renv.lock" ]; then + if grep -q 'source("renv/activate.R")' .Rprofile; then + sed -i '' '/source("renv\/activate.R")/d' .Rprofile + fi Rscript -e 'renv::init(bare = FALSE)' - Rscript -e 'renv::install("rmarkdown")' + Rscript -e 'renv::install(c("rmarkdown", "prompt", "languageserver", "lintr", "styler", "cli"))' Rscript -e 'renv::snapshot(type = "all")' fi } @@ -28,6 +31,16 @@ initialise_python() { fi } +initialise_uv() { + if [ "$FORCE" = true ] || [ ! -f "uv.lock" ]; then + uv init --no-package --vcs none --bare --no-readme --author-from none + uv venv + source .venv/bin/activate + uv add jupyter papermill + uv sync + fi +} + initialise_julia() { if [ "$FORCE" = true ] || [ ! -f "Project.toml" ]; then julia -e 'using Pkg; Pkg.activate("."); Pkg.instantiate()' @@ -63,14 +76,14 @@ done case $WHAT in all) initialise_r - initialise_python + initialise_uv initialise_julia ;; r) initialise_r ;; python) - initialise_python + initialise_uv ;; julia) initialise_julia