texlive[41378] Master/texmf-dist/doc/support/hook-pre-commit-pkg:
commits+karl at tug.org
commits+karl at tug.org
Sun Jun 12 01:15:54 CEST 2016
Revision: 41378
http://tug.org/svn/texlive?view=revision&revision=41378
Author: karl
Date: 2016-06-12 01:15:54 +0200 (Sun, 12 Jun 2016)
Log Message:
-----------
hook-pre-commit-pkg (5jun16)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README
trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex
Modified: trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README
===================================================================
--- trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README 2016-06-11 23:15:38 UTC (rev 41377)
+++ trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/README 2016-06-11 23:15:54 UTC (rev 41378)
@@ -1,11 +1,11 @@
-Pre-commit hook for LaTeX package developpers
+Pre-commit hook for LaTeX package developers
=== What it is ?
-A pre-commit hook to check basic LaTeX syntaxe for develloper of package.
+A pre-commit hook to check basic LaTeX syntax for developer of package.
==== How to install
-Copy pre-commit in the .git/.hooks file
+Copy pre-commit in the .git/hooks file
Add execution right (chmod +x)
Enjoy !
@@ -29,7 +29,7 @@
=== Licence and copyright
Maïeul Rouquette 2014-....
-v 1.1.0
+v 1.1.2
Licence GPl3 https://www.gnu.org/licenses/gpl-3.0.txt
=== Help and github repository
Modified: trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex
===================================================================
--- trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex 2016-06-11 23:15:38 UTC (rev 41377)
+++ trunk/Master/texmf-dist/doc/support/hook-pre-commit-pkg/pre-commit-latex 2016-06-11 23:15:54 UTC (rev 41378)
@@ -1,13 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""Pre-commit hook for LaTeX package developpers
+"""Pre-commit hook for LaTeX package developers
=== What it is ?
-A pre-commit hook to check basic LaTeX syntaxe for develloper of package.
+A pre-commit hook to check basic LaTeX syntax for developer of package.
==== How to install
-Copy pre-commit in the .git/.hooks file
+Copy pre-commit in the .git/hooks file
Add execution right (chmod +x)
Enjoy !
@@ -31,7 +31,7 @@
=== Licence and copyright
Maïeul Rouquette 2014-....
-v 1.1.0
+v 1.1.2
Licence GPl3 https://www.gnu.org/licenses/gpl-3.0.txt
=== Help and github repository
@@ -69,15 +69,14 @@
line_number = int(line_number[0]) -1
elif not line[0] == "-" and not line[0:1] == "\\":
line_number = line_number + 1
- return line_number
+ return line_number
-lines_results ={}#global, bad, I have to find an other way. Key = filename_linenumber. content : see check_lines
+lines_results ={}#global, bad, I have to find an other way. Key = filename_linenumber. content : see check_lines
def check_lines():
""" Check all modified lines"""
diff = os.popen("git diff --cached")
line_number = 0
file_name = ""
-
for line in diff:
line_number = change_line_number(line_number,line)
# what is the file_name?
@@ -84,13 +83,13 @@
if "+++ b/" in line:
file_name = line[6:-1]
extension = os.path.splitext(file_name)[1][1:]
+ lines_results[file_name] ={}
elif "++ /dev/null" in line:
extension = ""
file_name = ""
elif line[0] == "+" and extension in to_be_checked:
check = check_line(line,line_number,file_name)
- lines_results[file_name+"_"+str(line_number)]={
- "line_number":line_number,
+ lines_results[file_name][line_number]={
"content":line,
"results":check,
"file_name":file_name
@@ -124,12 +123,12 @@
# only for line concerning macro env
errors = []
if begin in line:
-
+
# Check only one space after %
normal_indent = "% \\begin{macro}"
if line[:len(normal_indent)] != normal_indent:
errors.append("indent")
-
+
#Check there is second argument
if line.count("{") != 2 or line.count("}") != 2:
errors.append("#2")
@@ -136,25 +135,26 @@
# we think its not paired before anyone paired
errors.append("pairing")
+
if file_name in begin_macro:
- begin_macro[file_name].append(str(line_number))
+ begin_macro[file_name].append(line_number)
else:
- begin_macro[file_name]=[str(line_number)]
+ begin_macro[file_name]=[line_number]
return errors
elif end in line:
-
- #check only
+
+ #check only
normal_indent = "% \end{macro}"
if line[:len(normal_indent)] != normal_indent:
errors.append("indent")
-
+
#correct pairing
try:
begin_pairing = begin_macro[file_name].pop()#get the line of the \begin{macro}
- lines_results[file_name+"_"+begin_pairing]["results"]["macro_env"].remove("pairing")
- if lines_results[file_name+"_"+begin_pairing]["results"]["macro_env"] ==[]:
- del(lines_results[file_name+"_"+begin_pairing]["results"]["macro_env"])
+ lines_results[file_name][begin_pairing]["results"]["macro_env"].remove("pairing")
+ if lines_results[file_name][begin_pairing]["results"]["macro_env"] ==[]:
+ del(lines_results[file_name][begin_pairing]["results"]["macro_env"])
except:
errors.append("pairing")
return errors
@@ -174,7 +174,7 @@
# only for line concerning macrocode env
errors = []
if begin in line:
-
+
# Check only one space after %
normal_indent = "% \\begin{macrocode}"
if line[:len(normal_indent)] != normal_indent:
@@ -183,24 +183,24 @@
# we think its not paired before anyone paired
errors.append("pairing")
if file_name in begin_macrocode:
- begin_macrocode[file_name].append(str(line_number))
+ begin_macrocode[file_name].append(line_number)
else:
- begin_macrocode[file_name]=[str(line_number)]
+ begin_macrocode[file_name]=[line_number]
return errors
elif end in line:
-
- #check only
+
+ #check only
normal_indent = "% \end{macrocode}"
if line[:len(normal_indent)] != normal_indent:
errors.append("indent")
-
+
#correct pairing
try:
begin_pairing = begin_macrocode[file_name].pop()#get the line of the \begin{macrocode}
- lines_results[file_name+"_"+begin_pairing]["results"]["macrocode_env"].remove("pairing")
- if lines_results[file_name+"_"+begin_pairing]["results"]["macrocode_env"] ==[]:
- del(lines_results[file_name+"_"+begin_pairing]["results"]["macrocode_env"])
+ lines_results[file_name][begin_pairing]["results"]["macrocode_env"].remove("pairing")
+ if lines_results[file_name][begin_pairing]["results"]["macrocode_env"] ==[]:
+ del(lines_results[file_name][begin_pairing]["results"]["macrocode_env"])
except:
errors.append("pairing")
return errors
@@ -215,15 +215,15 @@
def check_end_line_percent_signe(line,line_number,file_name):
""""Check line finish by %"""
- line = line.replace("\%","") # Don't look for protected %
-
+ line = line.replace("\%","") # Don't look for protected %
+
if line == "+\n": # Allow empty line
return True
-
+
elif "%" not in line: # If not % -> problem
return False
- elif re.search ("\s+%",line): # Spaces before % -> problem
+ elif re.search ("\s+%",line): # Spaces before % -> problem
return False
else:
return True
@@ -232,25 +232,23 @@
def __main__():
"""Main function: calls the check to bad line, print them if need, and return exit if error"""
lines_results = check_lines()
- exit = 0 #Set to 1 if we have ONE bad line.
- seen_file_names=[]
- for line_result in lines_results:
- line= lines_results[line_result]
- if line["results"]!={}: #there is some error
- exit=1
- if line["file_name"] not in seen_file_names:
- seen_file_names.append(line["file_name"])
- print (line["file_name"])
- print ("\x1b[31m\tl."+ str(line["line_number"]) + ": " + line["content"][:-1])
-
- results = line["results"]
- for error in line["results"]:
- if results[error] == True:
- print ("\t\t " + commands[error])
- else:
- for e in results[error]:
- print ("\t\t " + commands[error][e])
- print("\x1b[0m")
+ exit = 0 #Set to 1 if we have ONE bad line.
+ for file_name in lines_results:
+ print (file_name)
+ for line_number in sorted(lines_results[file_name].keys()):
+ line = lines_results[file_name][line_number]
+ if line["results"]!={}: #there is some error
+ exit=1
+ print ("\x1b[31m\tl."+ str(line_number) + ": " + line["content"][:-1])
+
+ results = line["results"]
+ for error in line["results"]:
+ if results[error] == True:
+ print ("\t\t " + commands[error])
+ else:
+ for e in results[error]:
+ print ("\t\t " + commands[error][e])
+ print("\x1b[0m")
sys.exit(exit)
More information about the tex-live-commits
mailing list