diff --git a/.Rbuildignore b/.Rbuildignore index 131ffee..323913e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,6 +6,7 @@ ^README.rst$ ^Rakefile$ ^\.air.toml$ +^\.claude$ ^\.editorconfig$ ^\.git$ ^\.github$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 106ba5d..da505fa 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,13 +1,14 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/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 +permissions: read-all + jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} @@ -18,8 +19,8 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} - - {os: windows-latest, r: 'release'} + # - {os: macOS-latest, r: 'release'} + # - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} @@ -31,6 +32,9 @@ jobs: steps: - uses: actions/checkout@v4 + # - if: runner.os == 'macOS' + # run: brew install --cask xquartz + - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r@v2 @@ -41,18 +45,10 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: rcmdcheck + extra-packages: any::rcmdcheck + needs: check - uses: r-lib/actions/check-r-package@v2 - - - 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 + # with: + # upload-snapshots: true + # build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index f94eebb..03362af 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -29,4 +29,4 @@ jobs: - name: Test coverage run: covr::codecov() - shell: Rscript {0} + shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index 8e98768..8f831f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: argparse Type: Package Title: Command Line Optional and Positional Argument Parser -Version: 2.3.1 +Version: 2.3.2-1 Authors@R: c(person("Trevor L.", "Davis", role=c("aut", "cre"), email="trevor.l.davis@gmail.com", comment = c(ORCID = "0000-0001-6341-4639")), diff --git a/NEWS.md b/NEWS.md index b777a03..c458041 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +argparse 2.3.2 (development) +============================ + +* `ArgumentParser()` now also checks the `LITTLER_SCRIPT_PATH` environment variable for the script name so it works when called from `littler`. + argparse 2.3.1 ============== diff --git a/R/argparse.R b/R/argparse.R index c5ee4e1..02f23e2 100644 --- a/R/argparse.R +++ b/R/argparse.R @@ -453,13 +453,25 @@ needs_prog <- function(argument_names) { # Manually copied over from getopt to eliminate it as a dependency get_Rscript_filename <- function() { - prog <- sub("--file=", "", grep("--file=", commandArgs(), value = TRUE)[1]) - if (.Platform$OS.type == "windows") { + args <- command_args() + args_idx <- match("--args", args) + if (!is.na(args_idx)) { + args <- args[seq_len(args_idx - 1L)] + } + prog <- sub("--file=", "", grep("^--file=", args, value = TRUE)[1L]) + if (is.na(prog)) { + prog <- littler_script_path() + } + if (!is.na(prog) && .Platform$OS.type == "windows") { prog <- gsub("\\\\", "\\\\\\\\", prog) } prog } +command_args <- function() commandArgs() + +littler_script_path <- function() Sys.getenv("LITTLER_SCRIPT_PATH", unset = NA_character_) + # Internal function to check python cmd is okay # @param python_cmd Python cmd to use assert_python_cmd <- function(python_cmd) { diff --git a/raw-data/logo.R b/data-raw/logo.R similarity index 100% rename from raw-data/logo.R rename to data-raw/logo.R diff --git a/tests/testthat/test-argparse.R b/tests/testthat/test-argparse.R index 66dffd3..581ed56 100644 --- a/tests/testthat/test-argparse.R +++ b/tests/testthat/test-argparse.R @@ -459,3 +459,39 @@ test_that("Paths that `quit()`", { expect_equal("usage: scripts/test_help.R [-h]", help[1]) expect_equal(" -h, --help show this help message and exit", help[4]) }) + + +test_that("get_Rscript_filename() ignores --file= after --args", { + local_mocked_bindings( + command_args = function() c("Rscript", "--file=script.R", "--args", "--file=fake.R") + ) + expect_equal(get_Rscript_filename(), "script.R") +}) + +test_that("get_Rscript_filename() works with no --args", { + local_mocked_bindings( + command_args = function() c("Rscript", "--file=script.R") + ) + expect_equal(get_Rscript_filename(), "script.R") +}) + +test_that("get_Rscript_filename() returns NA when no --file=", { + local_mocked_bindings( + command_args = function() character(0) + ) + expect_equal(get_Rscript_filename(), NA_character_) +}) + +test_that("get_Rscript_filename() returns NA when no --file= before --args", { + local_mocked_bindings( + command_args = function() c("R", "--args", "--file=boo.r") + ) + expect_equal(get_Rscript_filename(), NA_character_) +}) + +test_that("get_Rscript_filename() returns LITTLER_SCRIPT_PATH when set", { + local_mocked_bindings( + littler_script_path = function() "script.r" + ) + expect_equal(get_Rscript_filename(), "script.r") +})