File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4040 language : python
4141 files : .*\.(TcPOU|TcGVL|TcDUT)$
4242 additional_dependencies : ["pytmc"]
43+ - id : no-product-version
44+ name : Check for product version
45+ description : Checks if the product version is saved in the TwinCAT source file.
46+ entry : no-product-version
47+ language : python
48+ files : .*\.(TcPOU|TcDUT|TcGVL)$
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.2 .0
12+ rev : v1.4 .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
18+ - id : no-product-version
1819 # Optional, if you use pytmc to generate EPICS IOCs:
1920 # - id: pytmc-pragma-linter
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ import argparse
4+
5+ from lxml import etree
6+
7+
8+ class PreCommitException (Exception ):
9+ pass
10+
11+
12+ def check_file (filename ):
13+ with open (filename , 'rb' ) as fd :
14+ original_xml = fd .read ()
15+
16+ xml_parser = etree .XMLParser (remove_blank_text = True )
17+ parse_tree = etree .XML (original_xml , parser = xml_parser ).getroottree ()
18+
19+ tc_plc_object = list (parse_tree .iter ("TcPlcObject" ))[0 ].attrib
20+ # Check if it contains a product version attribute
21+ if 'ProductVersion' in tc_plc_object :
22+ raise PreCommitException (
23+ f"Detected product version ({ tc_plc_object ['ProductVersion' ]} ) in { filename } . "
24+ f"To disable this go to Project settings > Advanced and disable 'Write product version in files.'" )
25+
26+
27+ def main (args = None ):
28+ if args is None :
29+ parser = argparse .ArgumentParser ()
30+ parser .add_argument ('filenames' , nargs = '*' )
31+ args = parser .parse_args ()
32+ try :
33+ for filename in args .filenames :
34+ check_file (filename )
35+ return 0
36+ except Exception as exc :
37+ print (exc )
38+ return 1
39+
40+
41+ if __name__ == "__main__" :
42+ exit (main ())
Original file line number Diff line number Diff line change 88hook_names = ['twincat-lineids-remover' ,
99 'leading-tabs-remover' ,
1010 'xml-format' ,
11- 'check-fixed-library-versions' ]
11+ 'check-fixed-library-versions' ,
12+ 'no-product-version' ,
13+ ]
1214console_scripts = []
1315for name in hook_names :
1416 module = name .replace ('-' , '_' )
You can’t perform that action at this time.
0 commit comments