Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renv::use_python() removes the renv/profile file #1217

Closed
milanmlft opened this issue May 2, 2023 · 3 comments
Closed

renv::use_python() removes the renv/profile file #1217

milanmlft opened this issue May 2, 2023 · 3 comments
Labels
bug an unexpected problem or unintended behavior python 🐍
Milestone

Comments

@milanmlft
Copy link

When activating Python within a renv profile, for some reason the renv/profile file gets removed (see reprex below).
Not sure if this is intentional, but it seems like an undesired side effect.

Any ideas of why this happens?

renv::init(project = ".", bare = TRUE, restart = FALSE, profile = "dev")
fs::dir_tree(path = "renv", recurse = 1)
#> renv
#> ├── activate.R
#> ├── profile
#> └── profiles
#>     └── dev

renv::use_python()
#> * Creating virtual environment 'renv-python-3.11' ... Done!
#> * Updating Python packages ... Done!
#> * Activated Python 3.11.3 [virtualenv; ./renv/profiles/dev/renv/python/virtualenvs/renv-python-3.11]
fs::dir_tree(path = "renv", recurse = 1)
#> renv
#> ├── activate.R
#> ├── library
#> │   └── R-4.3
#> └── profiles
#>     └── dev
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21)
#>  os       macOS Ventura 13.3.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language en_US.UTF-8
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/London
#>  date     2023-05-02
#>  pandoc   3.1.2 @ /opt/homebrew/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  ! package     * version date (UTC) lib source
#>  R cli           3.6.1   <NA>       [?] <NA>
#>  R digest        0.6.31  <NA>       [?] <NA>
#>  R evaluate      0.20    <NA>       [?] <NA>
#>  R fastmap       1.1.1   <NA>       [?] <NA>
#>  R fs            1.6.2   <NA>       [?] <NA>
#>  R glue          1.6.2   <NA>       [?] <NA>
#>  R htmltools     0.5.5   <NA>       [?] <NA>
#>  R knitr         1.42    <NA>       [?] <NA>
#>  R lifecycle     1.0.3   <NA>       [?] <NA>
#>  R magrittr      2.0.3   <NA>       [?] <NA>
#>  R purrr         1.0.1   <NA>       [?] <NA>
#>  R R.cache       0.16.0  <NA>       [?] <NA>
#>  R R.methodsS3   1.8.2   <NA>       [?] <NA>
#>  R R.oo          1.25.0  <NA>       [?] <NA>
#>  R R.utils       2.12.2  <NA>       [?] <NA>
#>  P renv          0.17.3  2023-04-06 [?] CRAN (R 4.3.0)
#>  R reprex        2.0.2   <NA>       [?] <NA>
#>  R rlang         1.1.0   <NA>       [?] <NA>
#>  R rmarkdown     2.21    <NA>       [?] <NA>
#>  R rstudioapi    0.14    <NA>       [?] <NA>
#>  R sessioninfo   1.2.2   <NA>       [?] <NA>
#>  R styler        1.9.1   <NA>       [?] <NA>
#>  R vctrs         0.6.2   <NA>       [?] <NA>
#>  R withr         2.5.0   <NA>       [?] <NA>
#>  R xfun          0.39    <NA>       [?] <NA>
#>  R yaml          2.3.7   <NA>       [?] <NA>
#> 
#>  [1] /private/var/folders/9z/4rs_sqvj38n8b02wv8p4j77h0000gn/T/RtmppBglPd/reprex-1286d5b74d1c1-brave-mara/renv/library/R-4.3/aarch64-apple-darwin20
#>  [2] /Users/milan/Library/Caches/org.R-project.R/R/renv/sandbox/R-4.3/aarch64-apple-darwin20/ac5c2659
#> 
#>  P ── Loaded and on-disk path mismatch.
#>  R ── Package was removed from disk.
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@kevinushey kevinushey added bug an unexpected problem or unintended behavior python 🐍 labels May 2, 2023
@milanmlft
Copy link
Author

Some more info: it seems that renv::use_python() deactivates the profile altogether:

renv::init(project = ".", bare = TRUE, restart = FALSE, profile = "dev")
Sys.getenv("RENV_PROFILE")
#> [1] "dev"
renv::use_python()
#> * Creating virtual environment 'renv-python-3.11' ... Done!
#> * Updating Python packages ... Done!
#> * Activated Python 3.11.3 [virtualenv; ./renv/profiles/dev/renv/python/virtualenvs/renv-python-3.11]
Sys.getenv("RENV_PROFILE")
#> [1] ""

milanmlft added a commit to milanmlft/sandpaper that referenced this issue May 3, 2023
@kevinushey kevinushey added this to the 1.1.0 milestone Jun 9, 2023
@kevinushey
Copy link
Collaborator

Finally taking a look at this now -- the issue arises because renv calls activate() here:

activate(project = project)

but renv::activate(), when called without arguments, reverts back to the default profile.

I think we should change the behavior of activate(), so that it preserves an existing profile (if any). Users can revert to the default profile if necessary with:

renv::activate(profile = "default")

@kevinushey
Copy link
Collaborator

Should be fixed via baba348; thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior python 🐍
Projects
None yet
Development

No branches or pull requests

2 participants