Pre-commit hooks for G
Project description
= Pre-Commit Hooks for G
This is the repository for holding the pre-commit hooks for G code (LabVIEW).
The code was developed over the pre-commit platform in python and uses G-CLI to call labview.
== Usage
Setup and usage of pre-commit hooks are well documented in link:https://pre-commit.com/#usage[Pre-Commit website].
Each hook has its own configuration and that is detailed down below in the available hooks section.
The main tool has some options that can be used as arguments in each of the hooks. Use this with caution, as this is not a global configuration, and can cause undesired effects running on multiple hooks at once.
[cols="1,1"]
|===
|Argument |description
|--allow-dialogs
|Allow dialogs option from G-CLI. Check G-CLI documentation.
|--debug
|Enables debugging of the hook wrapper, it does not close the VI after running.
|--hook-args and \--
|It is possible to forward args to the hooks. Use this as your last argument and the arguments to the hook as items in the list. Include a \-- at the end to split from the wrapper arguments. Arguments need to use a different leading notation, not - or \--, as they are recognized as python argparse arguments.
|===
== Available Hooks
The available hooks are mainly listed in the .pre-commit-hooks.yaml.
Here is a small description on the ones available now. For supported file types you may check the .pre-commit-hooks.yaml file.
* VI Broke - check if VI is in executable state.
* VI Description - check if there is a VI description.
* Yellow - G Code formatter - format the VIs, rearranging Windows, ... (Some steps were borrowed from the Nattify). None of the steps are configurable, not even by INI entries. Name is a reference to the Black, which is a opinionated formatter for Python.
== Design
Because there is no support for direct G support in the pre-commits, it was decided to create a python wrapper that will call the labview hooks using G-CLI.
The hooks were simplified with a LabVIEW Wrapper, so they do not need to handle all arguments received by the Pre-Commit framework.
Instead it just receive a cluster with the required data.
The Python code handles arguments and calling the G-CLI for the specific hook
The coded iterates over the different files in one call, avoiding performance issues by calling the hook wrapper many times.
== Contributing
You can decide to create new hooks or contribute with the python code.
Either way, make sure to install pre-commit.
=== Python Code
Uses at least Python 3.11, as it was not tested with other versions (to do).
Requirementes:
* Python 3.11
* Poetry
To run it use:
* `make setup` - Setup
* `make tests` - Test
* `make format` - Code formatting
* `make all` - Format and test
=== Developing new hooks
New hooks can be developed following the template in docs/hook-template.vit.
Make sure you close the VI reference if you open it.
Create tests accordingly for each of the supported files types and eventually VI types.
Fork, modify the code and submit a merge request back.
=== External hooks
External hooks are not supported yet, although it is under investigation.
This means if you want to develop your own hook you need to submit a MR or create a hook in your own fork.
== Dependencies
- G-CLI
- Caraya Unit Test Framework
- Python 3.11 and Poetry
== Author
Felipe Pinheiro Silva - felipefoz@gmail.com
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pre_commit_hooks_g-1.0.2.tar.gz
(460.2 kB
view hashes)
Built Distribution
Close
Hashes for pre_commit_hooks_g-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 567fba399b2f81fbd7317b5224ba83601d82f0e70b954d18a0cf72b0b0ab4451 |
|
MD5 | 75d34c18ea15016422f02057c4b50149 |
|
BLAKE2b-256 | a6c65f07ab90d18241816f71d2db08d4b18bc60a3c186d1948be8e82ba7ce533 |