pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/R2pkg pkgtools/R2pkg: separate R code from sh...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/dc2e22b9a29e
branches:  trunk
changeset: 415763:dc2e22b9a29e
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Oct 13 13:26:22 2019 +0000

description:
pkgtools/R2pkg: separate R code from shell code

Before, it was difficult to edit the R code since all dollars,
backslashes and backticks had to be escaped. Separating the code also
makes the R part testable on its own.

diffstat:

 pkgtools/R2pkg/Makefile       |    36 +-
 pkgtools/R2pkg/PLIST          |     3 +-
 pkgtools/R2pkg/files/R2pkg.R  |  1265 +++++++++++++++++++++++++++++++++++++++++
 pkgtools/R2pkg/files/R2pkg.sh |  1249 +---------------------------------------
 pkgtools/R2pkg/files/RELEASE  |     4 +-
 5 files changed, 1303 insertions(+), 1254 deletions(-)

diffs (truncated from 2661 to 300 lines):

diff -r 787688ca1074 -r dc2e22b9a29e pkgtools/R2pkg/Makefile
--- a/pkgtools/R2pkg/Makefile   Sun Oct 13 12:22:27 2019 +0000
+++ b/pkgtools/R2pkg/Makefile   Sun Oct 13 13:26:22 2019 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.6 2019/10/13 09:43:26 rillig Exp $
+# $NetBSD: Makefile,v 1.7 2019/10/13 13:26:22 rillig Exp $
 #
 
-VERS=          0.6.1
+VERS=          0.6.2
 PKGNAME=       R2pkg-${VERS}
 CATEGORIES=    pkgtools
 
@@ -10,33 +10,25 @@
 COMMENT=       Tool to automate initial steps in building an R package
 LICENSE=       modified-bsd
 
-WRKSRC=                        ${WRKDIR}
-NO_BUILD=              yes
-USE_LANGUAGES=         # none
-AUTO_MKDIRS=           yes
-
-DEPENDS+=              curl>=7.52.1:../../www/curl
+WRKSRC=                ${WRKDIR}
+NO_BUILD=      yes
+USE_LANGUAGES= # none
+AUTO_MKDIRS=   yes
 
-SUBST_CLASSES+=                version
-SUBST_STAGE.version=   pre-configure
-SUBST_MESSAGE.version= Substituting version in R2pkg.sh.
-SUBST_FILES.version=   R2pkg.sh
-SUBST_VARS.version=    VERS
+DEPENDS+=      curl>=7.52.1:../../www/curl
 
-SUBST_CLASSES+=                tools
-SUBST_STAGE.tools=     pre-configure
-SUBST_MESSAGE.tools=   Substituting tool locations.
-SUBST_FILES.tools=     R2pkg.sh
-SUBST_VARS.tools=      MAKE
-
-INSTALLATION_DIRS+=    sbin ${PKGMANDIR}/man8
+SUBST_CLASSES+=        R
+SUBST_STAGE.R= pre-configure
+SUBST_FILES.R= R2pkg.sh
+SUBST_VARS.R=  VERS MAKE LIBDIR
+LIBDIR=                ${PREFIX}/lib/R2pkg
 
 do-extract:
-       ${CP} ${FILESDIR}/R2pkg.sh ${WRKSRC}
-       ${CP} ${FILESDIR}/R2pkg.8 ${WRKSRC}
+       cd ${FILESDIR} && ${CP} R2pkg.* ${WRKSRC}
 
 do-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/R2pkg.sh ${DESTDIR}${PREFIX}/sbin/R2pkg
+       ${INSTALL_DATA} ${WRKSRC}/R2pkg.R ${DESTDIR}${LIBDIR}/R2pkg.R
        ${INSTALL_MAN} ${WRKSRC}/R2pkg.8 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/R2pkg.8
 
 .include "../../math/R/buildlink3.mk"
diff -r 787688ca1074 -r dc2e22b9a29e pkgtools/R2pkg/PLIST
--- a/pkgtools/R2pkg/PLIST      Sun Oct 13 12:22:27 2019 +0000
+++ b/pkgtools/R2pkg/PLIST      Sun Oct 13 13:26:22 2019 +0000
@@ -1,3 +1,4 @@
-@comment $NetBSD: PLIST,v 1.1 2015/04/25 22:06:34 brook Exp $
+@comment $NetBSD: PLIST,v 1.2 2019/10/13 13:26:22 rillig Exp $
+lib/R2pkg/R2pkg.R
 man/man8/R2pkg.8
 sbin/R2pkg
diff -r 787688ca1074 -r dc2e22b9a29e pkgtools/R2pkg/files/R2pkg.R
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.R      Sun Oct 13 13:26:22 2019 +0000
@@ -0,0 +1,1265 @@
+# $NetBSD: R2pkg.R,v 1.1 2019/10/13 13:26:22 rillig Exp $
+#
+# Copyright (c) 2014,2015,2016,2017,2018,2019
+#      Brook Milligan.  All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of the author nor the names of any contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+#
+# Create an R package in the current directory
+#
+
+arg.level                <- Sys.getenv('LEVEL')
+arg.rpkg                 <- Sys.getenv('RPKG')
+arg.packages_list        <- Sys.getenv('PACKAGES_LIST')
+arg.r2pkg                <- Sys.getenv('R2PKG')
+arg.args                 <- Sys.getenv('ARGS')
+arg.recursive            <- as.logical(Sys.getenv('RECURSIVE'))
+arg.update               <- as.logical(Sys.getenv('UPDATE'))
+arg.dependency_list      <- Sys.getenv('DEPENDENCY_LIST')
+arg.maintainer_email     <- Sys.getenv('MAINTAINER_EMAIL')
+arg.rpkg_description_url <- Sys.getenv('RPKG_DESCRIPTION_URL')
+arg.quiet_curl           <- as.logical(Sys.getenv('QUIET_CURL'))
+
+level.message <- function(...)
+  message('[ ', arg.level, ' ] ', ...)
+
+warning.message <- function(...)
+  level.message('WARNING: ', ...)
+
+R_version <- function()
+{
+  info <- R.Version()
+  version <- paste0(info[['major']],'.',info[['minor']])
+  version
+}
+
+set.locale <- function() { invisible(Sys.setlocale('LC_ALL','C')) }
+
+trim.space <- function(s) gsub('[[:space:]]','',s)
+trim.blank <- function(s) gsub('[[:blank:]]','',s)
+one.space <- function(s) gsub('[[:blank:]]+',' ',s)
+one.line <- function(s) gsub('\n',' ',s)
+pkg.vers <- function(s) gsub('_','.',s)
+field <- function(key,value) paste(key,'=\t',value,sep='')
+
+# The list of "recommended packages which are to be included in all
+# binary distributions of R." (R FAQ 5.1.2 2018-10-18)
+#
+base.packages.FAQ.5.1.2 <- c(
+  'KernSmooth',
+  'MASS',
+  'Matrix',
+  'boot',
+  'class',
+  'cluster',
+  'codetools',
+  'foreign',
+  'lattice',
+  'mgcv',
+  'nlme',
+  'nnet',
+  'rpart',
+  'spatial',
+  'survival')
+
+# Other R packages that appear in dependency lists but are included in
+# the R package.
+#
+base.packages.other <- c(
+  'grDevices',
+  'graphics',
+  'grid',
+  'methods',
+  'parallel',
+  'splines',
+  'stats',
+  'tools',
+  'utils')
+base.packages <- c('R',base.packages.FAQ.5.1.2,base.packages.other)
+
+licenses <- list()
+licenses[['ACM']]                                    <- 'acm-license'
+licenses[['ACM | file LICENSE']]                     <- 'acm-license   # OR file LICENSE'
+licenses[['APACHE']]                                 <- 'apache-1.1 OR apache-2.0'
+licenses[['Apache License 2.0']]                     <- 'apache-2.0'
+licenses[['Apache License (== 2.0)']]                <- 'apache-2.0'
+licenses[['Apache License (== 2.0) | file LICENSE']] <- 'apache-2.0    # OR file LICENSE'
+licenses[['ARTISTIC']]                               <- 'artistic OR artistic-2.0'
+licenses[['Artistic-2.0']]                           <- 'artistic-2.0'
+licenses[['BSD']]                                    <- '2-clause-bsd OR modified-bsd OR original-bsd'
+licenses[['BSD-2']]                                  <- '2-clause-bsd'
+licenses[['BSD_2_clause + file LICENSE']]            <- '2-clause-bsd  # + file LICENSE'
+licenses[['BSD 3 clause']]                           <- 'modified-bsd'
+licenses[['BSD 3 clause + file LICENSE']]            <- 'modified-bsd  # + file LICENSE'
+licenses[['BSD_3_clause + file LICENSE']]            <- 'modified-bsd  # + file LICENSE'
+licenses[['BSL-1.0']]                                <- 'boost-license'
+licenses[['CC0']]                                   <- 'cc0-1.0-universal'
+licenses[['GPL']]                                    <- 'gnu-gpl-v1 OR gnu-gpl-v2 OR gnu-gpl-v3'
+licenses[['GPL-1']]                                  <- 'gnu-gpl-v1'
+licenses[['GPL-2']]                                  <- 'gnu-gpl-v2'
+licenses[['GPL-2 | file LICENSE']]                   <- 'gnu-gpl-v2    # OR file LICENSE'
+licenses[['GPL-3']]                                  <- 'gnu-gpl-v3'
+licenses[['GPL-2 | GPL-3']]                          <- 'gnu-gpl-v2 OR gnu-gpl-v3'
+licenses[['GPL (>= 2)']]                             <- 'gnu-gpl-v2 OR gnu-gpl-v3'
+licenses[['GPL (>= 2.0)']]                           <- 'gnu-gpl-v2 OR gnu-gpl-v3'
+licenses[['GPL (>= 2) | file LICENSE']]              <- 'gnu-gpl-v2 OR gnu-gpl-v3      # OR file LICENSE'
+licenses[['GPL (>= 3)']]                             <- 'gnu-gpl-v3'
+licenses[['LGPL']]                                   <- 'gnu-lgpl-v2 OR gnu-lgpl-v2.1 OR gnu-lgpl-v3'
+licenses[['LGPL-2']]                                 <- 'gnu-lgpl-v2'
+licenses[['LGPL-2.1']]                               <- 'gnu-lgpl-v2.1'
+licenses[['LGPL-3']]                                 <- 'gnu-lgpl-v3'
+licenses[['LGPL-3 + file LICENSE']]                  <- 'gnu-lgpl-v3   # + file LICENSE'
+licenses[['LGPL-2 | LGPL-3']]                        <- 'gnu-lgpl-v2 OR gnu-lgpl-v3'
+licenses[['LGPL (>= 2)']]                            <- 'gnu-lgpl-v2 OR gnu-lgpl-v2.1 OR gnu-lgpl-v3'
+licenses[['LUCENT']]                                 <- 'lucent'
+licenses[['Lucent Public License']]                  <- 'lucent'
+licenses[['MIT']]                                    <- 'mit'
+licenses[['MIT + file LICENSE']]                     <- 'mit   # + file LICENSE'
+licenses[['MIT + file LICENSE | Unlimited']]         <- 'mit   # + file LICENSE OR unlimited'
+licenses[['MPL-1.0']]                                <- 'mpl-1.0'
+licenses[['MPL-1.1']]                                <- 'mpl-1.1'
+licenses[['MPL-2.0']]                                <- 'mpl-2.0'
+licenses[['MPL-2.0 | file LICENSE']]                 <- 'mpl-2.0       # OR file LICENSE'
+licenses[['POSTGRESQL']]                             <- 'postgresql-license'
+
+adjacent.duplicates <- function(x)
+{
+  a <- x[-length(x)]
+  b <- x[-1]
+  dups <- a == b
+  dups <- c(FALSE,dups)
+  dups
+}
+
+paste2 <- function(s1,s2)
+{
+  if (is.na(s1) && is.na(s2)) return ('')
+  if (is.na(s1) && !is.na(s2)) return (s2)
+  if (!is.na(s1) && is.na(s2)) return (s1)
+  if (!is.na(s1) && !is.na(s2)) return (paste(s1,s2))
+}
+
+end.paragraph <- function(l,l1=l,l2=list())
+{
+  if (length(l1) > 0 || length(l2) > 0)
+    l <- append(l,'')
+  l
+}
+
+as.sorted.list <- function(df)
+{
+  l <- list()
+  df <- df[!duplicated(df),]
+  if (nrow(df) > 0)
+    {
+      key <- as.vector(df[,1])
+      value <- as.vector(df[,2])
+      key <- order(key,value)
+      l <- as.list(value[key])
+    }
+  l
+}
+
+read.file.as.dataframe <- function(filename)
+{
+  # message('===> read.file.as.dataframe(',filename,')')
+  contents <- as.list(readLines(filename))
+  df <- data.frame()
+  for (line in contents)
+    {
+      # str(line)
+      df <- rbind(df,data.frame(line=line,stringsAsFactors=FALSE))
+    }
+  df
+}
+
+categorize.key_value <- function(df,line='line')
+{
+  re.skip_blank <- '[[:blank:]]*'
+  re.blank <- '[[:blank:]]+'
+  re.anything <- '.*'
+
+  re.key <- '[^+=[:blank:]]+'
+  re.operator <- '[+=]+'
+  re.delimiter <- re.skip_blank
+  re.value <- re.anything
+  re.optional_TODO <- '(#[[:blank:]]*TODO[[:blank:]]*:[[:blank:]]*)*'
+
+  re.match_key_value_line <- paste0('^',
+    re.skip_blank,
+    re.optional_TODO,
+    re.key,
+    re.skip_blank,
+    re.operator,
+    re.delimiter,
+    re.value,
+    '$')
+
+  re.match_key <- paste0('^',
+    re.skip_blank,
+    re.optional_TODO,
+    '(',re.key,')',
+    re.skip_blank,
+    re.operator,
+    re.delimiter,
+    re.value,



Home | Main Index | Thread Index | Old Index