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: format source code



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5478c20827c3
branches:  trunk
changeset: 403361:5478c20827c3
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Oct 25 19:00:16 2019 +0000

description:
pkgtools/R2pkg: format source code

diffstat:

 pkgtools/R2pkg/files/R2pkg.R      |   551 ++++++++-----------
 pkgtools/R2pkg/files/R2pkg_test.R |  1049 ++++++++++++++++++------------------
 2 files changed, 761 insertions(+), 839 deletions(-)

diffs (truncated from 2283 to 300 lines):

diff -r 41358ac53ef4 -r 5478c20827c3 pkgtools/R2pkg/files/R2pkg.R
--- a/pkgtools/R2pkg/files/R2pkg.R      Fri Oct 25 14:48:17 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.R      Fri Oct 25 19:00:16 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: R2pkg.R,v 1.26 2019/10/19 22:10:58 rillig Exp $
+# $NetBSD: R2pkg.R,v 1.27 2019/10/25 19:00:16 rillig Exp $
 #
 # Copyright (c) 2014,2015,2016,2017,2018,2019
 #      Brook Milligan.  All rights reserved.
@@ -141,41 +141,37 @@
 adjacent.duplicates <- function(lines)
   c(FALSE, lines[-length(lines)] == lines[-1])
 
-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))
+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(lines)
   if (length(lines) > 0) append(lines, '') else lines
 
-as.sorted.list <- function(df)
-{
+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])
-    }
+  {
+    key <- as.vector(df[, 1])
+    value <- as.vector(df[, 2])
+    key <- order(key, value)
+    l <- as.list(value[key])
+  }
   l
 }
 
-mklines.get_value <- function(mklines, varname, default = '')
-{
+mklines.get_value <- function(mklines, varname, default = '') {
   values <- mklines$old_value[mklines$key == varname]
   if (length(values) == 0)
     values <- mklines$old_value[mklines$key == paste0('#', varname)]
   if (length(values) == 1) values[1] else default
 }
 
-categorize.key_value <- function(df,line='line')
-{
+categorize.key_value <- function(df, line='line') {
   re_varassign <- paste0(
     '^',
     ' *',
@@ -198,8 +194,7 @@
   df
 }
 
-categorize.depends <- function(df, line='line')
-{
+categorize.depends <- function(df, line='line') {
   df$depends <- df$key_value & df$key == 'DEPENDS'
   df$category[df$depends] <- unlist(relpath_category(df[df$depends, line]))
   df
@@ -212,32 +207,29 @@
   df
 }
 
-fix.continued.lines <- function(df,line='line')
-{
+fix.continued.lines <- function(df, line='line') {
   if (nrow(df) < 2)
     return(df)
 
   continued <- grepl('\\\\$', df[, line])
   continued_key_value <- df$key_value & continued
 
-  if (FALSE %in% df[continued,'key_value'])
+  if (FALSE %in% df[continued, 'key_value'])
     level.warning('unhandled continued line(s)')
 
-  for (i in 1 : (nrow(df) - 1))
-    {
-      if (!continued_key_value[i])
-        next
+  for (i in 1:(nrow(df) - 1)) {
+    if (!continued_key_value[i])
+      next
 
-      df[i, line] <- sub('[\t ]*\\\\$', '', df[i, line])
-      df$key_value[i + 1] <- TRUE
-      df$key[i + 1] <- df$key[i]
-      df[i + 1, line] <- paste0(df$key[i], '+=', df[i + 1, line])
-    }
+    df[i, line] <- sub('[\t ]*\\\\$', '', df[i, line])
+    df$key_value[i + 1] <- TRUE
+    df$key[i + 1] <- df$key[i]
+    df[i + 1, line] <- paste0(df$key[i], '+=', df[i + 1, line])
+  }
   df
 }
 
-read_mklines <- function(filename)
-{
+read_mklines <- function(filename) {
   df <- data.frame()
   for (line in as.list(readLines(filename)))
     df <- rbind(df, data.frame(line = line, stringsAsFactors = FALSE))
@@ -252,16 +244,14 @@
   df
 }
 
-read.file.as.list <- function(filename)
-{
+read.file.as.list <- function(filename) {
   result <- list()
   info <- file.info(filename)
-  size <- info[filename,'size']
-  if (!is.na(size) && size > 0)
-    {
-       contents <- readLines(filename)
-       result <- as.list(contents)
-    }
+  size <- info[filename, 'size']
+  if (!is.na(size) && size > 0) {
+    contents <- readLines(filename)
+    result <- as.list(contents)
+  }
   result
 }
 
@@ -270,22 +260,19 @@
 remove.quotes <- function(s) gsub('[\'`"]', '', s)
 remove.articles <- function(s) gsub('\\b[Aa]n?\\b', '\\1', s)
 
-case.insensitive.equals <- function(s1,s2)
-{
+case.insensitive.equals <- function(s1, s2) {
   s1.lower <- tolower(simplify.whitespace(s1))
   s2.lower <- tolower(simplify.whitespace(s2))
   s1.lower == s2.lower
 }
 
-weakly.equals <- function(s1,s2)
-{
+weakly.equals <- function(s1, s2) {
   case.insensitive.equals(
     remove.articles(remove.quotes(remove.punctuation(s1))),
     remove.articles(remove.quotes(remove.punctuation(s2))))
 }
 
-license <- function(mklines, s)
-{
+license <- function(mklines, s) {
   license <- licenses[[s]]
   if (is.null(license))
     license <- s
@@ -298,68 +285,59 @@
 find.Rcpp <- function(imps, deps)
   any(grepl('Rcpp', paste(imps, deps)))
 
-buildlink3.mk <- function(imps,deps)
-{
+buildlink3.mk <- function(imps, deps) {
   BUILDLINK3.MK <- data.frame()
   buildlink3.mk.list <- read.file.as.list('BUILDLINK3.MK')
-  for (line in buildlink3.mk.list)
-    {
-      fields <- strsplit(line[[1]],'/',fixed=TRUE)
-      key <- fields[[1]][3]
-      value <- line
-      BUILDLINK3.MK <- rbind(BUILDLINK3.MK,data.frame(key=key,value=value))
-    }
-  if (find.Rcpp(imps,deps))
-    {
-      buildlink3.line <- '.include "../../devel/R-Rcpp/buildlink3.mk"'
-      key <- 'devel'
-      value <- buildlink3.line
-      BUILDLINK3.MK <- rbind(BUILDLINK3.MK,data.frame(key=key,value=value))
-    }
+  for (line in buildlink3.mk.list) {
+    fields <- strsplit(line[[1]], '/', fixed = TRUE)
+    key <- fields[[1]][3]
+    value <- line
+    BUILDLINK3.MK <- rbind(BUILDLINK3.MK, data.frame(key = key, value = value))
+  }
+  if (find.Rcpp(imps, deps)) {
+    buildlink3.line <- '.include "../../devel/R-Rcpp/buildlink3.mk"'
+    key <- 'devel'
+    value <- buildlink3.line
+    BUILDLINK3.MK <- rbind(BUILDLINK3.MK, data.frame(key = key, value = value))
+  }
   BUILDLINK3.MK
 }
 
-varassigns <- function(key, values)
-{
+varassigns <- function(key, values) {
   fields <- list()
-  for (l in values)
-    {
-      value <- unlist(l)
-      if (value != '')
-        fields <- append(fields, varassign(key, list(value)))
-      else
-        fields <- append(fields, list(''))
-    }
+  for (l in values) {
+    value <- unlist(l)
+    if (value != '')
+      fields <- append(fields, varassign(key, list(value)))
+    else
+      fields <- append(fields, list(''))
+  }
   fields
 }
 
 categories <- function() basename(dirname(getwd()))
 
-filter.imports <- function(s)
-{
-  for (pkg in base.packages)
-    {
-      re.pkg <- paste('^',pkg,sep='')
-      s <- s[!grepl(re.pkg,s)]
-    }
+filter.imports <- function(s) {
+  for (pkg in base.packages) {
+    re.pkg <- paste('^', pkg, sep = '')
+    s <- s[!grepl(re.pkg, s)]
+  }
   s
 }
 
-make.imports <- function(s1,s2)
-{
-  s <- paste2(s1,s2)
-  s <- gsub('([[:alnum:]]+)[[:blank:]]+(\\([^\\)]*\\))?[[:blank:]]*,?','\\1 \\2,',s)
-  imports <- na.omit(unlist(strsplit(s,',[[:blank:]]*')))
+make.imports <- function(s1, s2) {
+  s <- paste2(s1, s2)
+  s <- gsub('([[:alnum:]]+)[[:blank:]]+(\\([^\\)]*\\))?[[:blank:]]*,?', '\\1 \\2,', s)
+  imports <- na.omit(unlist(strsplit(s, ',[[:blank:]]*')))
   imports <- trim.space(imports)
   imports <- filter.imports(imports)
   imports
 }
 
-make.dependency <- function(s)
-{
-  s <- gsub('\\)','',s)
-  s <- gsub('-','.',s)
-  unlist(strsplit(s,'\\('))
+make.dependency <- function(s) {
+  s <- gsub('\\)', '', s)
+  s <- gsub('-', '.', s)
+  unlist(strsplit(s, '\\('))
 }
 
 depends <- function(dependency) dependency[1]
@@ -370,20 +348,17 @@
 new.depends.pkg <- function(dependency)
   Sys.glob(paste0('../../wip/R-', depends(dependency)))
 
-depends.pkg.fullname <- function(dependency,index=1)
-{
-  result <- system(paste('cd',depends.pkg(dependency)[index],'&& bmake show-var VARNAME=PKGNAME'),intern=TRUE)
+depends.pkg.fullname <- function(dependency, index=1) {
+  result <- system(paste('cd', depends.pkg(dependency)[index], '&& bmake show-var VARNAME=PKGNAME'), intern = TRUE)
   result
 }
 
-depends.pkg.vers <- function(dependency,index=1)
-{
-  result <- sub('^(.*)-([^-]*)$','\\2',depends.pkg.fullname(dependency,index))
+depends.pkg.vers <- function(dependency, index=1) {
+  result <- sub('^(.*)-([^-]*)$', '\\2', depends.pkg.fullname(dependency, index))
   result
 }
 
-depends.vers <- function(dependency, index=1)
-{
+depends.vers <- function(dependency, index=1) {
   if (length(dependency) == 2)
     trim.space(dependency[2])
   else
@@ -393,23 +368,20 @@
 depends.vers.2 <- function(dependency)
   ifelse(length(dependency) == 2, trim.space(dependency[2]), '>=???')



Home | Main Index | Thread Index | Old Index