From f71051976519ccfbb9c859c68c7d0483dee136e6 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Thu, 3 Sep 2026 15:02:49 +0100 Subject: [PATCH 1/2] feat: added get_package_license to module creation --- R/module-create.R | 35 +++++++++++++++++-- inst/extdata/translation_skeleton/DESCRIPTION | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/R/module-create.R b/R/module-create.R index c3d07e0..32a9ab0 100644 --- a/R/module-create.R +++ b/R/module-create.R @@ -57,12 +57,17 @@ i18n_module_create <- function( module_path, rstudio_project = if (isTRUE(rstudio_project)) module_name else NULL ) + + license <- get_package_license(package_path) + copy_license_file(package_path, module_path) + modify_description( module_path, module_name = module_name, package = package, version = version, - language = language + language = language, + license = license ) macros <- tools::loadPkgRdMacros(package_path) @@ -266,7 +271,8 @@ copy_pkg_template <- function(path, rstudio_project = TRUE) { } -modify_description <- function(path, module_name, package, version, language) { +modify_description <- function(path, module_name, package, version, language, + license = NULL) { description_file <- file.path(path, "DESCRIPTION") description_template <- paste0(readLines(description_file), collapse = "\n") @@ -275,12 +281,35 @@ modify_description <- function(path, module_name, package, version, language) { data = list( module_name = module_name, package_version = paste0(package, " (== ", version, ")"), - language = language + language = language, + license = license ) ) writeLines(description_text, description_file) } +get_package_license <- function(package_path) { + description_file <- file.path(package_path, "DESCRIPTION") + tryCatch( + read.dcf(description_file, fields = "License")[[1]], + error = function(e) NULL + ) +} + +copy_license_file <- function(package_path, module_path) { + license_files <- c("LICENSE", "LICENSE.md", "LICENSE.txt", "LICENCE", "LICENCE.md") + + for (file in license_files) { + src_file <- file.path(package_path, file) + if (file.exists(src_file)) { + dest_file <- file.path(module_path, file) + file.copy(src_file, dest_file, overwrite = TRUE) + return(invisible(TRUE)) + } + } + invisible(FALSE) +} + valid_package_name <- function(x) { grepl(paste0("^(", .standard_regexps()$valid_package_name, ")$"), x) } diff --git a/inst/extdata/translation_skeleton/DESCRIPTION b/inst/extdata/translation_skeleton/DESCRIPTION index ea396b9..407a6fc 100644 --- a/inst/extdata/translation_skeleton/DESCRIPTION +++ b/inst/extdata/translation_skeleton/DESCRIPTION @@ -6,7 +6,7 @@ Date: 2024-05-26 Author: Who wrote it Maintainer: Who to complain to Description: More about what it does (maybe more than one line) -License: What license is it under? +License: {{license}} Language: {{language}} Translates: {{package_version}} LazyData: true From 715d8e1ddf140e267c9f53fc59c989909fb61252 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Sun, 6 Sep 2026 16:51:36 +0100 Subject: [PATCH 2/2] feat: gracefully handle missing licence files and license names --- R/module-create.R | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/R/module-create.R b/R/module-create.R index 32a9ab0..0726d6f 100644 --- a/R/module-create.R +++ b/R/module-create.R @@ -59,7 +59,7 @@ i18n_module_create <- function( ) license <- get_package_license(package_path) - copy_license_file(package_path, module_path) + license_file_copied <- copy_license_file(package_path, module_path) modify_description( module_path, @@ -67,7 +67,8 @@ i18n_module_create <- function( package = package, version = version, language = language, - license = license + license = license, + license_file_copied = license_file_copied ) macros <- tools::loadPkgRdMacros(package_path) @@ -272,9 +273,17 @@ copy_pkg_template <- function(path, rstudio_project = TRUE) { modify_description <- function(path, module_name, package, version, language, - license = NULL) { + license = NULL, license_file_copied = FALSE) { description_file <- file.path(path, "DESCRIPTION") description_template <- paste0(readLines(description_file), collapse = "\n") + + if (is.null(license)) { + if (license_file_copied) { + license <- "Inherited from source package" + } else { + license <- "Not Specified" + } + } description_text <- whisker::whisker.render( description_template, @@ -285,6 +294,12 @@ modify_description <- function(path, module_name, package, version, language, license = license ) ) + + # Remove License: NA lines if no license field should be present + if (is.na(license)) { + description_text <- gsub("License: NA\n?", "", description_text) + } + writeLines(description_text, description_file) } @@ -304,10 +319,10 @@ copy_license_file <- function(package_path, module_path) { if (file.exists(src_file)) { dest_file <- file.path(module_path, file) file.copy(src_file, dest_file, overwrite = TRUE) - return(invisible(TRUE)) + return(TRUE) } } - invisible(FALSE) + return(FALSE) } valid_package_name <- function(x) {