Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProMod3
Manage
Activity
Members
Plan
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
ProMod3
Commits
13c230ed
Commit
13c230ed
authored
10 years ago
by
Bienchen
Committed by
BIOPZ-Johner Niklaus
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
More pre-commit hook
parent
af3dcd9c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
extras/pre-commit
+21
-12
21 additions, 12 deletions
extras/pre-commit
with
21 additions
and
12 deletions
extras/pre-commit
+
21
−
12
View file @
13c230ed
...
...
@@ -123,6 +123,8 @@ def GetFileType(filepath):
return
"
python
"
elif
fo
==
"
%s: a ost script text executable
"
%
filepath
:
return
"
python
"
elif
fo
==
"
%s: a /usr/bin/env ost script text executable
"
%
filepath
:
return
"
python
"
elif
fo
==
"
%s: Bourne shell script text executable
"
%
filepath
:
return
"
shell-script
"
elif
fo
==
"
%s: POSIX shell script text executable
"
%
filepath
:
...
...
@@ -192,21 +194,23 @@ def GetModFiles():
+
"
recognised by the pre-commit hook which is not handled.
"
,
13
)
return
py_files
,
rst_files
,
cmake_files
,
shell_scripts
,
c_files
,
ukn_files
def
TestLineWidthExit
(
line
,
filename
):
def
TestLineWidthExit
(
line
,
line_no
,
filename
):
"""
Test the line width and fail.
"""
if
len
(
line
)
>
79
:
FailMsg
(
"
Line width in
'
%s
'
exceeds 79 characters. For better
"
%
filename
+
"
readability of code, this is prohibited.
"
,
15
)
FailMsg
(
"
Line width in
'
%s:%d
'
exceeds 79
"
%
(
filename
,
line_no
)
+
"
characters. For better readability of code, this is prohibited.
"
,
15
)
def
CheckPythonCode
(
filepath
):
fh
=
open
(
filepath
,
"
U
"
)
print_re
=
re
.
compile
(
'
print
'
)
import_re
=
re
.
compile
(
'
import\s+\*
'
)
lno
=
1
for
line
in
fh
:
line
=
line
.
strip
()
TestLineWidthExit
(
line
,
filepath
)
TestLineWidthExit
(
line
,
lno
,
filepath
)
m_line
=
re
.
match
(
'
([^#]*)
'
,
line
)
ex_line
=
m_line
.
group
(
1
)
if
len
(
ex_line
):
...
...
@@ -216,34 +220,39 @@ def CheckPythonCode(filepath):
if
import_re
.
match
(
ex_line
):
FailMsg
(
"'
%s
'
imports *. This clutters namespaces.
"
\
%
filepath
,
14
)
lno
+=
1
def
CheckRest
(
filepath
):
fh
=
open
(
filepath
,
"
U
"
)
lno
=
1
for
line
in
fh
:
line
=
line
.
strip
()
TestLineWidthExit
(
line
,
filepath
)
TestLineWidthExit
(
line
,
lno
,
filepath
)
lno
+=
1
def
CheckCmake
(
filepath
):
fh
=
open
(
filepath
,
"
U
"
)
lno
=
1
for
line
in
fh
:
line
=
line
.
strip
()
TestLineWidthExit
(
line
,
filepath
)
return
TestLineWidthExit
(
line
,
lno
,
filepath
)
lno
+=
1
def
CheckShellScript
(
filepath
):
fh
=
open
(
filepath
,
"
U
"
)
lno
=
1
for
line
in
fh
:
line
=
line
.
strip
()
TestLineWidthExit
(
line
,
filepath
)
return
TestLineWidthExit
(
line
,
lno
,
filepath
)
lno
+=
1
def
CheckCCode
(
filepath
):
fh
=
open
(
filepath
,
"
U
"
)
lno
=
1
for
line
in
fh
:
line
=
line
.
strip
()
TestLineWidthExit
(
line
,
filepath
)
return
TestLineWidthExit
(
line
,
lno
,
filepath
)
lno
+=
1
### FUNCTIONS - END
### MAIN - BEGIN
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment