forked from ropensci/codemetar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include dependencies as SoftwareApplication types with name, version, provider publisher-> provider for CRAN/BIOC tidier json output (fewer empty nodes) tidier, more sensible subroutines. cleaner logic for handling pkg="." vs pkg="packagename"
- Loading branch information
Showing
10 changed files
with
317 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
#' create_codemeta | ||
#' | ||
#' create a codemeta list object in R for further manipulation | ||
#' @inheritParams write_codemeta | ||
#' @return a codemeta list object | ||
#' @export | ||
#' @examples | ||
#' cm <- create_codemeta("jsonlite") | ||
#' cm$keywords <- list("metadata", "ropensci") | ||
#' write_codemeta(cm = cm) | ||
create_codemeta <- function(pkg = ".", | ||
path = "codemeta.json", | ||
version = "2", | ||
...){ | ||
|
||
cm <- new_codemeta() | ||
descr <- read_dcf(pkg) | ||
cm <- import_pkg_description(descr = descr, cm = cm, version = version) | ||
|
||
## legacy support only | ||
if(version == "1") return(cm) | ||
|
||
readme <- get_file("README.md", pkg) | ||
|
||
cm$contIntegration <- guess_ci(readme) | ||
cm$developmentStatus <- guess_devStatus(readme) | ||
cm$provider <- guess_provider(cm$name) | ||
|
||
|
||
## Add blank slots as placeholders? and declare as an S3 class? | ||
|
||
cm | ||
} | ||
|
||
|
||
|
||
|
||
## generate codemeta.json from a DESCRIPTION file | ||
## FIXME parse and use crosswalk to reference DESCRIPTION terms? | ||
import_pkg_description <- | ||
function(descr, | ||
id = NULL, | ||
cm = new_codemeta(), | ||
version = "2") { | ||
version <- as.character(version) | ||
|
||
|
||
|
||
switch(version, | ||
"2" = codemeta_description(descr, id, cm), | ||
"1" = create_codemeta_v1(descr, id)) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,35 @@ | ||
## internal method for parsing a list of package dependencies into pkg URLs | ||
|
||
|
||
## cache avail packages | ||
avail <- utils::available.packages(utils::contrib.url("https://cran.rstudio.com", "source")) | ||
|
||
|
||
## FIXME: makes a list of package URLs. Technically we could declare a different type for these, e.g. SoftwareApplication or SoftwareSourceCode | ||
## Revisit with SoftwareSourceCode and just implement fields suggested in schema v1 | ||
#' @importFrom utils available.packages contrib.url | ||
parse_depends <- function(deps){ | ||
if(!is.null(deps)) | ||
str <- strsplit(deps, ",\n*")[[1]] | ||
else | ||
str <- NULL | ||
|
||
out <- lapply(str, function(str){ | ||
lapply(str, function(str){ | ||
|
||
if(length(str) > 1){ | ||
warning(paste0("package depends", str, "may be multiple packages?")) | ||
} | ||
|
||
## this is vectorized, though we apply it pkg by pkg anyhow | ||
pkg <- gsub("\\s*(\\w+)\\s.*", "\\1", str) | ||
pkg <- gsub("\\s+", "", pkg) | ||
|
||
pkgs <- gsub("\\s*(\\w+)\\s.*", "\\1", str) | ||
out <- list("@type" = "SoftwareApplication", | ||
name = pkg) | ||
|
||
## Add Version if available | ||
pattern <- "\\s*\\w+\\s+\\([><=]+\\s([1-9.\\-]*)\\)*" | ||
versions <- gsub(pattern, "\\1", str) | ||
## We want a NULL, not the full string, if no match is found | ||
nomatch <- !grepl(pattern, str) | ||
versions[nomatch] <- NA | ||
|
||
pkgs <- gsub("\\s+", "", pkgs) | ||
|
||
## Check if pkg is on CRAN | ||
if(all(pkgs %in% avail[,"Package"])){ | ||
pkgs <- paste0("https://cran.r-project.org/package=", pkgs) | ||
} else { | ||
## Consider suppressing message (and fixing url) for R & base packages? | ||
# message(paste("could not find URL for package", pkgs, "since it is not available on CRAN.")) | ||
} | ||
pkgs | ||
}) | ||
version <- gsub(pattern, "\\1", str) | ||
has_version <- grepl(pattern, str) | ||
if(has_version) | ||
out$version <- version | ||
|
||
out | ||
out$provider <- guess_provider(pkg) | ||
|
||
out | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.