File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4646 entry : no-product-version
4747 language : python
4848 files : .*\.(TcPOU|TcDUT|TcGVL)$
49+ - id : twincat-st-newline
50+ name : TwinCAT ST Newline Formatter
51+ description : Affixes newlines to ST segments
52+ entry : twincat-st-newline
53+ language : python
54+ files : .*\.(TcPOU|TcGVL|TcDUT)$
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ Pre-commit hooks for PCDS projects (https://pre-commit.com/)
1212
1313If ` .pre-config-config.yaml ` does not already exist in the repository, copy
1414the appropriate file from this repository to the top-level of your local
15- repository, or add the folowing to an existing ` .pre-config-config.yaml `
15+ repository, or add the folowing to an existing ` .pre-config-config.yaml `
1616file and commit the addition.
1717
1818``` yaml
@@ -25,13 +25,14 @@ repos:
2525 files : \.(TcPOU|TcDUT|TcGVL)$
2626
2727- repo : https://github.com/pcdshub/pre-commit-hooks.git
28- rev : v1.4 .0
28+ rev : v1.5 .0
2929 hooks :
3030 - id : twincat-leading-tabs-remover
3131 - id : twincat-lineids-remover
3232 - id : twincat-xml-format
3333 - id : check-fixed-library-versions
3434 - id : no-product-version
35+ - id : twincat-st-newline
3536 # Optional, if you use pytmc to generate EPICS IOCs:
3637 # - id: pytmc-pragma-linter
3738```
Original file line number Diff line number Diff line change 99 files : \.(TcPOU|TcDUT|TcGVL)$
1010
1111- repo : https://github.com/pcdshub/pre-commit-hooks.git
12- rev : v1.4 .0
12+ rev : v1.5 .0
1313 hooks :
1414 - id : twincat-leading-tabs-remover
1515 - id : twincat-lineids-remover
1616 - id : twincat-xml-format
1717 - id : check-fixed-library-versions
1818 - id : no-product-version
19+ - id : twincat-st-newline
1920 # Optional, if you use pytmc to generate EPICS IOCs:
2021 # - id: pytmc-pragma-linter
Original file line number Diff line number Diff line change 1+ import argparse
2+ from lxml import etree
3+
4+ def structured_text_formatter (path : str , lines : int = 1 ) -> None :
5+ root = etree .parse (path ).getroot ()
6+ sect = root .xpath ('.//Declaration|.//Implementation/ST' )
7+ if len (sect ) == 0 :
8+ return
9+
10+ newlines = '\n ' * lines
11+ for section in sect :
12+ try :
13+ section .text = etree .CDATA (newlines + section .text .strip ('\n ' ) + newlines )
14+ except AttributeError :
15+ pass
16+ etree .ElementTree (root ).write (path , encoding = 'utf-8' , xml_declaration = True )
17+
18+ def main ():
19+ parser = argparse .ArgumentParser ()
20+ parser .add_argument ('--lines' , type = int , default = 1 )
21+ parser .add_argument ('files' , nargs = '*' )
22+ args = parser .parse_args ()
23+
24+ try :
25+ for file in args .files :
26+ structured_text_formatter (file , args .lines )
27+ except :
28+ return 1
29+
30+
31+ if __name__ == "__main__" :
32+ exit (main ())
Original file line number Diff line number Diff line change 1010 'xml-format' ,
1111 'check-fixed-library-versions' ,
1212 'no-product-version' ,
13+ 'twincat-st-newline' ,
1314 ]
1415console_scripts = []
1516for name in hook_names :
You can’t perform that action at this time.
0 commit comments