From 3e4d380b49da581f0d7e1f1a15c7b6cb07abf804 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 9 Jan 2022 20:39:51 +0100 Subject: [PATCH 1/5] add standard workflow --- .Rbuildignore | 2 ++ .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 40 ++++++++++++++++++++++++++++++ cyclocomp.Rproj | 22 ++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 cyclocomp.Rproj diff --git a/.Rbuildignore b/.Rbuildignore index fdb7e2b..e0d9e02 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,5 @@ ^README.Rmd$ ^.travis.yml$ ^appveyor.yml$ +^cyclocomp\.Rproj$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..18163e4 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,40 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v1 + with: + extra-packages: rcmdcheck + + - uses: r-lib/actions/check-r-package@v1 + + - name: Show testthat output + if: always() + run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@main + with: + name: ${{ runner.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/cyclocomp.Rproj b/cyclocomp.Rproj new file mode 100644 index 0000000..69fafd4 --- /dev/null +++ b/cyclocomp.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace From d15667d82ee3afd33cc872900304e07448833012 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 9 Jan 2022 20:46:09 +0100 Subject: [PATCH 2/5] remove travis and appveyor --- .travis.yml | 34 ---------------------------------- appveyor.yml | 41 ----------------------------------------- 2 files changed, 75 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 55010e0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -## Sample .travis.yml file for use with metacran/r-builder -## See https://github.com/metacran/r-builder for details. - -language: c -sudo: required - -before_install: - - curl -OL https://raw.githubusercontent.com/metacran/r-builder/master/pkg-build.sh - - chmod 755 pkg-build.sh - - ./pkg-build.sh bootstrap - -install: - - ./pkg-build.sh install_deps - - ./pkg-build.sh install_github jimhester/covr - -script: - - ./pkg-build.sh run_tests - -after_failure: - - ./pkg-build.sh dump_logs - -after_success: - - if [[ ! -z "$COVERAGE" ]];then ./pkg-build.sh run_script -e 'covr::codecov()'; fi - -notifications: - email: - on_success: change - on_failure: change - -env: - matrix: - - RVERSION=oldrel - - RVERSION=release - - RVERSION=devel COVERAGE=true diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 7d1c45b..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,41 +0,0 @@ -# DO NOT CHANGE the "init" and "install" sections below - -# Download script file from GitHub -init: - ps: | - $ErrorActionPreference = "Stop" - Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" - Import-Module '..\appveyor-tool.ps1' - -install: - ps: Bootstrap - -# Adapt as necessary starting from here - -build_script: - - travis-tool.sh install_deps - -test_script: - - travis-tool.sh run_tests - -on_failure: - - travis-tool.sh dump_logs - -artifacts: - - path: '*.Rcheck\**\*.log' - name: Logs - - - path: '*.Rcheck\**\*.out' - name: Logs - - - path: '*.Rcheck\**\*.fail' - name: Logs - - - path: '*.Rcheck\**\*.Rout' - name: Logs - - - path: '\*_*.tar.gz' - name: Bits - - - path: '\*_*.zip' - name: Bits From 0c94e1a2220f365c13375bb83164841e88f84ffa Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 9 Jan 2022 20:53:18 +0100 Subject: [PATCH 3/5] use remotes to build source package and withr to handle local envs --- DESCRIPTION | 3 +-- NAMESPACE | 3 --- R/package_dir.R | 50 +++--------------------------------- man/cyclocomp.Rd | 8 +++--- man/cyclocomp_package.Rd | 7 ++--- man/cyclocomp_package_dir.Rd | 7 ++--- 6 files changed, 17 insertions(+), 61 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dad7be4..ae3bac4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,11 +12,10 @@ LazyData: true URL: https://github.com/MangoTheCat/cyclocomp BugReports: https://github.com/MangoTheCat/cyclocomp/issues Imports: - callr, crayon, desc, remotes, withr Suggests: testthat -RoxygenNote: 5.0.1 +RoxygenNote: 7.1.2 diff --git a/NAMESPACE b/NAMESPACE index c18cccd..13beb66 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,8 +4,6 @@ export(cyclocomp) export(cyclocomp_package) export(cyclocomp_package_dir) export(cyclocomp_q) -importFrom(callr,r) -importFrom(callr,rcmd_safe) importFrom(crayon,red) importFrom(crayon,underline) importFrom(crayon,yellow) @@ -13,4 +11,3 @@ importFrom(desc,desc_get) importFrom(remotes,install_local) importFrom(utils,head) importFrom(utils,tail) -importFrom(withr,with_dir) diff --git a/R/package_dir.R b/R/package_dir.R index 1bea7fa..22b6c56 100644 --- a/R/package_dir.R +++ b/R/package_dir.R @@ -9,10 +9,8 @@ #' #' @family cyclomatic complexity #' @importFrom remotes install_local -#' @importFrom callr r #' @importFrom desc desc_get #' @export - cyclocomp_package_dir <- function(path = ".") { tmp <- tempfile() dir.create(tmp) @@ -20,50 +18,10 @@ cyclocomp_package_dir <- function(path = ".") { pkgname <- desc_get("Package", file = file.path(path, "DESCRIPTION")) - targz <- build_package(path) - - install_local(targz, lib = tmp) - - r(libpath = c(tmp, .libPaths()), - function(pkg) { - loadNamespace(pkg) - cyclocomp::cyclocomp_package(pkg) - }, - args = list(pkgname) - ) -} - -#' @importFrom withr with_dir -#' @importFrom callr rcmd_safe - -build_package <- function(path) { - - path <- normalizePath(path) - - tmpdir <- tempfile() - dir.create(tmpdir) - on.exit(unlink(tmpdir, recursive = TRUE)) - - file.copy(path, tmpdir, recursive = TRUE) - - ## If not a tar.gz, build it. Otherwise just leave it as it is. - if (file.info(path)$isdir) { - build_status <- with_dir( - tmpdir, - rcmd_safe("build", basename(path)) - ) - unlink(file.path(tmpdir, basename(path)), recursive = TRUE) - } - - report_system_error("Build failed", build_status) - - ## replace previous handler, no need to clean up any more - on.exit(NULL) - - file.path( - tmpdir, - list.files(tmpdir, pattern = "\\.tar\\.gz$") - ) + install_local(path, lib = tmp) + withr::local_libpaths(c(tmp, .libPaths())) + withr::local_namespace(pkg) + cyclocomp::cyclocomp_package(pkgname) } #' @importFrom crayon yellow red underline diff --git a/man/cyclocomp.Rd b/man/cyclocomp.Rd index efb0dd1..d92576a 100644 --- a/man/cyclocomp.Rd +++ b/man/cyclocomp.Rd @@ -3,7 +3,6 @@ \docType{package} \name{cyclocomp} \alias{cyclocomp} -\alias{cyclocomp-package} \alias{cyclocomp_q} \title{Cyclomatic Complexity of R Code} \usage{ @@ -78,7 +77,8 @@ cyclocomp(quote({ })) } \seealso{ -Other cyclomatic.complexity: \code{\link{cyclocomp_package_dir}}, - \code{\link{cyclocomp_package}} +Other cyclomatic complexity: +\code{\link{cyclocomp_package_dir}()}, +\code{\link{cyclocomp_package}()} } - +\concept{cyclomatic complexity} diff --git a/man/cyclocomp_package.Rd b/man/cyclocomp_package.Rd index 6d80f4b..a07acd2 100644 --- a/man/cyclocomp_package.Rd +++ b/man/cyclocomp_package.Rd @@ -23,7 +23,8 @@ cyclocomp_package("methods") } } \seealso{ -Other cyclomatic.complexity: \code{\link{cyclocomp_package_dir}}, - \code{\link{cyclocomp}} +Other cyclomatic complexity: +\code{\link{cyclocomp_package_dir}()}, +\code{\link{cyclocomp}()} } - +\concept{cyclomatic complexity} diff --git a/man/cyclocomp_package_dir.Rd b/man/cyclocomp_package_dir.Rd index fa9d338..ad82c26 100644 --- a/man/cyclocomp_package_dir.Rd +++ b/man/cyclocomp_package_dir.Rd @@ -17,7 +17,8 @@ Automatically builds the package and installs it to a temporary directory. } \seealso{ -Other cyclomatic.complexity: \code{\link{cyclocomp_package}}, - \code{\link{cyclocomp}} +Other cyclomatic complexity: +\code{\link{cyclocomp_package}()}, +\code{\link{cyclocomp}()} } - +\concept{cyclomatic complexity} From 08bd65336220720dacf31d0d222b36d8143e9ddb Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 9 Jan 2022 20:55:37 +0100 Subject: [PATCH 4/5] use withr --- R/package_dir.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/package_dir.R b/R/package_dir.R index 22b6c56..888fdef 100644 --- a/R/package_dir.R +++ b/R/package_dir.R @@ -12,10 +12,7 @@ #' @importFrom desc desc_get #' @export cyclocomp_package_dir <- function(path = ".") { - tmp <- tempfile() - dir.create(tmp) - on.exit(unlink(tmp, recursive = TRUE), add = TRUE) - + tmp <- withr::local_tempdir() pkgname <- desc_get("Package", file = file.path(path, "DESCRIPTION")) install_local(path, lib = tmp) From b9b0c5a53a270c1efe8fed4fb592f87a098aec40 Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 9 Jan 2022 20:57:34 +0100 Subject: [PATCH 5/5] bump package version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae3bac4..f121fd2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cyclocomp Title: Cyclomatic Complexity of R Code -Version: 1.1.0 +Version: 1.1.0.9000 Author: Gabor Csardi Maintainer: Hannah Alexander Description: Cyclomatic complexity is a software metric (measurement),