You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having found languages/all.py, as well as the PRs 812 & 120, I'm left wondering what level of Python knowledge would be needed? Merely Python modules (like for data analysis), or system-level integration & experience with git-interfacingmodules?
Thanks for any hints :-)
PS: Specifically, R would be of interest (see r-lib/styler#467) because of its use in academia.
Yep! you've found the right files to get started. I'd be happy to help you through the python parts of this if you're interested in getting started! You shouldn't need to deal with git at all as the framework bits handle that. The parts for adding a "language" are just installing $your-language packages and running the executables that get installed.
There's ~roughly a couple flavors of "languages" right now -- either those which pre-commit will bootstrap an entire environment for you (node / ruby), or where pre-commit will assume some amount of system installation (python, because well, you need python to run pre-commit) or where pre-commit assumes you've installed some sort of system tooling (go / rust / docker / etc.).
Depending on how the R ecosystem works (I'm not at all familiar with it) you'd pick to either set up a full R runtime or to depend on R already being installed at the system.
For the apis you have to implement for a language here's what they would do (for instance for R):
ENVIRONMENT_DIR
a short string which will be used for the prefix of where packages will be installed. Probably r_env or something like that. (For python for instance, we use py_env and then packages are referenced from py_env/bin/...)
get_default_version
probably don't need to implement this for a first pass -- right now this is only implemented by the python language which guesses what interpreter version to try and use for hooks.
healthy
probably don't need to implement this for a first pass -- right now this is only implemented by the python language which makes sure that a virtual environment is still dll-linked properly
install_environment
this is the tricky part and where the smart bits come in. probably need to do the following things:
install an R runtime (optional: you could just depend on R already being installed globally)
install the current repository into the ENVIRONMENT_DIR (for python this is pip install . for instance)
install additional_dependencies (also optional, but often useful for plugin-like things)
run_hook
This is usually the easiest to implement, most of them look the same as the python hook implementation:
Depending on how the R ecosystem works (I'm not at all familiar with it) you'd pick to either set up a full R runtime or to depend on R already being installed at the system.
I think we can for simplicity depend on the global installation of R.
Within the R console (again), you can install.packages("styler") to satisfy all requirements needed. So in the console, when assuming R is installed, you can run
@katrinleinweber did you ever work out how to write a pre-commit hook for styler? I'm interested in doing the same but don't want to reinvent the wheel
Activity
asottile commentedon Jan 29, 2019
Yep! you've found the right files to get started. I'd be happy to help you through the python parts of this if you're interested in getting started! You shouldn't need to deal with
gitat all as the framework bits handle that. The parts for adding a "language" are just installing $your-language packages and running the executables that get installed.There's ~roughly a couple flavors of "languages" right now -- either those which pre-commit will bootstrap an entire environment for you (
node/ruby), or where pre-commit will assume some amount of system installation (python, because well, you need python to run pre-commit) or where pre-commit assumes you've installed some sort of system tooling (go/rust/docker/ etc.).Depending on how the R ecosystem works (I'm not at all familiar with it) you'd pick to either set up a full
Rruntime or to depend onRalready being installed at the system.For the apis you have to implement for a language here's what they would do (for instance for R):
ENVIRONMENT_DIRa short string which will be used for the prefix of where packages will be installed. Probably
r_envor something like that. (For python for instance, we usepy_envand then packages are referenced frompy_env/bin/...)get_default_versionprobably don't need to implement this for a first pass -- right now this is only implemented by the
pythonlanguage which guesses what interpreter version to try and use for hooks.healthyprobably don't need to implement this for a first pass -- right now this is only implemented by the
pythonlanguage which makes sure that a virtual environment is still dll-linked properlyinstall_environmentthis is the tricky part and where the smart bits come in. probably need to do the following things:
ENVIRONMENT_DIR(for python this ispip install .for instance)additional_dependencies(also optional, but often useful for plugin-like things)run_hookThis is usually the easiest to implement, most of them look the same as the
pythonhook implementation:pre-commit/pre_commit/languages/node.py
Lines 72 to 74 in 1602382
recent PRs
Probably the best most-recent PR which added a language is this one: #751
Then the last bit is adding a few tests for that -- I can help you out with that :)
[-]How to support for a language?[/-][+]How to add support for a language?[/+]lorenzwalthert commentedon Feb 16, 2019
I think we can for simplicity depend on the global installation of R.
asottile commentedon Feb 16, 2019
Sounds good, is there a mechanism for local package installation in R?
lorenzwalthert commentedon Feb 16, 2019
Within the R console (again), you can
install.packages("styler")to satisfy all requirements needed. So in the console, when assuming R is installed, you can runasottile commentedon Jun 9, 2019
I've decided to clean this up and add it to the docs #1056 -- thanks for the issue it definitely helped me collect my thoughts on this :)
katrinleinweber commentedon Jun 9, 2019
Awesome, thank you :-)
scottgigante-immunai commentedon Aug 31, 2021
@katrinleinweber did you ever work out how to write a pre-commit hook for styler? I'm interested in doing the same but don't want to reinvent the wheel
lorenzwalthert commentedon Aug 31, 2021
@scottgigante-immunai you can use the {styler} hook from https://github.com/lorenzwalthert/precommit, hopefully soon with pre-commit.ci support :D
scottgigante-immunai commentedon Aug 31, 2021
Amazing! Thank you!