Skip to content

Commit

Permalink
Fix page_size float/int issue + auto-select and configure python libr…
Browse files Browse the repository at this point in the history
…ary from @datawookie and @daattali (#13)

* install domino_data python module on install and select a python interpreter on package load; thanks to @datawookie

* dont run configure script on CI

* try installing the correct version of the python module

* Change python install to latest version of dominodatalab-data

* rstudio: remove trailing whitespace and auto append new lines (#10)

* Update version in DESCRIPTION (#12)

* Force page_size to integer

* Add optional version of domino_data to install

* Remove spaces

* Add stuff

* Generate docs

* Update DESCRIPTION

* Don't use v

---------

Co-authored-by: Dean Attali <[email protected]>
Co-authored-by: Dean Attali <[email protected]>
  • Loading branch information
3 people authored Feb 28, 2023
1 parent e34d765 commit a0dabb8
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: DominoDataR
Title: Domino Data R API
Version: 0.2.0
Version: 0.2.1
Authors@R:
person("Gabriel", "Haim", , "[email protected]", role = c("aut", "cre"))
Description: Domino Data API for interacting with Data features (Data Sources).
License: Apache License (>= 2)
URL: https://github.com/dominodatalab/r-domino-data
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Imports:
arrow,
ConfigParser,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(get_object)
export(list_keys)
export(object_http)
export(put_object)
export(py_domino_data_install)
export(query)
export(save_object)
export(upload_object)
Expand Down
2 changes: 1 addition & 1 deletion R/objectstore.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ list_keys <- function(client,
client$list_keys(
datasource$identifier,
prefix,
page_size,
as.integer(page_size),
reticulate::dict(override),
reticulate::dict(credentials)
)
Expand Down
51 changes: 51 additions & 0 deletions R/python.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
py_select_interpreter <- function() {
# Tell {reticulate} to use the Conda version of Python available on Domino Data Lab.
#
# Provide other options in case the package is being used for local development.
#
PYTHON_PATH <- c(
"/opt/conda/bin/python",
path.expand("~/.virtualenvs/r-reticulate/bin/python"),
"/usr/bin/python"
)
#
for (path in PYTHON_PATH) {
if (file.exists(path)) {
reticulate::use_python(path)
break
}
}
#
# If no Python is present (or not in the expected place), then install MiniConda.
#
if (!reticulate::py_available(initialize = TRUE)) {
try(reticulate::install_miniconda())
}
}

#' Install domino_data Python package
#' @return `TRUE` if installation was successful, `FALSE` otherwise.
#' @param version Version of the domino_data package to install.
#' @export
py_domino_data_install <- function(version) {
py_select_interpreter()

# Install the (Python) domino_data package.
#
if (!reticulate::py_module_available("domino_data")) {
if (missing(version)) {
package <- "dominodatalab-data"
} else {
package <- paste0("dominodatalab-data==", version)
}
result <- tryCatch({
reticulate::py_install(package, pip = TRUE, method = "virtualenv")
TRUE
}, error = function(e) {
FALSE
})
result
} else {
TRUE
}
}
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.onLoad <- function(libname, pkgname) {
py_select_interpreter()
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ install.packages("remotes")
remotes::install_github("dominodatalab/DominoDataR")
```

The Domino Data R library depends on the [python
library](https://pypi.org/project/dominodatalab-data/). Make sure it is
installed in your environment or use the following command:
The Domino Data R library depends on the [Python
library](https://pypi.org/project/dominodatalab-data/). On unix systems this should be
installed automatically when `{DominoDataR}` is installed. You can also
install it manually:

``` r
library(reticulate)
py_install("dominodatalab-data")
DominoDataR::py_domino_data_install()
```
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -x
set -e

${R_HOME}/bin/Rscript inst/scripts/python-setup.R
5 changes: 5 additions & 0 deletions inst/scripts/python-setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (!nzchar(Sys.getenv('CI'))) {
source("R/python.R")

py_domino_data_install()
}
17 changes: 17 additions & 0 deletions man/py_domino_data_install.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0dabb8

Please sign in to comment.