pcdshub / pre-commit-hooks

Pre-commit hooks for PCDS projects (https://pre-commit.com/)
Other
10 stars 7 forks source link

ENH: add pytmc pragmalint pre-commit hook #21

Closed klauer closed 1 year ago

klauer commented 1 year ago

Closes #20

Sample output - while not pretty, it appears functional and useful:

pytmc-pragma-linter......................................................Failed
- hook id: pytmc-pragma-linter
- exit code: 1

+ for fn in "$@"
+ pytmc pragmalint LCLSGeneral/LCLSGeneral/POUs/Hardware/FB_LED.TcPOU
ERROR:pytmc.bin.pragmalint:Linter error: Unhandled exception: Found invalid pragma line(s):
    |         pv: NAME
    |         io: iofoob
    |       field: DESC Descriptive name for the LED
--> |       pragamama : lint
    |         autosave_pass0: VAL DESC
--> |
LCLSGeneral/LCLSGeneral/POUs/Hardware/FB_LED.TcPOU:line 21:     {attribute 'pytmc' := '
            pv: NAME
            io: iofoob
          field: DESC Descriptive name for the LED
          pragamama : lint
            autosave_pass0: VAL DESC
        '}
ERROR:pytmc.bin.pragmalint:Unhandled exception (may be a pytmc bug)
Traceback (most recent call last):
  File "/Users/klauer/.cache/pre-commit/repoznchl_6k/py_env-python3.11/lib/python3.11/site-packages/pytmc/bin/pragmalint.py", line 253, in lint_source
    lint_pragma(pragma)
  File "/Users/klauer/.cache/pre-commit/repoznchl_6k/py_env-python3.11/lib/python3.11/site-packages/pytmc/bin/pragmalint.py", line 131, in lint_pragma
    pragmas.split_pytmc_pragma(pragma_setting)
  File "/Users/klauer/.cache/pre-commit/repoznchl_6k/py_env-python3.11/lib/python3.11/site-packages/pytmc/pragmas.py", line 95, in split_pytmc_pragma
    raise ValueError(f"Found invalid pragma line(s):\n{invalid_lines}")
ValueError: Found invalid pragma line(s):
    |         pv: NAME
    |         io: iofoob
    |       field: DESC Descriptive name for the LED
--> |       pragamama : lint
    |         autosave_pass0: VAL DESC
--> |
INFO:pytmc.bin.pragmalint:Total pragmas found: 3 Total linter errors: 1

On a separate note, it looks like pytmc's linter output needs some work...

klauer commented 1 year ago

We need to update the pre-commit config on various repos to pick this up, right?

Yes, they will need the additional uncommented id: line from here: https://github.com/pcdshub/pre-commit-hooks/blob/53c5e35a83965d08e4088444bdfdafbc90a17f81/forTwinCatRepos/.pre-commit-config.yaml#L19