Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit.ci does not work with our hooks #215

Closed
lorenzwalthert opened this issue Nov 2, 2020 · 8 comments
Closed

pre-commit.ci does not work with our hooks #215

lorenzwalthert opened this issue Nov 2, 2020 · 8 comments

Comments

@lorenzwalthert
Copy link
Owner

lorenzwalthert commented Nov 2, 2020

https://pre-commit.ci is an upcoming CI/CD service by the creator of pre-commit that lets you run your pre-commit hooks via GitHub (and more to come). It does not work for script, system or local hooks as discussed in pre-commit-ci/issues#13 because the Rscript executable is not installed in the standard Docker image. For pre-commit to work with our R hooks on CI/CD, we must add support for R / renv as a language in pre-commit.

Alternative: https://github.com/openproblems-bio/openproblems/blob/main/.github/workflows/pre-commit.yml

@PelzKo
Copy link

PelzKo commented Jun 28, 2021

Is the current status still to use the alternative or is R support in pre-commit.ci in sight?
Because when I tried to implement pre-commit.ci (free open source version), I got the error message "Executable Rscript not found"
Or is there just something specific to consider?

@lorenzwalthert
Copy link
Owner Author

lorenzwalthert commented Jun 28, 2021

Yes, I suggest to use this GitHub Action.

There is a pending issue (pre-commit-ci/runner-image#59) to support R out of the box. This will be through the language:r and will require {precommit} to also change the config from language: script to language: r.

@lorenzwalthert
Copy link
Owner Author

lorenzwalthert commented Sep 10, 2021

Now, R is supported as a language (pre-commit-ci/runner-image#80 (comment)). However, there are multiple problems:

  • Because in our source installation, we chose to strip away the recommended packages, {Matrix} (which is a recursive dependency of {precommit}) can't be build because build-time-dependencies are not there at runtime. This needs a new image build that does contain the recommended packages.
  • All packages that have system dependencies like {gert} won't work. System dependencies that are shipped with the package (like {git2r}) are possible if they are installed in /opt/r.
  • We can get rid or the {usethis} -> {git2r} dependency for most of {precommit}, but not the roxygenize hook but using {cli} as we do for {touchstone}.
  • the roxygen hook requires the ability to load the package, so all packages that have recursive system dependencies won't run.
  • to install system dependencies, we could use pak::local_system_dependencies() or similar, but probably they won't be persistent with /opt/r.

@lorenzwalthert
Copy link
Owner Author

lorenzwalthert commented Sep 11, 2021

@PelzKo I opened #291 to maybe document the use of GitHub Actions + {precommit} to save everyone from trial and error. In #291, there is also a link to a very elaborated Github Action workflow file that you could probably adapt.

@lorenzwalthert lorenzwalthert unpinned this issue Nov 30, 2021
@lorenzwalthert
Copy link
Owner Author

lorenzwalthert commented Dec 3, 2021

@PelzKo I am happy to say that with release v0.2.0, pre-commit.ci is working for all hooks except roxygenize if your package has dependencies that have system dependencies. Please see NEWS.md for details. TLDR; use_ci(ci = "native") for migrating existing, use_precommit() for new ones after you updated {precommit}. There is also a vignette on CI.

@luchaoqi
Copy link

Hello, I am having a similar problem:

[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('Rscript', '--vanilla', '-e', '            prefix_dir <- \'/home/lqi/.cache/pre-commit/repowt1wkajq\'\n            options(\n                repos = c(CRAN = "https://cran.rstudio.com"),\n                renv.consent = TRUE\n            )\n            source("renv/activate.R")\n            renv::restore()\n            activate_statement <- paste0(\n              \'suppressWarnings({\',\n              \'old <- setwd("\', getwd(), \'"); \',\n              \'source("renv/activate.R"); \',\n              \'setwd(old); \',\n              \'renv::load("\', getwd(), \'");})\'\n            )\n            writeLines(activate_statement, \'activate.R\')\n            is_package <- tryCatch(\n              {\n                  path_desc <- file.path(prefix_dir, \'DESCRIPTION\')\n                  suppressWarnings(desc <- read.dcf(path_desc))\n                  "Package" %in% colnames(desc)\n              },\n              error = function(...) FALSE\n            )\n            if (is_package) {\n                renv::install(prefix_dir)\n            }\n            ')
return code: 1
expected return code: 0
stdout:
    Executable `Rscript` not found
stderr: (none)
Check the log at /home/lqi/.cache/pre-commit/pre-commit.log

My config

-   repo: https://github.com/lorenzwalthert/precommit
    rev: v0.2.2.9013
    hooks:
    -   id: style-files
        language: r
    -   id: parsable-R
        language: r
    -   id: no-browser-statement
        language: r
    -   id: readme-rmd-rendered
        language: r
    -   id: roxygenize
        language: r
    -   id: use-tidy-description
        language: r
    -   id: lintr
        args: [--warn_only]
        language: r

and pre-commit was installed using pip.
Did I miss something above or should I install any extra system-level dependencies in my local environment (it doesn't have R installed but I remember pre-commit should cover it)?

@luchaoqi
Copy link

Ah, I think I got the answer: https://pre-commit.com/#r
So to make pre-commit happy, I still have to install R locally?

@lorenzwalthert
Copy link
Owner Author

You need an R installation @luchaoqi yes. R itself is not boostrapped, only the packges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants