Skip to content

Commit

Permalink
License improvements
Browse files Browse the repository at this point in the history
* Use full-text workaround. Fixes r-lib#10

* Add Apache 2.0 helper.
  • Loading branch information
hadley committed Aug 10, 2017
1 parent d2195df commit cc259af
Show file tree
Hide file tree
Showing 12 changed files with 919 additions and 34 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
^revdep$
^\.travis\.yml$
^codecov\.yml$
^LICENSE\.md$
4 changes: 2 additions & 2 deletions inst/templates/gpl-v3.md → LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ and each file should have at least the “copyright” line and a pointer to
where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
Copyright (C) 2017 RStudio

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -573,7 +573,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this
when it starts in an interactive mode:

<program> Copyright (C) <year> <name of author>
usethis Copyright (C) 2017 RStudio
This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'show c' for details.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(create_package)
export(use_apl2_license)
export(use_appveyor)
export(use_build_ignore)
export(use_code_of_conduct)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# usethis 0.0.0.9000

* New `use_apl2_license()` if you want to use the Apache 2.0 license.

* The license functions (`use_mit_license()`, `use_apl2_license()`, and
`use_gpl3_license()`) save a copy of the standard license text in
`LICENSE.md`, which is then added to `.Rbuildignore`. This allows you
to follow standard licensing best practices while adhering to CRANs
requirements (#10).

* New `use_github_labels()` will automatically set up a standard set of labels,
optionally removing the default labels (#1).

Expand Down
6 changes: 2 additions & 4 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ project_name <- function(base_path = ".") {
}

use_description_field <- function(name, value, base_path = ".", overwrite = FALSE) {
path <- file.path(base_path, "DESCRIPTION")

curr <- desc::desc_get(name, file = path)[[1]]
curr <- desc::desc_get(name, file = base_path)[[1]]
if (identical(curr, value))
return()

if (is.na(curr) || overwrite) {
done(paste0("Setting DESCRIPTION ", field(name), " to ", value(value)))
desc::desc_set(name, value, file = path)
desc::desc_set(name, value, file = base_path)
}
}

Expand Down
86 changes: 69 additions & 17 deletions R/license.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,91 @@
#' Add licenses
#' Use MIT, GPL-3, or Apache 2.0 license for your package
#'
#' Adds the necessary infrastructure to declare your package as
#' distributed under either the MIT license (including the \code{LICENSE}
#' file), or GPL v3.
#' @description
#' Adds the necessary infrastructure to declare your package as licensed
#' with one of three popular open source license:
#'
#' * [MIT](https://choosealicense.com/licenses/mit/): simple and permission.
#' * [Apache 2.0](https://choosealicense.com/licenses/apache-2.0/):
#' provides patent protection.
#' * [GPL v3](https://choosealicense.com/licenses/gpl-3.0/): requires sharing
#' of improvements.
#'
#' See <https://choosealicense.com> for more details and other options.
#'
#' @details
#' CRAN does not allow you to include copies of standard licenses in your
#' package, so these functions save the license as `LICENSE.md` and add it
#' to `.Rbuildignore`.
#'
#' @name licenses
#' @param name Name of the copyright holder or holders. Separate multiple
#' individuals with \code{;}.
#' @inheritParams use_template
#' @aliases NULL
#' @md
NULL

#' @rdname licenses
#' @param copyright_holder The copyright holder for this package. Defaults to
#' \code{getOption("devtools.name")}.
#' @export
use_mit_license <- function(copyright_holder = getOption("devtools.name", "<Author>"),
use_mit_license <- function(name,
base_path = ".") {

use_description_field("License", "MIT + file LICENSE", base_path = base_path)
use_description_field(
"License", "MIT + file LICENSE",
overwrite = TRUE,
base_path = base_path
)
use_license_template("mit", name, base_path = base_path)

# Fill in template
use_template(
"mit-license.txt",
"license-mit.txt",
"LICENSE",
data = list(
year = format(Sys.Date(), "%Y"),
copyright_holder = copyright_holder
),
open = identical(copyright_holder, "<Author>"),
data = license_data(name, base_path = base_path),
base_path = base_path
)
}


#' @rdname licenses
#' @export
use_gpl3_license <- function(base_path = ".") {
use_description_field("License", "GPL-3 + file LICENSE", base_path = base_path)
use_template("gpl-v3.md", "LICENSE", base_path = base_path)
use_gpl3_license <- function(name, base_path = ".") {
use_description_field(
"License", "GPL-3",
overwrite = TRUE,
base_path = base_path
)
use_license_template("GPL-3", name = name, base_path = base_path)
}

#' @rdname licenses
#' @export
use_apl2_license <- function(name, base_path = ".") {
use_description_field(
"License", "Apache License (>= 2.0)",
overwrite = TRUE,
base_path = base_path
)
use_license_template("apache-2.0", name, base_path = base_path)
}


use_license_template <- function(license, name, base_path = ".") {
license_template <- paste0("license-", license, ".md")

use_template(
license_template,
"LICENSE.md",
data = license_data(name, base_path = base_path),
base_path = base_path,
ignore = TRUE
)
}

license_data <- function(name, base_path = ".") {
list(
year = format(Sys.Date(), "%Y"),
name = name,
project = project_name(base_path)
)
}
Loading

0 comments on commit cc259af

Please sign in to comment.