blob: 29d49156b4e96f2c4f1bb7c839c5487545a0fe01 [file] [log] [blame]
Joey Armstrong34690ba2024-04-15 12:45:39 -04001.. _Makefile Target lint-pre-commit:
2
3Tool: pre-commit
4================
5
6The `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 Armstrong08b75992024-04-29 11:50:00 -040015Install
16-------
Joey Armstrong34690ba2024-04-15 12:45:39 -040017
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 Armstrong08b75992024-04-29 11:50:00 -040034repo:onf-make convenience target
35^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36
37VOLTHA repositories that have
38`repo:onf-make <https://gerrit.opencord.org/plugins/gitiles/onf-make/+/refs/heads/master>`_
39installed as a git submodule can use the makefile target `pre-commit` to
40create 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
56Configuration
57-------------
Joey Armstrong34690ba2024-04-15 12:45:39 -040058
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 Armstrong08b75992024-04-29 11:50:00 -040064
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 Armstrong34690ba2024-04-15 12:45:39 -040072- 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 Armstrong08b75992024-04-29 11:50:00 -040076Source & 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 Armstrong34690ba2024-04-15 12:45:39 -040095.. seealso:
96
97| URL | Description |
Joey Armstrong08b75992024-04-29 11:50:00 -040098| `pre-commit <https://pre-commit.com/>` | A framework for managing and maintaining multi-language pre-commit hooks |