Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Commit d9554b9

Browse files
authored
Merge pull request #96 from stemangiola/fix-74
Create `update_database()` for updating metadata
2 parents 643fa77 + 5c8173d commit d9554b9

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

DESCRIPTION

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ Suggests:
106106
knitr,
107107
testthat,
108108
tidySingleCellExperiment,
109-
ggplot2
109+
ggplot2,
110+
basilisk,
111+
arrow,
112+
reticulate
110113
Biarch: true
111114
biocViews:
112115
AssayDomain,

R/dev.R

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Utility scripts for development purposes, that are not exported to users
2+
3+
#' Update the metadata database in nectar using a newly created data frame
4+
#' @param metadata The data frame to upload
5+
#' @param version The version for the new metadata as a character scalar, e.g.
6+
#' "0.2.3"
7+
#' @param credential_id The OpenStack application credential ID as a character
8+
#' scalar. This is optional because you can alternatively source a
9+
#' `-openrc.sh` file instead of providing it here.
10+
#' @param credential_id The OpenStack application credential secret as a
11+
#' character scalar
12+
#' @noRd
13+
#' @example
14+
#' \dontrun{
15+
#' metadata = CuratedAtlasQueryR::get_metadata() |> head(10) |> dplyr::collect()
16+
#' update_database(metadata, "0.2.3", "rfypdlunhrfopdnkrs", "3q5lw3qntafptdfsrdh-wa4p8h")
17+
#' # Prints "metadata.0.2.3.parquet" if successful
18+
#' }
19+
update_database = function(metadata, version, credential_id = NULL, credential_secret = NULL){
20+
# These are optional dev packages
21+
rlang::check_installed(c("arrow", "glue", "basilisk"))
22+
23+
# Create parquet
24+
dir <- tempdir()
25+
parquet_name <- glue::glue("metadata.{version}.parquet")
26+
parquet_path <- file.path(dir, parquet_name)
27+
arrow::write_parquet(metadata, sink=parquet_path)
28+
29+
# Create the basilisk environment
30+
swift_env <- basilisk::BasiliskEnvironment(
31+
envname="swift-nectar-upload",
32+
pkgname=packageName(),
33+
packages=c("python-swiftclient==4.2.0", "python-keystoneclient==5.1.0", "python==3.10.9")
34+
)
35+
proc <- basilisk::basiliskStart(swift_env)
36+
37+
# Build the CLI args
38+
if (!is.null(credential_id) && !is.null(credential_secret)){
39+
auth <- c(
40+
"--os-auth-type",
41+
"v3applicationcredential",
42+
"--os-application-credential-id",
43+
credential_id,
44+
"--os-application-credential-secret",
45+
credential_secret
46+
)
47+
}
48+
else {
49+
auth <- character()
50+
}
51+
args = c(
52+
"-m",
53+
"swiftclient.shell",
54+
"--os-auth-url",
55+
"https://keystone.rc.nectar.org.au:5000/v3/",
56+
"--os-project-id",
57+
"06d6e008e3e642da99d806ba3ea629c5",
58+
auth,
59+
"upload",
60+
"metadata",
61+
parquet_path,
62+
"--object-name",
63+
parquet_name
64+
)
65+
66+
# Perform the upload
67+
system2(reticulate::py_exe(), args=args)
68+
basilisk::basiliskStop(proc)
69+
}

0 commit comments

Comments
 (0)