Skip to content

Commit

Permalink
Merge pull request #1699 from rstudio/compile-python
Browse files Browse the repository at this point in the history
add `tools/compile-python.R` script
  • Loading branch information
t-kalinowski authored Nov 13, 2024
2 parents 141c1cb + 065a9ff commit 5d509e1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/compile-python.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env Rscript

package_dir <- Sys.getenv("R_PACKAGE_DIR", NA)
if (is.na(package_dir))
package_dir <- path.package("reticulate")

tryCatch({
owd <- setwd(package_dir)
for (stale_pycache in grep("__pycache__$", list.dirs(recursive = TRUE), value = TRUE))
unlink(stale_pycache, recursive = TRUE)

df <- reticulate::virtualenv_starter(all = TRUE)
df <- df[order(df$version, decreasing = TRUE), ]
df$minor <- df$version[, 1:2]
df <- df[!duplicated(df$minor), ]
for (python in df$path) {
reticulate:::system2t(python, "-m compileall config python")
}
}, finally = setwd(owd))

0 comments on commit 5d509e1

Please sign in to comment.