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
83b8573a
Commit
83b8573a
authored
9 years ago
by
Henning Glawe
Browse files
Options
Downloads
Patches
Plain Diff
move gathering of match telementry to match_info
parent
a435ed5b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/annotator.py
+71
-41
71 additions, 41 deletions
common/python/nomadcore/annotator.py
with
71 additions
and
41 deletions
common/python/nomadcore/annotator.py
+
71
−
41
View file @
83b8573a
...
@@ -41,31 +41,64 @@ class Annotator(object):
...
@@ -41,31 +41,64 @@ class Annotator(object):
self
.
_formatNameWidth
=
formatNameWidth
self
.
_formatNameWidth
=
formatNameWidth
self
.
_update_annotate_format
()
self
.
_update_annotate_format
()
def
annotate
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
def
match_info
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
# classify match
result
=
{
full
=
match
and
match
.
start
()
==
0
and
match
.
end
()
==
len
(
line
)
# raw line
local_ignore
=
False
'
line
'
:
line
,
global_ignore
=
False
# information about SimpleMatcher
matcher_does_nothing
=
False
'
name
'
:
matcher
.
name
if
matcher
.
name
else
'
UNNAMED
'
,
'
defFile
'
:
matcher
.
defFile
,
'
defLine
'
:
matcher
.
defLine
,
'
matcher_does_nothing
'
:
matcher
.
does_nothing
,
# matcher without effect
'
which_re
'
:
'
end
'
if
targetStartEnd
else
'
start
'
,
# classification of match
'
match
'
:
0
,
# 0 - no, 1 - partial, 2 - full
'
coverageIgnore
'
:
0
,
# 0 - no, 1 - local, 2 - global
# overall span of match
'
span
'
:
[],
# capture groups
'
group
'
:
[],
}
if
match
:
if
match
:
if
matcher
.
coverageIgnore
:
result
[
'
span
'
]
=
[
match
.
start
(),
match
.
end
()]
local_ignore
=
True
if
match
.
start
()
==
0
and
match
.
end
()
==
len
(
line
):
elif
matcher
.
does_nothing
:
result
[
'
match
'
]
=
2
# full match
matcher_does_nothing
=
True
else
:
result
[
'
match
'
]
=
1
# partial match
if
matcher
.
coverageIgnore
:
# matcher is local coverageIgnore
result
[
'
coverageIgnore
'
]
=
1
# capture groups
# todo: move this to SimpleMatcher/CompiledMatcher
groupname
=
[
'
all
'
]
+
[
str
(
num
+
1
)
for
num
in
range
(
match
.
re
.
groups
)]
for
name
,
num
in
match
.
re
.
groupindex
.
items
():
groupname
[
num
]
=
name
# extract capture group info
for
groupi
in
range
(
1
,
match
.
re
.
groups
+
1
):
# Forward compatibility with 'regex' or 're2', which support
# multiple captures per named group:
# span: list of start/end indices
# capture: list of matched strings
result
[
'
group
'
].
append
({
'
name
'
:
groupname
[
groupi
],
'
span
'
:
[],
'
capture
'
:
[]})
if
match
.
group
(
groupi
)
is
not
None
:
result
[
'
group
'
][
-
1
][
'
capture
'
].
append
(
match
.
group
(
groupi
))
result
[
'
group
'
][
-
1
][
'
span
'
].
append
(
match
.
span
(
groupi
))
else
:
else
:
m2
=
self
.
coverageIgnore
.
match
(
line
)
m_ci
=
self
.
coverageIgnore
.
match
(
line
)
if
m2
:
if
m_ci
:
global_ignore
=
True
result
[
'
coverageIgnore
'
]
=
2
# global coverageIgnore matched
match
=
m2
result
[
'
span
'
]
=
[
m_ci
.
start
(),
m_ci
.
end
()]
return
result
def
annotate
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
minfo
=
self
.
match_info
(
match
,
line
,
matcher
,
targetStartEnd
)
# update counters
# update counters
self
.
counter
[
'
total
'
]
+=
1
self
.
counter
[
'
total
'
]
+=
1
if
local_ignore
or
global_i
gnore
:
if
minfo
[
'
coverageI
gnore
'
]
:
self
.
counter
[
'
ignore
'
]
+=
1
self
.
counter
[
'
ignore
'
]
+=
1
elif
match
:
elif
minfo
[
'
match
'
]
>
1
:
if
full
:
self
.
counter
[
'
match
'
]
+=
1
self
.
counter
[
'
match
'
]
+=
1
else
:
elif
minfo
[
'
match
'
]
:
self
.
counter
[
'
partial
'
]
+=
1
self
.
counter
[
'
partial
'
]
+=
1
else
:
else
:
self
.
counter
[
'
unmatched
'
]
+=
1
self
.
counter
[
'
unmatched
'
]
+=
1
...
@@ -76,36 +109,33 @@ class Annotator(object):
...
@@ -76,36 +109,33 @@ class Annotator(object):
# setup match label
# setup match label
matchlabel
=
''
matchlabel
=
''
if
local_ignore
:
if
minfo
[
'
coverageIgnore
'
]
==
1
:
matchlabel
=
'
l_ign
'
matchlabel
=
'
l_ign
'
elif
global_i
gnore
:
elif
minfo
[
'
coverageI
gnore
'
]
:
matchlabel
=
'
g_ign
'
matchlabel
=
'
g_ign
'
elif
match
:
elif
minfo
[
'
match
'
]
:
if
matcher_does_nothing
:
if
minfo
[
'
matcher_does_nothing
'
]
:
matchlabel
=
'
n_
'
matchlabel
=
'
n_
'
if
not
full
:
if
minfo
[
'
match
'
]
<
2
:
matchlabel
+=
'
p_
'
matchlabel
+=
'
p_
'
matchlabel
+=
'
end
'
if
targetStartEnd
else
'
start
'
matchlabel
+=
minfo
[
'
which_re
'
]
else
:
else
:
matchlabel
=
'
no
'
matchlabel
=
'
no
'
# highlight line
# highlight line
if
local_ignore
or
global_i
gnore
:
if
minfo
[
'
coverageI
gnore
'
]
:
highlighted
=
self
.
matchHighlighter
.
highlight
(
highlighted
=
self
.
matchHighlighter
.
highlight
_minfo
(
m
atch
,
line
,
linecolor
=
ANSI
.
FG_BLUE
)
m
info
,
linecolor
=
ANSI
.
FG_BLUE
)
elif
matcher_does_nothing
:
elif
minfo
[
'
matcher_does_nothing
'
]
:
highlighted
=
self
.
matchHighlighter
.
highlight
(
highlighted
=
self
.
matchHighlighter
.
highlight
_minfo
(
m
atch
,
line
,
linecolor
=
ANSI
.
FG_MAGENTA
)
m
info
,
linecolor
=
ANSI
.
FG_MAGENTA
)
elif
match
:
elif
minfo
[
'
match
'
]
:
highlighted
=
self
.
matchHighlighter
.
highlight
(
match
,
line
)
highlighted
=
self
.
matchHighlighter
.
highlight
_minfo
(
minfo
)
else
:
else
:
highlighted
=
line
highlighted
=
line
# set matcher name
# shorted matcher- and source file names
if
matcher
.
name
:
name
=
minfo
[
'
name
'
][
-
self
.
_formatNameWidth
:]
name
=
matcher
.
name
[
-
self
.
_formatNameWidth
:]
defFile
=
minfo
[
'
defFile
'
][
-
self
.
_formatSourceWidth
:]
else
:
name
=
'
UNNAMED
'
defFile
=
matcher
.
defFile
[
-
self
.
_formatSourceWidth
:]
self
.
annotateFile
.
write
(
self
.
_annotate_format
%
(
self
.
annotateFile
.
write
(
self
.
_annotate_format
%
(
defFile
,
m
atcher
.
defLine
,
name
,
defFile
,
m
info
[
'
defLine
'
]
,
name
,
matchlabel
,
highlighted
,
matchlabel
,
highlighted
,
))
))
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