-
Notifications
You must be signed in to change notification settings - Fork 11
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
Official Air pre-commit
hook
#269
Comments
@DavisVaughan your observations are all correct IMO. Python must not necessarily be available, you can also install pre-commit with brew for example, then it will manage the python installation I think. Note that pre-commit always clones a repo using a tag or a hash from Unifying approach Splitting approach
There are many examples where the pre-commit hooks configs are directly in the root of the actual project. I'd say considerations pro and con of unifying vs splitting:
|
Noting that what we really need is something like this pre-commit/pre-commit#1453 to download pre installed binaries using pre-commit |
IIUC with Unifying Approach we'd set So that likely leaves us with Splitting Approach, where we need to decide which language: RCreate a pseudo-R package at
For I'm not exactly sure how caching of the binary between commits would work here. It sounds like maybe it is up to the R package, and we could use something like rappdirs for the location. IIUC pre-commit would build the R package the first time around and then reuse the built package for subsequent calls until the language: PythonBe like ruff and compile binary wheels and upload an air python package to pypi that just makes air available. Don't love this idea as it is a lot of extra work on our end for little benefit. language: systemhttps://pre-commit.com/#system We could write a "system" hook that assumes that the user has already installed the binary. In this case:
I don't mind this that much, and if |
With both unifying and splitting, you will point to a git repo and specify a language property, that's not unique to splitting. If you choose
To sum it up: whether or not you choose a splitting or unifying approach, you need to choose a pre-commit language. But if you choose unifying approach and |
On which pre-commit language to use: pre-commit supports standard package management mechanisms for R, rust, python and other languages. If airs usage is limited to the command line and positron / RStudio, you may not see a lot of benefit distributing it through standard package repos like CRAN, pypi etc. {styler} has been used in many different third-party tools that want to format code and I think it was beneficial to have it installable as an R package through standard mechanisms. But that's up to you. In that regard, the fact that {styler} is a pure R implementation is also a benefit. Also, a number of R users don't feel comfortable leaving the R console and an R API was certainly beneficial for {styler}. If you go for
There is one virtual environment per hook repo and
Correct.
|
Sorry my comments get so long. Hope they are not too convoluted. |
In lieu of an official pre-commit hook, you can use this if you already have air installed: repos:
# R
- repo: local
hooks:
# https://github.com/posit-dev/air
- id: air
name: Format R code with air
entry: air format .
language: system
files: \.R$ |
@SamEdwardes without |
Thank you for the suggestion! I am new to pre-commit and appreciate the feedback. |
https://github.com/pre-commit/pre-commit
Pre-commit itself seems to be written in python, so requires python to install
https://pre-commit.com/#install
Ruff example: https://github.com/astral-sh/ruff-pre-commit
I think the vibe of how the Ruff one works is that they have this pre commit hook yaml:
https://github.com/astral-sh/ruff-pre-commit/blob/main/.pre-commit-hooks.yaml
Note the
ruff format --force-exclude
call.And I think ruff itself gets installed from being listed as a requirement here:
https://github.com/astral-sh/ruff-pre-commit/blob/main/pyproject.toml
They do tag releases synced to each ruff version
https://github.com/astral-sh/ruff-pre-commit/tags
And this is how a user would reference that tag and call the hook:
https://github.com/astral-sh/ruff/blob/568cf88c6c5b5551a675ae2b13deedec0fe226cb/.pre-commit-config.yaml#L76-L79
The text was updated successfully, but these errors were encountered: