Skip to content

Commit

Permalink
ignore .env virtual environments; allow .env files (#973)
Browse files Browse the repository at this point in the history
* ignore .env directores; allow .env files

fixes #972

* ignore .env, .venv, venv only when virtual environments

* ignore venvs on Windows

* windows debug and GUI binaries
  • Loading branch information
aronatkins authored Aug 23, 2023
1 parent 8b3b8a0 commit 2eda945
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 13 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
`rsconnect.max.bundle.files=10000` limit but larger than the
`renv.config.dependencies.limit=1000` limit. (#968)

* Ignore `.env`, `.venv`, and `venv` files only when they reference Python
virtual environments. (#972)

# rsconnect 1.0.2

* Fixed redeployments to shinyapps.io where `appName` is provided, but no local
Expand Down Expand Up @@ -204,7 +207,7 @@

* `deployApp()` excludes temporary backup files (names starting or ending
with `~`) when automatically determining files to bundle (#111) as well as
directories that are likely to be python virtual environments (#632).
directories that are likely to be Python virtual environments (#632).
Additionally, ignore rules are always now applied to all directories;
previously some (like `.Rproj.user` and `"manifest.json"`) were only
applied to the root directory. It correctly handles `.rscignore` files
Expand Down
16 changes: 9 additions & 7 deletions R/bundleFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ recursiveBundleFiles <- function(dir,
}

ignoreBundleFiles <- function(dir, contents) {
ignore <- c(
# entries ignored regardless of type
ignored <- c(
# rsconnect packages
"rsconnect", "rsconnect-python", "manifest.json",
# packrat + renv,
Expand All @@ -179,13 +180,11 @@ ignoreBundleFiles <- function(dir, contents) {
".git", ".gitignore", ".svn",
# R/RStudio
".Rhistory", ".Rproj.user",
# python virtual envs
# https://github.com/rstudio/rsconnect-python/blob/94dbd28797ee503d66411f736da6edc29fcf44ed/rsconnect/bundle.py#L37-L50
".env", "env", ".venv", "venv", "__pycache__/",
# other
".DS_Store", ".quarto", "app_cache"
".DS_Store", ".quarto", "app_cache", "__pycache__/"
)
contents <- setdiff(contents, ignore)

contents <- setdiff(contents, ignored)
contents <- contents[!isKnitrCacheDir(contents)]
contents <- contents[!isPythonEnv(dir, contents)]
contents <- contents[!grepl("^~|~$", contents)]
Expand All @@ -211,7 +210,10 @@ isKnitrCacheDir <- function(files) {

# https://github.com/rstudio/rsconnect-python/blob/94dbd28797ee503d6/rsconnect/bundle.py#L541-L543
isPythonEnv <- function(dir, files) {
file.exists(file.path(dir, files, "bin", "python"))
(file.exists(file.path(dir, files, "bin", "python")) |
file.exists(file.path(dir, files, "Scripts", "python.exe")) |
file.exists(file.path(dir, files, "Scripts", "pythond.exe")) |
file.exists(file.path(dir, files, "Scripts", "pythonw.exe")))
}

enforceBundleLimits <- function(appDir, totalFiles, totalSize) {
Expand Down
75 changes: 70 additions & 5 deletions tests/testthat/test-bundleFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,81 @@ test_that("ignores temporary files", {
expect_equal(ignored, c("foo.xlsx", "foo.csv"))
})

test_that("ignores python virtual envs", {
test_that("ignores Python virtual envs (non-Windows)", {
dir <- withr::local_tempdir()
dirCreate(file.path(dir, "test", "bin"))
file.create(file.path(dir, "test", "bin", "python"))
dirCreate(file.path(dir, "venv"))
file.create(file.path(dir, "venv", "somefile"))

names <- c(
# well-known names ...
".env", ".venv", "venv",

# other names ...
"test"
)

dirCreate(file.path(dir, names, "bin"))
file.create(file.path(dir, names, "bin", "python"))

expect_equal(bundleFiles(dir), character())
})

test_that("ignores Python virtual envs (Windows)", {
dir <- withr::local_tempdir()

names <- c(
# well-known names ...
".env", ".venv", "venv",

# other names ...
"test"
)

dirCreate(file.path(dir, names, "Scripts"))
file.create(file.path(dir, names, "Scripts", "python.exe"))

expect_equal(bundleFiles(dir), character())
})

test_that("ignores Python virtual envs (Windows-GUI)", {
dir <- withr::local_tempdir()

names <- c(
# well-known names ...
".env", ".venv", "venv",

# other names ...
"test"
)

dirCreate(file.path(dir, names, "Scripts"))
file.create(file.path(dir, names, "Scripts", "pythonw.exe"))

expect_equal(bundleFiles(dir), character())
})

test_that("ignores Python virtual envs (Windows-debug)", {
dir <- withr::local_tempdir()

names <- c(
# well-known names ...
".env", ".venv", "venv",

# other names ...
"test"
)

dirCreate(file.path(dir, names, "Scripts"))
file.create(file.path(dir, names, "Scripts", "pythond.exe"))

expect_equal(bundleFiles(dir), character())
})

test_that("preserves well-known names when not Python virtual environment", {
dir <- withr::local_tempdir()
file.create(file.path(dir, c(".env", ".venv", "venv")))

expect_setequal(bundleFiles(dir), c(".env", ".venv", "venv"))
})

# explodeFiles ------------------------------------------------------------

test_that("returns relative paths", {
Expand Down

0 comments on commit 2eda945

Please sign in to comment.