-
Notifications
You must be signed in to change notification settings - Fork 330
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
reticulate is creating files in the R library path after installation #1680
Comments
Thank you for opening this issue. We can't assume
df <- reticulate::virtualenv_starter(all = TRUE)
df <- df[order(df$version, decreasing = TRUE), ]
df$minor <- df$version[, 1:2]
df <- df[!duplicated(df$minor), ]
setwd("python")
for (python in df$path) {
system2(python, "-m compileall .")
} Would you be interested in submitting a pull request? |
Could we make use of |
We could possibly set this to However, setting this would be a global option that affects all module imports. Also, (I haven't tested), I suspect it might also make python ignore existing |
Just a suggestion, but maybe R could always use user's cache directory? E.g. via: pythoncache_prefix <- file.path(rappdirs::user_cache_dir("reticulate"), "pycache")
dir.create(pythoncache_prefix, showWarnings = FALSE, recursive = TRUE)
Sys.senv(PYTHONPYCACHEPREFIX=pythoncache_prefix) From my understanding the slowdown would be noticeable only upon first time the user imports a library. P.S. I think P.P.S. Hm, |
@t-kalinowski Actually the more I think about it the more I’m convinced that it’s a bad idea to have any cache data written in the installation path: it categorically does not belong there. Unfortunately Python chose the wrong default behaviour. And, as you say, changing this behaviour inside ‘reticulate’ would affect all Python code loaded in that session. Maybe a hybrid approach would be to check whether the user has already specified For our own purposes we’ve now worked around this issue by creating an empty |
This scenario—where a package library is shared by users, some with write permissions and others without—seems relatively niche. Typically, shared package libraries are managed by a root account and provided to users as read-only. In these cases:
Alternatively, if shared libraries are writable by all users, mixed ownership isn’t an issue. I wouldn’t want to introduce significant complexity or a runtime performance hit for such a niche case. That said, I’m open to precompiling .pyc files during package installation. In environments with mixed permissions, we can assume the system was configured by an expert, and most likely, Python binaries are available. That should resolve the problem. |
Is there anything which speaks agains this, @t-kalinowski ?
if (is.na(Sys.getenv("PYTHONPYCACHEPREFIX", NA)) {
pythoncache_prefix <- file.path(tools::R_user_dir("reticulate", which="cache"), "pycache")
if (!dir.exists(pythoncache_prefix)) {
dir.create(pythoncache_prefix, recursive=TRUE)
}
Sys.setenv(PYTHONPYCACHEPREFIX=pythoncache_prefix)
} |
Do we know what happens on Windows without long path support enabled? |
Also, we would probably want a strategy for periodically clearing the cache on long-lived systems. |
Clearing the cache is usually the user’s responsibility. I see no reason why ‘reticulate’ should deviate from this practice, or indeed do anything special in this regard. In fact, I’d argue against doing anything special because of POLA. Regarding Windows path handling, I also don’t think that this requires special consideration — if this would turn out to be a problem (unlikely, but who knows), it would be a general Python problem, not one specific to ‘reticulate’. |
CRAN Policy states (emphasis mine):
|
I don’t think a single CRAN package actually does that (okay, that’s too easily disproved by finding a single counter-example, but I’d wager that the majority of packages doesn’t). But fair enough — how about exporting a function |
The ‘reticulate’ package is creating files inside the R library path after installation, when it is being used. Here’s an MWE:
It is my understanding of CRAN guidelines that packages are not allowed to write into the R package library path after installation, and in fact this behaviour is causing breaking issues for us on a system with a shared group library folder: if person A installs the package and person B first uses it, the folder owners get mixed up. In combination with default permissions (which make these folders non-writable for other group members!), this means that removing the package or installing updates cannot be done without the cooperation of multiple people.
The text was updated successfully, but these errors were encountered: