Skip to content

Commit

Permalink
Merge pull request #18 from alteryx/custom-pkg-subdirs
Browse files Browse the repository at this point in the history
Custom pkg subdirs
  • Loading branch information
emessess authored Feb 5, 2019
2 parents 3185499 + 9696bbf commit a6f6195
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: promote
Type: Package
Title: Client for the 'Alteryx Promote' API
Version: 1.1.0
Version: 1.1.1
Date: 2018-11-07
Author: Paul E. Promote <[email protected]>
Maintainer: Paul E. Promote <[email protected]>
Expand Down
25 changes: 4 additions & 21 deletions R/deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,21 @@
#' @param install whether or not the package should be installed in the model image
#' @param auth_token a personal access token for github or gitlab repositories
#' @param ref The git branch, tag, or SHA of the package to be installed
#' @param subdir The path to the repo subdirectory holding the package to be installed

add.dependency <- function(name, importName, src, version, install, auth_token, ref) {
# nulls will break the data.frame/rbind
# but we don't want to pass a version or auth token if not necessary
if (is.null(auth_token)) {
auth_token <- NA
}

if (is.null(version)) {
version <- NA
}

if (is.null(ref)) {
version <- NA
}

if (src == "version") {
ref <- NA
}

add.dependency <- function(name, importName, src, version, install, auth_token, ref, subdir) {
# Don't add the dependency if it's already there, but if a package with the same importName is present,
# make sure to enter the most recent arguments in case of ref or name update

dependencies <- promote$dependencies

if (!any(dependencies$importName == importName)) {
newRow <- data.frame(name = name, importName = importName, src = src, version = version, install = install, auth_token = auth_token, ref = ref)
newRow <- data.frame(name = name, importName = importName, src = src, version = version, install = install, auth_token = auth_token, ref = ref, subdir = subdir)
dependencies <- rbind(dependencies, newRow)
promote$dependencies <- dependencies
} else {
dependencies <- dependencies[importName != importName, ]
newRow <- data.frame(name = name, importName = importName, src = src, version = version, install = install, auth_token = auth_token, ref = ref)
newRow <- data.frame(name = name, importName = importName, src = src, version = version, install = install, auth_token = auth_token, ref = ref, subdir = subdir)
dependencies <- rbind(dependencies, newRow)
promote$dependencies <- dependencies
}
Expand Down
11 changes: 9 additions & 2 deletions R/promote.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ promote.predict <- function(model_name, data, model_owner, raw_input = FALSE, si
#' @param url A valid URL pointing to a remote hosted git repository
#' @param auth_token Personal access token string associated with a private package's repository
#' @param ref The git branch, tag, or SHA of the package to be installed
#' @param subdir The path to the repo subdirectory holding the package to be installed
#' @param install Whether the package should also be installed into the model on the
#' Promote server; this is typically set to False when the package has already been
#' added to the Promote base image.
Expand All @@ -161,9 +162,10 @@ promote.predict <- function(model_name, data, model_owner, raw_input = FALSE, si
#' src="git",
#' url="https://x-access-token:<PersonalAccessToken>ATgitlab.com/username/rpkg.git",
#' ref="stage")
#' promote.library("my_package", src="github", auth_token=<yourToken> subdir="/pathToSubdir/")
#' }
#' @importFrom utils packageDescription
promote.library <- function(name, src="version", version=NULL, user=NULL, install=TRUE, auth_token=NULL, url=NULL, ref="master") {
promote.library <- function(name, src="version", version=NULL, user=NULL, install=TRUE, auth_token=NULL, url=NULL, ref="master", subdir=NULL) {

# If a vector of CRAN packages is passed, add each of them
if (length(name) > 1) {
Expand Down Expand Up @@ -209,7 +211,12 @@ promote.library <- function(name, src="version", version=NULL, user=NULL, instal
version <- packageDescription(name)$Version
}

add.dependency(installName, name, src, version, install, auth_token, ref)
paramsList <- list(installName, name, src, version, install, auth_token, ref, subdir)
replacedNulls <- lapply(paramsList, function(x) ifelse(is.null(x), NA, x))

do.call(add.dependency, replacedNulls)

# add.dependency(installName, name, src, version, install, auth_token, ref, subdir)

set.model.require()
}
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,21 @@ model.predict(data.frame(jsonlite::fromJSON(testdata),stringsAsFactors=TRUE))

### Usage

`promote.library(name, src = "version", version = NULL, user = NULL, install = TRUE, auth_token = NULL, url = NULL, ref = "master")`
`promote.library(name, src = "version", version = NULL, user = NULL, install = TRUE, auth_token = NULL, url = NULL, ref = "master", subdir = NULL)`

**Note**: Installing custom packages from git requires Promote version 2018.4.1 or higher. Installing custom packages with `subdir` parameter requires Promote version 2019.1.0 or higher.

### Arguments

- `name` name of the package to be added
- `src` source from which the package will be installed on Promote (CRAN (version) or git)
- `version` version of the package to be added
- `src` source from which the package will be installed on Promote (CRAN or git)
- `version` version of the package to be added (CRAN only, use `ref` parameter for git packages)
- `user` Github username associated with the package
- `install` whether the package should also be installed into the model on the Promote server; this is typically set to False when the package has already been added to the Promote base image.
- `auth_token` Personal access token string associated with a private package's repository (only works when `src = 'github'`, recommended usage is to include PAT in the URL parameter while using `src='git'`)
- `url` A valid URL pointing to a remote hosted git repository (recommended)
- `ref` The git branch, tag, or SHA of the package to be installed (SHA recommended)
- `subdir` The subdirectory path of a git repository holding the package to install

**Examples:**

Expand Down
5 changes: 4 additions & 1 deletion man/add.dependency.Rd

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

6 changes: 5 additions & 1 deletion man/promote.library.Rd

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

0 comments on commit a6f6195

Please sign in to comment.