pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/R2pkg/files pkgtools/R2pkg: refactorings, sma...
details: https://anonhg.NetBSD.org/pkgsrc/rev/a0ed40af4b36
branches: trunk
changeset: 415984:a0ed40af4b36
user: rillig <rillig%pkgsrc.org@localhost>
date: Thu Oct 17 17:14:34 2019 +0000
description:
pkgtools/R2pkg: refactorings, small bugfixes, tests
find.Rcpp is now guaranteed to return a boolean.
Added some tests and many more templates that are still waiting to be
filled.
diffstat:
pkgtools/R2pkg/files/R2pkg.R | 93 ++-----
pkgtools/R2pkg/files/R2pkg_test.R | 489 ++++++++++++++++++++++++++++++-------
2 files changed, 416 insertions(+), 166 deletions(-)
diffs (truncated from 737 to 300 lines):
diff -r 02189345c87e -r a0ed40af4b36 pkgtools/R2pkg/files/R2pkg.R
--- a/pkgtools/R2pkg/files/R2pkg.R Thu Oct 17 16:13:40 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.R Thu Oct 17 17:14:34 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg.R,v 1.9 2019/10/17 01:21:12 rillig Exp $
+# $NetBSD: R2pkg.R,v 1.10 2019/10/17 17:14:34 rillig Exp $
#
# Copyright (c) 2014,2015,2016,2017,2018,2019
# Brook Milligan. All rights reserved.
@@ -49,19 +49,12 @@
level.warning <- function(...)
level.message('WARNING: ', ...)
-R_version <- function()
-{
- info <- R.Version()
- version <- paste0(info[['major']],'.',info[['minor']])
- version
-}
-
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='')
+varassign <- function(varname, value) paste0(varname, '=\t', value)
# The list of "recommended packages which are to be included in all
# binary distributions of R." (R FAQ 5.1.2 2018-10-18)
@@ -96,7 +89,7 @@
'stats',
'tools',
'utils')
-base.packages <- c('R',base.packages.FAQ.5.1.2,base.packages.other)
+base.packages <- c('R', base.packages.FAQ.5.1.2, base.packages.other)
licenses <- list()
licenses[['ACM']] <- 'acm-license'
@@ -160,12 +153,8 @@
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
-}
+end.paragraph <- function(lines)
+ if (length(lines) > 0) append(lines, '') else lines
as.sorted.list <- function(df)
{
@@ -392,34 +381,23 @@
result
}
-new.field.if.different <- function(filename,s)
+new.field.if.different <- function(filename, s)
{
- field <- field(filename,one.line(s))
+ field <- varassign(filename, one.line(s))
field.list <- read.file.as.list(filename)
if (length(field.list) == 1)
{
f <- field.list[[1]]
- if (case.insensitive.equals(f,field))
+ if (case.insensitive.equals(f, field))
field <- f
}
field
}
-todo.license <- function(s)
-{
- if (is.null(licenses[[s]]))
- todo <- '# TODO: LICENSE'
- else
- todo <- 'LICENSE'
- todo
-}
-
pkgsrc.license <- function(s)
{
license <- licenses[[s]]
- if (is.null(license))
- license <- s
- license
+ if (is.null(license)) license <- s else license
}
package <- function(s) one.line(s)
@@ -444,7 +422,8 @@
MAINTAINER
}
-find.Rcpp <- function(imps, deps) grepl('Rcpp', paste(imps, deps))
+find.Rcpp <- function(imps, deps)
+ any(grepl('Rcpp', paste(imps, deps)))
buildlink3.mk <- function(imps,deps)
{
@@ -467,30 +446,17 @@
BUILDLINK3.MK
}
-makefile.field <- function(key,value)
+varassigns <- function(key, values)
{
- # message('===> makefile.field(',key,',',value,'):')
- field <- paste0(key,'=\t',value)
- # print(field)
- field
-}
-
-makefile.fields <- function(key,values)
-{
- # message('===> makefile.fields():')
fields <- list()
for (l in values)
{
value <- unlist(l)
- # message('===> value=',value,' ',length(value),' ',value == '')
- # print(value)
if (value != '')
- fields <- append(fields,makefile.field(key,list(value)))
+ fields <- append(fields, varassign(key, list(value)))
else
- fields <- append(fields,list(''))
- # print(fields)
+ fields <- append(fields, list(''))
}
- # print(fields)
fields
}
@@ -720,18 +686,11 @@
result
}
-use.languages <- function(s1,s2)
+use.languages <- function(imps, deps)
{
-# message('===> use.languages(',s1,',',s2,'):')
-# USE_LANGUAGES <- read.file.as.values('USE_LANGUAGES')
-# if (length(USE_LANGUAGES) == 0)
-# {
-# if (find.Rcpp(s1,s2))
-# USE_LANGUAGES <- append(USE_LANGUAGES,list('USE_LANGUAGES+=\tc c++'))
-# }
USE_LANGUAGES <- list()
- if (find.Rcpp(s1,s2))
- USE_LANGUAGES <- append(USE_LANGUAGES,list('c c++'))
+ if (find.Rcpp(imps, deps))
+ USE_LANGUAGES <- append(USE_LANGUAGES, list('c c++'))
if (length(USE_LANGUAGES) == 0)
USE_LANGUAGES <- '# none'
USE_LANGUAGES <- end.paragraph(USE_LANGUAGES)
@@ -747,13 +706,13 @@
write.Makefile <- function(metadata)
{
RCSID <- paste0('# $','NetBSD$')
- CATEGORIES <- makefile.field('CATEGORIES',categories())
- MAINTAINER <- makefile.field('MAINTAINER',maintainer(arg.maintainer_email))
- COMMENT <- makefile.field('COMMENT',comment(metadata$Title))
- LICENSE <- makefile.field('LICENSE',license(metadata$License))
- R_PKGNAME <- makefile.field('R_PKGNAME',package(metadata$Package))
- R_PKGVER <- makefile.field('R_PKGVER',version(metadata$Version))
- USE_LANGUAGES <- makefile.fields('USE_LANGUAGES',use.languages(metadata$Imports,metadata$Depends))
+ CATEGORIES <- varassign('CATEGORIES',categories())
+ MAINTAINER <- varassign('MAINTAINER',maintainer(arg.maintainer_email))
+ COMMENT <- varassign('COMMENT',comment(metadata$Title))
+ LICENSE <- varassign('LICENSE',license(metadata$License))
+ R_PKGNAME <- varassign('R_PKGNAME',package(metadata$Package))
+ R_PKGVER <- varassign('R_PKGVER',version(metadata$Version))
+ USE_LANGUAGES <- varassigns('USE_LANGUAGES',use.languages(metadata$Imports,metadata$Depends))
DEPENDENCIES <- make.depends(metadata$Imports,metadata$Depends)
DEPENDS <- DEPENDENCIES[1]
BUILDLINK3.MK <- DEPENDENCIES[2]
@@ -1044,11 +1003,11 @@
conflicts <- function(pkg)
{
- conflict <- paste0('R>=',R_version())
+ conflict <- sprintf('R>=%s.%s', R.version$major, R.version$minor)
conflicts <- list()
if (pkg %in% base.packages)
{
- conflicts <- append(conflicts,makefile.field('CONFLICTS',conflict))
+ conflicts <- append(conflicts, varassign('CONFLICTS', conflict))
conflicts <- end.paragraph(conflicts)
}
conflicts
diff -r 02189345c87e -r a0ed40af4b36 pkgtools/R2pkg/files/R2pkg_test.R
--- a/pkgtools/R2pkg/files/R2pkg_test.R Thu Oct 17 16:13:40 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg_test.R Thu Oct 17 17:14:34 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg_test.R,v 1.2 2019/10/13 19:13:47 rillig Exp $
+# $NetBSD: R2pkg_test.R,v 1.3 2019/10/17 17:14:34 rillig Exp $
#
# Copyright (c) 2019
# Roland Illig. All rights reserved.
@@ -40,37 +40,8 @@
expect_equal(out, expected)
}
-test_that('make.imports', {
- imports <- make.imports('first (>= 1.0)', 'second')
-
- expect_equal(imports, c('first(>=1.0)', 'second'))
-})
-
-test_that('make.dependency', {
- imports <- make.dependency('first(>=1.0)')
-
- expect_equal(imports, c('first', '>=1.0'))
-})
-
-test_that('buildlink3.file with matching version number', {
- local_dir(package.dir)
- dependency <- make.dependency('bitops(>=0.1)')
-
- bl3 <- buildlink3.file(dependency)
-
- expect_equal(bl3, '../../math/R-bitops/buildlink3.mk')
-})
-
-# The version number of the dependency is not checked against
-# the resolved buildlink3 file.
-test_that('buildlink3.file with too high version number', {
- local_dir(package.dir)
- dependency <- make.dependency('bitops(>=1000.0)')
-
- bl3 <- buildlink3.file(dependency)
-
- expect_equal(bl3, '../../math/R-bitops/buildlink3.mk')
-})
+# test_that('level.message', {
+# })
test_that('level.warning', {
output <- ''
@@ -84,6 +55,96 @@
expect_equal(output, '[ 123 ] WARNING: message text\n')
})
+# test_that('trim.space', {
+# })
+
+# test_that('trim.blank', {
+# })
+
+# test_that('one.space', {
+# })
+
+# test_that('one.line', {
+# })
+
+# test_that('pkg.vers', {
+# })
+
+# test_that('varassign', {
+# })
+
+# test_that('adjacent.duplicates', {
+# })
+
+# test_that('paste2', {
+# })
+
+# test_that('end.paragraph', {
+# })
+
+# test_that('as.sorted.list', {
+# })
+
+test_that('read.file.as.dataframe', {
+ content <- textConnection('VAR=value\nVAR2=value2\n')
+
+ df <- read.file.as.dataframe(content)
+
+ expect_equal(length(df$line), 3)
+ expect_equal(df$line[[1]], 'VAR=value')
+ expect_equal(df$line[[2]], 'VAR2=value2')
+ expect_equal(df$line[[3]], '')
+})
+
+# test_that('categorize.key_value', {
+# })
+
+# test_that('categorize.depends', {
+# })
+
+# test_that('categorize.buildlink', {
+# })
+
+# test_that('fix.continued.lines', {
+# })
+
Home |
Main Index |
Thread Index |
Old Index