Skip to content

Commit

Permalink
Merge pull request #105 from mlverse/updates
Browse files Browse the repository at this point in the history
Ensures requirements prompt does not happen if `confirm` is set to false
  • Loading branch information
edgararuiz authored Jan 12, 2024
2 parents 5ad6b95 + 2584fc4 commit d970ccf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
30 changes: 16 additions & 14 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ deploy_databricks <- function(

cli_div(theme = cli_colors())

cluster_id <- cluster_id %||% Sys.getenv("DATABRICKS_CLUSTER_ID")

if (is.null(version) && !is.null(cluster_id)) {
version <- databricks_dbr_version(
cluster_id = cluster_id,
Expand Down Expand Up @@ -202,21 +204,21 @@ deploy <- function(
server <- rs_accounts$server[choice]
account <- rs_accounts$name[choice]
}
}

req_file <- path(appDir, "requirements.txt")
prev_deployments <- deployments(appDir)
if(!file_exists(req_file) && nrow(prev_deployments) == 0 && check_interactive()) {
cli_inform(c(
"{.header Would you like to create the 'requirements.txt' file?}",
"{.class Why consider? This will allow you to skip using `version` or `cluster_id`}"
))
choice <- menu(choices = c("Yes", "No"))
if(choice == 1) {
requirements_write(
destfile = req_file,
python = python
)
req_file <- path(appDir, "requirements.txt")
prev_deployments <- deployments(appDir)
if(!file_exists(req_file) && nrow(prev_deployments) == 0 && check_interactive()) {
cli_inform(c(
"{.header Would you like to create the 'requirements.txt' file?}",
"{.class Why consider? This will allow you to skip using `version` or `cluster_id`}"
))
choice <- menu(choices = c("Yes", "No"))
if(choice == 1) {
requirements_write(
destfile = req_file,
python = python
)
}
}
}

Expand Down
17 changes: 16 additions & 1 deletion tests/testthat/test-deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ test_that("Basic use, passing the cluster's ID", {
)
})

test_that("Use the Cluster ID from environment variable", {
withr::with_envvar(
new = c("WORKON_HOME" = use_test_env()),
{
local_mocked_bindings(
deployApp = function(...) list(...),
accounts = function(...) accounts_df()
)
expect_equal(
deploy_databricks(),
test_databricks_deploy_output()
)
}
)
})

test_that("Additional arguments are passed on to deployApp()", {
withr::with_envvar(
new = c("WORKON_HOME" = use_test_env()),
Expand Down Expand Up @@ -215,7 +231,6 @@ test_that("Rare cases for finding environments works", {
)
})


test_that("Misc deploy tests", {
expect_error(deploy(), "'backend'")

Expand Down

0 comments on commit d970ccf

Please sign in to comment.