Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
797813bd
Commit
797813bd
authored
8 years ago
by
Henning Glawe
Browse files
Options
Downloads
Patches
Plain Diff
move handling of coverageIgnore to annotator
parent
db3a73e8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/python/nomadcore/annotator.py
+12
-10
12 additions, 10 deletions
common/python/nomadcore/annotator.py
common/python/nomadcore/match_highlighter.py
+11
-14
11 additions, 14 deletions
common/python/nomadcore/match_highlighter.py
with
23 additions
and
24 deletions
common/python/nomadcore/annotator.py
+
12
−
10
View file @
797813bd
import
logging
from
nomadcore.match_highlighter
import
MatchHighlighter
from
nomadcore.match_highlighter
import
MatchHighlighter
,
ANSI
LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -19,21 +19,23 @@ class Annotator(object):
def
annotate
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
if
not
self
.
annotateFile
:
return
1
(
match
type
,
highlightedLine
)
=
self
.
matchHighlighter
.
highlight
(
match
,
line
,
self
.
coverageIgnore
)
(
match
ed
,
full
,
highlightedLine
)
=
self
.
matchHighlighter
.
highlight
(
match
,
line
)
matchlabel
=
''
if
matchtype
==
0
:
matchlabel
=
'
ign
'
elif
matchtype
==
1
:
matchlabel
=
'
no
'
else
:
if
matched
:
# we matched
if
matchtype
==
2
:
if
not
full
:
matchlabel
=
'
p_
'
if
targetStartEnd
==
0
:
if
targetStartEnd
==
0
:
matchlabel
+=
'
start
'
else
:
matchlabel
+=
'
end
'
else
:
if
self
.
coverageIgnore
.
match
(
line
):
matchlabel
=
'
ign
'
highlightedLine
=
ANSI
.
FG_BLUE
+
highlightedLine
else
:
matchlabel
=
'
no
'
if
matcher
.
name
:
name
=
matcher
.
name
[
-
15
:]
...
...
This diff is collapsed.
Click to expand it.
common/python/nomadcore/match_highlighter.py
+
11
−
14
View file @
797813bd
...
...
@@ -16,12 +16,15 @@ RE_finalnewlines=re.compile(r"^(.*?)(\n*)$")
class
MatchHighlighter
(
object
):
"""
ANSI-Color highlighting for capturing groups in regex matches
"""
def
highlight
(
self
,
match
,
lineOrig
,
coverageIgnore
,
multiline
=
False
):
"""
:returns: (int, str_including_ANSI_escapes)
0 - RE did not match, and line was part of coverage-ignored
1 - RE did not match, and line was not part of coverage-ignored
2 - RE matched partially
3 - RE matched fully
"""
def
highlight
(
self
,
match
,
lineOrig
,
multiline
=
False
):
"""
:returns: (matched, fullmatch, highlighed)
:rtype: (bool, bool, str)
matched: true if matched at all
fullmatch: all characters of lineOrig were covered by match
hightlighted: string containing ANSI escapes (at least ANSI RESET at
end of string)
"""
if
multiline
:
line
=
lineOrig
trailing
=
''
...
...
@@ -33,10 +36,7 @@ class MatchHighlighter(object):
trailing
=
m
.
group
(
2
)
# shortcut: there is nothing to highlight
if
not
match
:
if
coverageIgnore
and
coverageIgnore
.
match
(
lineOrig
):
return
(
0
,
ANSI
.
FG_BLUE
+
line
+
ANSI
.
RESET
+
trailing
)
else
:
return
(
1
,
lineOrig
)
return
(
False
,
False
,
line
+
ANSI
.
RESET
+
trailing
)
else
:
match_full
=
match
.
start
()
==
0
and
match
.
end
()
==
len
(
lineOrig
)
...
...
@@ -81,7 +81,4 @@ class MatchHighlighter(object):
highlightedLine
+=
ansiSwitch
[
i
][
2
]
# re-append trailing newlines if we stripped them
highlightedLine
+=
trailing
if
match_full
:
return
(
3
,
highlightedLine
)
else
:
return
(
2
,
highlightedLine
)
return
(
True
,
match_full
,
highlightedLine
)
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