Skip to content

Commit

Permalink
[SYN-1520] upgrade python client version and R version (#336)
Browse files Browse the repository at this point in the history
* upgraded synapseclient version to v4.4.0
* updated R version and package dependencies
* added/extended reference documents for both new and modified functions
* updated Github action to reflect most recent compatible R versions
* resolved infinite recursion issues and package building failures on Ubuntu and Windows
  • Loading branch information
danlu1 authored Jul 31, 2024
1 parent a58916a commit 4301c25
Show file tree
Hide file tree
Showing 38 changed files with 914 additions and 318 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# build and test synapser. Additionally deploys to S3 RAN server on GitHub release.

name: build
Expand Down Expand Up @@ -28,14 +29,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, macos-13, windows-2022]
r: [4.1.3, 4.2.3, 4.3.1]
r: [4.1.3, 4.2.3, 4.3.1, 4.4.1]

steps:
- name: checkout
uses: actions/checkout@v4

- name: Set up Python Version
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand Down Expand Up @@ -137,6 +138,10 @@ jobs:
- name: linux-build-package
if: ${{runner.os == 'linux'}}
run: |
Rscript -e "install.packages('remotes'); remotes::install_version('reticulate', version = '1.28')"
Rscript -e "reticulate::install_miniconda()"
echo "options(reticulate.conda_binary = reticulate:::miniconda_conda())" >> .Rprofile
Rscript -e "reticulate::conda_create('r-reticulate', packages = c('python==3.10'))"
R CMD build ./
R CMD INSTALL ./ --library=$R_LIBS_USER --no-test-load
Expand All @@ -145,7 +150,7 @@ jobs:
- name: mac-build-package
if: ${{runner.os == 'macOS'}}
run: |
Rscript -e "install.packages(c('remotes', 'reticulate'))"
Rscript -e "install.packages('remotes'); remotes::install_version('reticulate', version = '1.28')"
Rscript -e "reticulate::install_miniconda()"
echo "options(reticulate.conda_binary = reticulate:::miniconda_conda())" >> .Rprofile
Rscript -e "reticulate::conda_create('r-reticulate', packages = c('python==3.10'))"
Expand All @@ -158,6 +163,11 @@ jobs:
if: ${{runner.os == 'Windows'}}
shell: bash
run: |
echo "options(repos = c(CRAN = 'https://cloud.r-project.org'))" >> .Rprofile
Rscript -e "install.packages('remotes'); remotes::install_version('reticulate', version = '1.28')"
Rscript -e "reticulate::install_python(version = '3.10.11')"
Rscript -e "reticulate::virtualenv_create(envname='r-reticulate',version = '3.10.11')"
Rscript -e "reticulate::use_virtualenv('r-reticulate')"
R CMD build ./
R CMD INSTALL --build ${PACKAGE_NAME}_${PACKAGE_VERSION}.tar.gz --library=$R_LIBS_USER --no-test-load --no-multiarch
Expand Down Expand Up @@ -193,7 +203,7 @@ jobs:
echo "UPLOAD_NAME=$UPLOAD_NAME" >> $GITHUB_ENV
- name: upload-artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{env.UPLOAD_NAME}}
path: ${{env.ARTIFACT_NAME}}
Expand Down Expand Up @@ -278,7 +288,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, windows-2022, macos-13]
r: [4.1.3, 4.2.3, 4.3.1]
r: [4.1.3, 4.2.3, 4.3.1, 4.4.1]

runs-on: ${{ matrix.os }}

Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Encoding: UTF-8
License: Apache License 2.0
Imports:
reticulate(>= 1.25),
reticulate(<= 1.28),
methods,
rjson,
stats,
utils
Depends:
R(>= 4.0)
R(>= 4.1.3),
R(< 4.5)
Remotes:
[email protected]
Suggests: pack, R6, testthat, knitr, rmarkdown
Expand Down
6 changes: 3 additions & 3 deletions R/table.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
df <- data.frame(
Map(.convertToRType, list = df, synapseType = types),
stringsAsFactors = F)

# The Map function mangles column names (which are in the Schema), so let's fix them
colnames(df) <- .extractColumnNames(columnSchema)
df
Expand All @@ -137,7 +137,7 @@
df <- data.frame(
Map(.convertToSynapseType, list = df, synapseType = types),
stringsAsFactors = F)

# The Map function mangles column names (which are in the Schema), so let's fix them
colnames(df) <- .extractColumnNames(columnSchema)
df
Expand Down Expand Up @@ -181,4 +181,4 @@
} else {
.saveToCsv(values, file)
}
}
}
59 changes: 30 additions & 29 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
# Ideally we would source tools/installPythonClient.R to not
# have to duplicate the synapseclient install code
# system2(paste("Rscript ", getwd(), "/tools/installPythonClient.R ", getwd(), sep=""))
PYTHON_CLIENT_VERSION <- '4.0.0'
PYTHON_CLIENT_VERSION <- '4.4.0'
# reticulate::virtualenv_create('r-reticulate')
# reticulate::use_virtualenv('r-reticulate')
reticulate::py_install(c("requests<3", "pandas~=2.0.0", "pysftp", "jinja2", "markupsafe"))
reticulate::py_install(c("pandas>=1.5,<=2.0.3", "jinja2", "markupsafe","numpy<=1.24.4"))
reticulate::py_install(c(paste("synapseclient==", PYTHON_CLIENT_VERSION, sep="")), pip=T)
reticulate::py_run_string("import synapseclient")
}
)

reticulate::py_run_string(sprintf("synapserVersion = 'synapser/%s' ", utils::packageVersion("synapser")))
reticulate::py_run_string("synapseclient.USER_AGENT['User-Agent'] = synapserVersion + ' '+ synapseclient.USER_AGENT['User-Agent']")
reticulate::py_run_string("synapseclient.core.config.single_threaded = True")
reticulate::py_run_string("syn=synapseclient.Synapse(skip_checks=True)")
reticulate::py_run_string("syn=synapseclient.Synapse(skip_checks=True, debug=False)")
# make syn available in the global environment
syn <<- reticulate::py_eval("syn")

.addPythonAndFoldersToSysPath(system.file(package = "synapser"))
.defineRPackageFunctions()
# .defineOverloadFunctions() must come AFTER .defineRPackageFunctions()
# because it redefines selected generic functions
.defineOverloadFunctions()

# mute Python warnings
reticulate::py_run_string("import warnings")
reticulate::py_run_string("warnings.filterwarnings('ignore')")
Expand All @@ -57,7 +57,6 @@
assignEnumCallback = .assignEnumCallback,
functionFilter = .synapseClassFunctionFilter,
functionPrefix = "syn",
transformReturnObject = .objectDefinitionHelper,
pySingletonName = "syn")
# exposing all supporting classes except for Synapse itself and some selected classes.
generateRWrappers(pyPkg = "synapseclient",
Expand All @@ -73,23 +72,25 @@
assignEnumCallback = .assignEnumCallback,
functionFilter = .cherryPickTableFunctionFilter,
classFilter = .removeAllClassesClassFilter,
functionPrefix = "syn",
transformReturnObject = .objectDefinitionHelper)
functionPrefix = "syn")
}

.objectDefinitionHelper <- function(object) {
if (methods::is(object, "CsvFileTable")) {
# reading from csv
# Removed due to Error in unlockBinding("asDataFrame", object) : no binding for "asDataFrame"
# unlockBinding("asDataFrame", object)
object$asDataFrame <- function() {
.readCsvBasedOnSchema(object)
}
# Removed due to Error in lockBinding("asDataFrame", object) : no binding for "asDataFrame"
# lockBinding("asDataFrame", object)
}
object
}
# TODO: This section is removed since it causes the infinite recursion
# issue when reading downloaded entity to a dataframe. Revisit this
# when deprecating PythonEmbedInR code
# .objectDefinitionHelper <- function(object) {
# if (methods::is(object, "CsvFileTable")) {
# # reading from csv
# # Removed due to Error in unlockBinding("asDataFrame", object) : no binding for "asDataFrame"
# # unlockBinding("asDataFrame", object)
# object$asDataFrame <- function() {
# .readCsvBasedOnSchema(object)
# }
# # Removed due to Error in lockBinding("asDataFrame", object) : no binding for "asDataFrame"
# # lockBinding("asDataFrame", object)
# }
# object
# }

.onAttach <- function(libname, pkgname) {
tou <- "\nTERMS OF USE NOTICE:
Expand All @@ -98,7 +99,7 @@
2) Not discriminate, identify, or recontact individuals or groups represented by the data.
3) Use and contribute only data de-identified to HIPAA standards.
4) Redistribute data only under these same terms of use.\n"

.checkForUpdate()
packageStartupMessage(tou)
}
Expand Down Expand Up @@ -128,7 +129,7 @@
Table(schema, file)
}
)

methods::setMethod(
f = "synBuildTable",
signature = c("ANY", "ANY", "data.frame"),
Expand All @@ -144,10 +145,10 @@
f = "as.data.frame",
signature = c(x = "CsvFileTable"),
definition = function(x) {
x$asDataFrame()
.readCsvBasedOnSchema(x)
}
)

methods::setClass("GeneratorWrapper")
methods::setMethod(
f = "as.list",
Expand All @@ -156,19 +157,19 @@
x$asList()
}
)

methods::setGeneric(
name = "nextElem",
def = function(x) {
standardGeneric("nextElem")
}
)

methods::setMethod(
f = "nextElem",
signature = c(x = "GeneratorWrapper"),
definition = function(x) {
x$nextElem()
}
)
}
}
3 changes: 2 additions & 1 deletion auto-man/Project-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ Projects in Synapse must be uniquely named. Trying to create a project with a na
Attributes:
name: The name of the project
alias: The project alias for use in friendly project urls.
properties: A map of Synapse properties
annotations: A map of user defined annotations
local_state: Internal use only
}
\section{Methods}{
\itemize{
\item \code{Project(name=NULL, properties=NULL, annotations=NULL, local_state=NULL)}: Constructor for \code{\link{Project}}
\item \code{Project(name=NULL, properties=NULL, annotations=NULL, local_state=NULL, alias=NULL)}: Constructor for \code{\link{Project}}
\item \code{local_state(state=NULL)}: Set or get the object's internal state, excluding properties, or annotations.\cr
\cr
Arguments:\cr
Expand Down
4 changes: 3 additions & 1 deletion auto-man/Project.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ Projects in Synapse must be uniquely named. Trying to create a project with a na
Attributes:
name: The name of the project
alias: The project alias for use in friendly project urls.
properties: A map of Synapse properties
annotations: A map of user defined annotations
local_state: Internal use only
}
\usage{
Project(name=NULL, properties=NULL, annotations=NULL, local_state=NULL)
Project(name=NULL, properties=NULL, annotations=NULL, local_state=NULL, alias=NULL)
}
\arguments{
\item{name}{}
\item{properties}{}
\item{annotations}{}
\item{local_state}{}
\item{alias}{}
}
\value{
An object of type Project
Expand Down
4 changes: 3 additions & 1 deletion auto-man/synCreateExternalS3FileHandle.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ Arguments:
storage_location_id: Explicit storage location id to create the file handle in, mutually exclusive
with parent
mimetype: Mimetype of the file, if known
md5: MD5 of the file, if known

Raises:
ValueError: If neither parent nor storage_location_id is specified, or if both are specified.
}
\usage{
synCreateExternalS3FileHandle(bucket_name, s3_file_key, file_path, parent=NULL, storage_location_id=NULL, mimetype=NULL)
synCreateExternalS3FileHandle(bucket_name, s3_file_key, file_path, parent=NULL, storage_location_id=NULL, mimetype=NULL, md5=NULL)
}
\arguments{
\item{bucket_name}{}
Expand All @@ -37,6 +38,7 @@ synCreateExternalS3FileHandle(bucket_name, s3_file_key, file_path, parent=NULL,
\item{parent}{}
\item{storage_location_id}{}
\item{mimetype}{}
\item{md5}{}
}
\value{

Expand Down
39 changes: 39 additions & 0 deletions auto-man/synCreateTeam.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%
% Auto-generated file, do not modify.
% Instead, copy this file to the man/ folder, remove this warning, and edit freely.
% Use Git to identify changes in this file which suggest where to change your edited copy.
%
\name{synCreateTeam}
\alias{synCreateTeam}
\docType{methods}
\title{
synCreateTeam
}
\description{
Creates a new team.

Arguments:
name: The name of the team to create.
description: A description of the team.
icon: The FileHandleID of the icon to be used for the team.
canPublicJoin: Whether the team can be joined by anyone. Defaults to False.
canRequestMembership: Whether the team can request membership. Defaults to True.

Returns:
An object of type [synapseclient.team.Team][]
}
\usage{
synCreateTeam(name, description=NULL, icon=NULL, can_public_join=FALSE, can_request_membership=TRUE)
}
\arguments{
\item{name}{}
\item{description}{}
\item{icon}{}
\item{can_public_join}{}
\item{can_request_membership}{}
}
\value{

}


28 changes: 28 additions & 0 deletions auto-man/synDeleteTeam.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
%
% Auto-generated file, do not modify.
% Instead, copy this file to the man/ folder, remove this warning, and edit freely.
% Use Git to identify changes in this file which suggest where to change your edited copy.
%
\name{synDeleteTeam}
\alias{synDeleteTeam}
\docType{methods}
\title{
synDeleteTeam
}
\description{
Deletes a team.

Arguments:
id: The ID of the team to delete.
}
\usage{
synDeleteTeam(id)
}
\arguments{
\item{id}{}
}
\value{

}


Loading

0 comments on commit 4301c25

Please sign in to comment.