Skip to content

Commit

Permalink
Merge pull request #92 from inbo/mit-license
Browse files Browse the repository at this point in the history
Mit license
  • Loading branch information
ThierryO authored Sep 14, 2022
2 parents 226906a + 9dbd402 commit b162fbd
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/check_on_different_r_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ jobs:
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_deps(dependencies = TRUE,
type = ifelse(.Platform$OS.type=="unix", "source", "binary"))
remotes::install_cran("rcmdcheck")
install.packages("stringi")
shell: Rscript {0}
Expand Down
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "checklist: A Thorough and Strict Set of Checks for R Packages and Source Code",
"version": "0.2.5",
"version": "0.2.6",
"description": "An opinionated set of rules for R packages and R source code projects.",
"creators": [
{
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contact:
- email: [email protected]
name: Research Institute for Nature and Forest
title: 'checklist: A Thorough and Strict Set of Checks for R Packages and Source Code'
version: 0.2.5
version: 0.2.6
abstract: An opinionated set of rules for R packages and R source code projects.
license: GPL-3.0
type: software
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: checklist
Title: A Thorough and Strict Set of Checks for R Packages and Source Code
Version: 0.2.5
Version: 0.2.6
Authors@R: c(
person("Thierry", "Onkelinx", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8804-4216")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# checklist 0.2.6

* `check_license()` allows `"MIT"` license in addition to `"GPLv3"` for packages

# checklist 0.2.5

* Add spell checking functionality.
Expand Down
46 changes: 38 additions & 8 deletions R/check_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ unchanged_repo <- function(repo, old_status) {
#'
#' Currently, following licenses are allowed:
#' - GPL-3
#' - MIT
#'
#' We will consider pull requests adding support for other open source licenses.
#'
Expand All @@ -218,9 +219,9 @@ check_license <- function(x = ".") {
problems <- sprintf(
"%s license currently not allowed.
Please send a pull request if you need support for this license.",
this_desc$get_field("License")
this_desc$get_field("License")
)[
!current_license %in% c("GPL-3")
!current_license %in% c("GPL-3", "MIT")
]
} else {
current_license <- "CC-BY"
Expand All @@ -236,22 +237,51 @@ this_desc$get_field("License")
}

# check if LICENSE.md matches the official version
current <- readLines(file.path(x$get_path, "LICENSE.md"))
current <- switch(
current_license,
"GPL-3" = readLines(file.path(x$get_path, "LICENSE.md")),
"MIT" = readLines(file.path(x$get_path, "LICENSE.md")),
"CC-BY" = readLines(file.path(x$get_path, "LICENSE.md"))
)
official <- switch(
current_license, "GPL-3" = "gplv3.md", "CC-BY" = "cc_by_4_0.md"
current_license,
"GPL-3" = "gplv3.md",
"MIT" = "mit.md",
"CC-BY" = "cc_by_4_0.md"
)
system.file("generic_template", official, package = "checklist") |>
readLines() -> official
x$add_error(
errors = c(
if (current_license == "MIT") {
author <- this_desc$get_author(role = "cph")
cph <- paste(c(author$given, author$family), collapse = " ")
problems <- c(
problems,
"Copyright holder in LICENSE.md doesn't match the one in DESCRIPTION"[
!grepl(paste0(cph, "$"), current[3])
]
)
problems <- c(
problems,
"Copyright statement in LICENSE.md not in correct format"[
!grepl(
paste0("^Copyright \\(c\\) \\d{4}(-(\\d{4})?)? ", cph, "$"),
current[3]
)
]
)
official <- official[-3]
current <- current[-3]
}
problems <- c(
problems,
"LICENSE.md doesn't match the version in the checklist package"[
(length(current) != length(official)) || any(current != official)
]
),
)
x$add_error(
errors = problems,
item = "license", keep = FALSE
)

return(x)
}

Expand Down
34 changes: 27 additions & 7 deletions R/create_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#' `YY` is the two letter code for the language variant.
#' E.g. `en-GB` for British English, `en-US` for American English, `nl-BE` for
#' Belgian Dutch.
#' @param license What type of license should be used?
#' Choice between GPL-3 and MIT.
#' Default GPL-3.
#' @export
#' @importFrom assertthat assert_that is.string
#' @importFrom fs dir_create dir_ls file_copy is_dir path
Expand Down Expand Up @@ -47,10 +50,11 @@
#' create_package(
#' path = path, package = "packagename", title = "package title",
#' description = "A short description.", maintainer = maintainer,
#' language = "en-GB"
#' language = "en-GB", license = "GPL-3"
#' )
create_package <- function(
package, path = ".", title, description, maintainer, language = "en-GB"
package, path = ".", title, description, maintainer, language = "en-GB",
license = c("GPL-3", "MIT")
) {
assert_that(
length(find.package("roxygen2", quiet = TRUE)) > 0,
Expand Down Expand Up @@ -79,6 +83,7 @@ create_package <- function(
)
assert_that(is.string(title))
validate_language(language)
license <- match.arg(license)

dir_create(path)
repo <- git_init(path = path)
Expand All @@ -102,7 +107,7 @@ Authors@R:
role = c(\"cph\", \"fnd\"),
email = \"[email protected]\"))
Description: %4$s
License: GPL-3
License: %7$s
URL: https://github.com/inbo/%1$s
BugReports: https://github.com/inbo/%1$s/issues
Encoding: UTF-8
Expand All @@ -113,7 +118,8 @@ RoxygenNote: %5$s
package, toTitleCase(title),
paste(format(maintainer, style = "R"), collapse = "\n"),
description,
installed.packages()["roxygen2", "Version"], language
installed.packages()["roxygen2", "Version"], language,
license
)
writeLines(description, path(path, "DESCRIPTION"))
tidy_desc(path)
Expand Down Expand Up @@ -177,12 +183,26 @@ RoxygenNote: %5$s
git_add("README.Rmd", repo = repo)

# add LICENSE.md
file_copy(
system.file(
path("generic_template", "gplv3.md"), package = "checklist"
file.copy(
switch(
license,
"GPL-3" = system.file(
file.path("generic_template", "gplv3.md"), package = "checklist"
),
"MIT" = system.file(
file.path("generic_template", "mit.md"), package = "checklist"
)
),
path(path, "LICENSE.md")
)
if (license == "MIT") {
mit <- readLines(file.path(path, "LICENSE.md"))
mit[3] <- gsub("<YEAR>", format(Sys.Date(), "%Y"), mit[3])
mit[3] <- gsub("<COPYRIGHT HOLDERS>",
"Research Institute for Nature and Forest",
mit[3])
writeLines(mit, file.path(path, "LICENSE.md"))
}
git_add("LICENSE.md", repo = repo)

# Add code of conduct
Expand Down
26 changes: 23 additions & 3 deletions R/setup_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
#'
#' @param path The path to the package.
#' Defaults to `"."`.
#' @param license What type of license should be used?
#' Choice between GPL-3 and MIT.
#' Default GPL-3.
#' @export
#' @importFrom assertthat assert_that
#' @importFrom desc desc
#' @importFrom fs dir_create dir_ls file_copy is_file path
#' @importFrom gert git_add
#' @importFrom utils file_test
#' @family setup
setup_package <- function(path = ".") {
setup_package <- function(path = ".",
license = c("GPL-3", "MIT")) {
path <- normalizePath(path, winslash = "/", mustWork = TRUE)
license <- match.arg(license)
assert_that(
file_test("-f", path(path, "DESCRIPTION")),
msg = paste("No DESCRIPTION file found at", path)
Expand Down Expand Up @@ -102,10 +107,25 @@ setup_package <- function(path = ".") {

# add LICENSE.md
if (length(dir_ls(path, regexp = "LICEN(S|C)E")) == 0) {
file_copy(
system.file(path("generic_template", "gplv3.md"), package = "checklist"),
file.copy(
switch(
license,
"GPL-3" = system.file(
path("generic_template", "gplv3.md"), package = "checklist"),
"MIT" = system.file(
path("generic_template", "mit.md"), package = "checklist"
)
),
path(path, "LICENSE.md")
)
if (license == "MIT") {
mit <- readLines(path(path, "LICENSE.md"))
mit[3] <- gsub("<YEAR>", format(Sys.Date(), "%Y"), mit[3])
mit[3] <- gsub("<COPYRIGHT HOLDERS>",
"Research Institute for Nature and Forest",
mit[3])
writeLines(mit, path(path, "LICENSE.md"))
}
git_add("LICENSE.md", force = TRUE, repo = path)
}

Expand Down
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ citHeader("To cite `checklist` in publications please use:")
# begin checklist entry
citEntry(
entry = "Manual",
title = "checklist: A Thorough and Strict Set of Checks for R Packages and Source Code. Version 0.2.5",
title = "checklist: A Thorough and Strict Set of Checks for R Packages and Source Code. Version 0.2.6",
author = c(person(given = "Thierry", family = "Onkelinx")),
year = 2022,
url = "https://inbo.github.io/checklist/",
abstract = "An opinionated set of rules for R packages and R source code projects.",
textVersion = "Onkelinx, Thierry (2022) checklist: A Thorough and Strict Set of Checks for R Packages and Source Code. Version 0.2.5. https://inbo.github.io/checklist/, https://github.com/inbo/checklist, https://doi.org/10.5281/zenodo.4028303",
textVersion = "Onkelinx, Thierry (2022) checklist: A Thorough and Strict Set of Checks for R Packages and Source Code. Version 0.2.6. https://inbo.github.io/checklist/, https://github.com/inbo/checklist, https://doi.org/10.5281/zenodo.4028303",
keywords = "R package, quality control",
doi = "10.5281/zenodo.4028303",
)
Expand Down
22 changes: 22 additions & 0 deletions inst/generic_template/mit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) <YEAR> <COPYRIGHT HOLDERS>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3 changes: 2 additions & 1 deletion inst/package_template/check_on_different_r_os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ jobs:
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_deps(dependencies = TRUE,
type = ifelse(.Platform$OS.type=="unix", "source", "binary"))
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/checklist_structure.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' What you get with a checklist setup:
#'
#' - minimal folder structure and files required for an R package using INBO
#' guidelines with GPL-3 license.
#' guidelines with GPL-3 or MIT license.
#' - an RStudio project file
#' - a local git repository
#' - an initial `NEWS.md` file
Expand Down
1 change: 1 addition & 0 deletions man/check_license.Rd

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

11 changes: 8 additions & 3 deletions man/create_package.Rd

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

8 changes: 6 additions & 2 deletions man/setup_package.Rd

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

7 changes: 0 additions & 7 deletions tests/testthat/test_d_check_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,4 @@ test_that("check_description() works", {
expect_identical(
x$.__enclos_env__$private$errors$DESCRIPTION, "Package version not updated"
)

file.remove(file.path(path, package, "LICENSE.md"))
expect_is(x <- check_license(file.path(path, package)), "checklist")
expect_identical(
x$.__enclos_env__$private$errors$license,
"No LICENSE.md file"
)
})
Loading

0 comments on commit b162fbd

Please sign in to comment.