Joey Armstrong | 34690ba | 2024-04-15 12:45:39 -0400 | [diff] [blame] | 1 | .. _Makefile Target lint-pre-commit: |
| 2 | |
| 3 | Tool: pre-commit |
| 4 | ================ |
| 5 | |
| 6 | The `pre-commit tool <https://pre-commit.com/>`__ can also be used to: |
| 7 | |
| 8 | - Scan for a variety of problems: syntax, licensing, etc. |
| 9 | - Perform some code cleanups |
| 10 | |
| 11 | - Remove whitespace |
| 12 | - re-indent files |
| 13 | - etc |
| 14 | |
Joey Armstrong | 08b7599 | 2024-04-29 11:50:00 -0400 | [diff] [blame] | 15 | Install |
| 16 | ------- |
Joey Armstrong | 34690ba | 2024-04-15 12:45:39 -0400 | [diff] [blame] | 17 | |
| 18 | .. code:: bash |
| 19 | |
| 20 | % git clone ssh://gerrit.opencord.org:29418/bbsim.git |
| 21 | % cd bbsim |
| 22 | |
| 23 | % make help |
| 24 | |
| 25 | # Install python virtualenv w/modules from requirements.txt |
| 26 | % make venv |
| 27 | % source .venv/bin/activate |
| 28 | |
| 29 | # Scan for problems |
| 30 | % pre-commit |
| 31 | |
| 32 | % make clean |
| 33 | |
Joey Armstrong | 08b7599 | 2024-04-29 11:50:00 -0400 | [diff] [blame] | 34 | repo:onf-make convenience target |
| 35 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 36 | |
| 37 | VOLTHA repositories that have |
| 38 | `repo:onf-make <https://gerrit.opencord.org/plugins/gitiles/onf-make/+/refs/heads/master>`_ |
| 39 | installed as a git submodule can use the makefile target `pre-commit` to |
| 40 | create a virtualenv and invoke pre-commit with a single command. |
| 41 | |
| 42 | .. code-block:: shell-session |
| 43 | :caption: Convenience Target |
| 44 | |
| 45 | % git clone bbsim |
| 46 | % cd bbsim |
| 47 | |
| 48 | % Is the repo:onf-make submodule available ? |
| 49 | % git config --file .gitmodules --name-only --get-regexp path |
| 50 | |
| 51 | # yes |
| 52 | submodule.lf/onf-make.path |
| 53 | |
| 54 | % make pre-commit |
| 55 | |
| 56 | Configuration |
| 57 | ------------- |
Joey Armstrong | 34690ba | 2024-04-15 12:45:39 -0400 | [diff] [blame] | 58 | |
| 59 | - Each repository contains a yaml config file that controls hooks and linting behavior: |
| 60 | |
| 61 | - repo:bbsim/`.pre-commit-config.yaml <https://gerrit.opencord.org/plugins/gitiles/bbsim/+/refs/heads/master/.pre-commit-config.yaml>`__ |
| 62 | |
| 63 | - A skeleton config is currently being used. |
Joey Armstrong | 08b7599 | 2024-04-29 11:50:00 -0400 | [diff] [blame] | 64 | |
| 65 | - Directory exclusions are supported (regex pattern at the end). |
| 66 | - Commit hooks can be enabled/disabled as needed per-repository. |
| 67 | - Open tickets to track repository cleanup needed. |
| 68 | |
| 69 | - Config changes can be made as needed but if new hooks are added or configs |
| 70 | change be sure to update the common config file in repo:onf-make and |
| 71 | propogate hook edits out to all VOLTHA repositories for consistency. |
Joey Armstrong | 34690ba | 2024-04-15 12:45:39 -0400 | [diff] [blame] | 72 | - Make changes as needed but be sure to propogate them out to all voltha repositories. |
| 73 | - Long term a central repository can be maintained for pre-commit hooks that can be |
| 74 | included as a git submodule to remove duplication and potential for linting variations. |
| 75 | |
Joey Armstrong | 08b7599 | 2024-04-29 11:50:00 -0400 | [diff] [blame] | 76 | Source & Dependencies |
| 77 | --------------------- |
| 78 | |
| 79 | | Source | Description | |
| 80 | | ------ | ----------- | |
| 81 | | `repo:onf-make <https://gerrit.opencord.org/plugins/gitiles/onf-make/+/refs/heads/master>`_ | Repository containing makefile targets and common pre-commit config. | |
| 82 | | `pre-commit <https://gerrit.opencord.org/plugins/gitiles/onf-make/+/refs/heads/master/makefiles/commands/pre-commit/>`_ | Makfile targets used to install the pre-commit tool. | |
| 83 | | `virtualenv <https://gerrit.opencord.org/plugins/gitiles/onf-make/+/refs/heads/master/makefiles/virtualenv/>`_ | These makefiles will install a python virtulenv into sandbox/.venv/. | |
| 84 | |
| 85 | .. todo: |
| 86 | |
| 87 | - Move .pre-copmmit-config.yaml setup into a standalone repository. |
| 88 | - Include the repo as a new git submodule. |
| 89 | - pre-commit config file can then be maintained as a file on disk |
| 90 | (per-repository checking for early cleanup) or be replaced with |
| 91 | a symlink that references the shared config file. Added benefit |
| 92 | -- the submodule also acts as a breadcrumb trail for locating |
| 93 | the config for pre-commit edits that span all repositories. |
| 94 | |
Joey Armstrong | 34690ba | 2024-04-15 12:45:39 -0400 | [diff] [blame] | 95 | .. seealso: |
| 96 | |
| 97 | | URL | Description | |
Joey Armstrong | 08b7599 | 2024-04-29 11:50:00 -0400 | [diff] [blame] | 98 | | `pre-commit <https://pre-commit.com/>` | A framework for managing and maintaining multi-language pre-commit hooks | |