Skip to content

Commit

Permalink
minimal parsing of sys dependencies thanks to @jeroen cf #147
Browse files Browse the repository at this point in the history
  • Loading branch information
Maëlle Salmon committed May 3, 2018
1 parent 3a914d2 commit 8ae0a4a
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 5 deletions.
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ Authors@R:
role = "ctb"),
person(given = "Noam",
family = "Ross",
role = "ctb"),
role = "ctb",
comment=c(ORCID = "0000-0002-2136-0000")),
person(given = "Arfon",
family = "Smith",
role = "ctb"))
role = "ctb"),
person(given = "Jeroen",
family = "Ooms",
role = "ctb",
comment = c(ORCID = "0000-0002-4035-0289")))
Description: The 'Codemeta' Project defines a 'JSON-LD' format for describing
software metadata, as detailed at <https://codemeta.github.io>. This package
provides utilities to generate, parse, and modify 'codemeta.json' files
Expand Down
4 changes: 3 additions & 1 deletion R/codemeta_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ codemeta_description <-

codemeta$softwareSuggestions <- parse_depends(suggests)
codemeta$softwareRequirements <- parse_depends(requirements)

codemeta$softwareRequirements <- c(codemeta$softwareRequirements,
parse_sys_reqs(descr$get("Package"),
descr$get("SystemRequirements")))


## add any additional codemeta terms found in the DESCRIPTION metadata
Expand Down
19 changes: 19 additions & 0 deletions R/parse_depends.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,22 @@ add_remote_to_dep <- function(package, remotes){
remote_provider
}
}


# helper to get system dependencies
get_sys_links <- function(pkg, description = ""){
out1 <- jsonlite::fromJSON(sprintf("https://sysreqs.r-hub.io/pkg/%s", pkg), simplifyVector = FALSE)
out2 <- jsonlite::fromJSON(sprintf("https://sysreqs.r-hub.io/map/%s", curl::curl_escape(description)), simplifyVector = FALSE)
sysreqs <- unique(c(sapply(out1, names), sapply(out2, names)))
sprintf("https://sysreqs.r-hub.io/get/%s", sysreqs)
}

format_sys_req <- function(url){
list("@type" = "SoftwareApplication",
identifier = url)
}

parse_sys_reqs <- function(pkg, sys_reqs){
urls <- get_sys_links(pkg, description = sys_reqs)
purrr::map(urls, format_sys_req)
}
11 changes: 9 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@
{
"@type": "Person",
"givenName": "Noam",
"familyName": "Ross"
"familyName": "Ross",
"@id": "https://orcid.org/0000-0002-2136-0000"
},
{
"@type": "Person",
"givenName": "Arfon",
"familyName": "Smith"
},
{
"@type": "Person",
"givenName": "Jeroen",
"familyName": "Ooms",
"@id": "https://orcid.org/0000-0002-4035-0289"
}
],
"copyrightHolder": [
Expand Down Expand Up @@ -422,7 +429,7 @@
"keywords": ["metadata", "codemeta", "ropensci", "citation", "credit", "linked-data", "json-ld"],
"releaseNotes": "https://github.com/ropensci/codemetar/blob/master/NEWS.md",
"readme": "https://github.com/ropensci/codemetar/blob/master/README.md",
"fileSize": "277.352KB",
"fileSize": "278.447KB",
"contIntegration": [
"https://travis-ci.org/ropensci/codemetar",
"https://ci.appveyor.com/project/cboettig/codemetar/branch/master",
Expand Down
79 changes: 79 additions & 0 deletions inst/examples/DESCRIPTION_sysreqs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Package: codemetar
Type: Package
Title: Generate 'CodeMeta' Metadata for R Packages
Version: 0.1.6
Authors@R:
c(person(given = "Carl",
family = "Boettiger",
role = c("aut", "cre", "cph"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-1642-628X")),
person(given = "Anna",
family = "Krystalli",
role = c("rev", "ctb"),
comment = c(ORCID = "0000-0002-2378-4915")),
person(given = "Toph",
family = "Allen",
role = "rev",
comment = c(ORCID = "0000-0003-4580-091X")),
person(given = "Maëlle",
family = "Salmon",
role = c("ctb", "aut"),
comment = c(ORCID = "0000-0002-2815-0399")),
person(given = "rOpenSci",
role = "fnd",
comment = "https://ropensci.org/"),
person(given = "Katrin",
family = "Leinweber",
role = "ctb"),
person(given = "Noam",
family = "Ross",
role = "ctb"),
person(given = "Arfon",
family = "Smith",
role = "ctb"))
Description: The 'Codemeta' Project defines a 'JSON-LD' format for describing
software metadata, as detailed at <https://codemeta.github.io>. This package
provides utilities to generate, parse, and modify 'codemeta.json' files
automatically for R packages, as well as tools and examples for working with
'codemeta.json' 'JSON-LD' more generally.
License: GPL-3
URL: https://github.com/ropensci/codemetar, https://ropensci.github.io/codemetar
BugReports: https://github.com/ropensci/codemetar/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1.9000
Depends: R (>= 3.0.0)
Imports:
jsonlite (>= 1.3),
jsonld,
git2r,
devtools,
memoise,
methods,
stats,
stringi,
readr,
desc,
usethis,
whisker,
tibble,
crul,
gh,
stringr,
sessioninfo,
purrr
Suggests:
testthat,
jsonvalidate,
covr,
knitr,
rmarkdown,
magrittr,
xml2,
dplyr (>= 0.7.0),
printr
SystemRequirements: ImageMagick++: ImageMagick-c++-devel (rpm) or libmagick++-dev (deb)
VignetteBuilder: knitr
X-schema.org-keywords: metadata, codemeta, ropensci, citation, credit, linked-data
X-schema.org-isPartOf: https://ropensci.org
7 changes: 7 additions & 0 deletions tests/testthat/test-parse_depends.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ testthat::test_that("Test the various cases for ids (NOT used currently)", {
# a <- guess_dep_id(parse_depends("not-a-package")[[1]])

})

testthat::test_that("Sys requirements", {
f <- system.file("examples/DESCRIPTION_sysreqs", package = "codemetar")
descr <- codemeta_description(f)
testthat::expect_equal(descr$softwareRequirements[[22]]$identifier,
"https://sysreqs.r-hub.io/get/imagemagick")
})

0 comments on commit 8ae0a4a

Please sign in to comment.