Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
e0d69db0
Commit
e0d69db0
authored
9 years ago
by
Danilo Piparo
Browse files
Options
Downloads
Patches
Plain Diff
Detect drawn canvases in the list of canvases, move comment stripper
parent
469ece46
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/pyroot/ROOTaaS/iPyROOT/cpptransformer.py
+1
-20
1 addition, 20 deletions
bindings/pyroot/ROOTaaS/iPyROOT/cpptransformer.py
bindings/pyroot/ROOTaaS/iPyROOT/utils.py
+42
-2
42 additions, 2 deletions
bindings/pyroot/ROOTaaS/iPyROOT/utils.py
with
43 additions
and
22 deletions
bindings/pyroot/ROOTaaS/iPyROOT/cpptransformer.py
+
1
−
20
View file @
e0d69db0
import
re
from
IPython.core.inputtransformer
import
InputTransformer
from
IPython
import
get_ipython
...
...
@@ -9,22 +7,7 @@ import cppcompleter
from
IPython.core
import
display
def
commentRemover
(
text
):
def
blotOutNonNewlines
(
strIn
)
:
# Return a string containing only the newline chars contained in strIn
return
""
+
(
"
\n
"
*
strIn
.
count
(
'
\n
'
))
def
replacer
(
match
)
:
s
=
match
.
group
(
0
)
if
s
.
startswith
(
'
/
'
):
# Matched string is //...EOL or /*...*/ ==> Blot out all non-newline chars
return
blotOutNonNewlines
(
s
)
else
:
# Matched string is '...' or "..." ==> Keep unchanged
return
s
pattern
=
re
.
compile
(
\
r
'
//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|
"
(?:\\.|[^\\
"
])*
"'
,
re
.
DOTALL
|
re
.
MULTILINE
)
return
re
.
sub
(
pattern
,
replacer
,
text
)
class
CppTransformer
(
InputTransformer
):
...
...
@@ -52,9 +35,7 @@ class CppTransformer(InputTransformer):
utils
.
declareCppCode
(
self
.
cell
)
self
.
mustDeclare
=
False
else
:
cell
=
self
.
cell
code
=
commentRemover
(
self
.
cell
)
utils
.
processCppCode
(
code
)
utils
.
processCppCode
(
self
.
cell
)
self
.
cell
=
""
if
self
.
mustSwitchToPython
:
ip
=
get_ipython
()
...
...
This diff is collapsed.
Click to expand it.
bindings/pyroot/ROOTaaS/iPyROOT/utils.py
+
42
−
2
View file @
e0d69db0
...
...
@@ -5,6 +5,7 @@ import time
import
tempfile
import
itertools
import
ctypes
import
re
from
contextlib
import
contextmanager
from
IPython
import
get_ipython
from
IPython.display
import
HTML
...
...
@@ -101,6 +102,23 @@ def _setIgnoreLevel(level):
yield
ROOT
.
gErrorIgnoreLevel
=
originalLevel
def
commentRemover
(
text
):
def
blotOutNonNewlines
(
strIn
)
:
# Return a string containing only the newline chars contained in strIn
return
""
+
(
"
\n
"
*
strIn
.
count
(
'
\n
'
))
def
replacer
(
match
)
:
s
=
match
.
group
(
0
)
if
s
.
startswith
(
'
/
'
):
# Matched string is //...EOL or /*...*/ ==> Blot out all non-newline chars
return
blotOutNonNewlines
(
s
)
else
:
# Matched string is '...' or "..." ==> Keep unchanged
return
s
pattern
=
re
.
compile
(
\
r
'
//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|
"
(?:\\.|[^\\
"
])*
"'
,
re
.
DOTALL
|
re
.
MULTILINE
)
return
re
.
sub
(
pattern
,
replacer
,
text
)
class
StreamCapture
(
object
):
def
__init__
(
self
,
stream
,
ip
=
get_ipython
()):
streamsFileNo
=
{
sys
.
stderr
:
2
,
sys
.
stdout
:
1
}
...
...
@@ -271,10 +289,30 @@ class CanvasCapture(object):
self
.
shell
.
events
.
unregister
(
'
pre_execute
'
,
self
.
_pre_execute
)
self
.
shell
.
events
.
unregister
(
'
post_execute
'
,
self
.
_post_execute
)
class
CaptureDrawnCanvases
(
object
):
'''
Capture the canvas which is drawn to display it.
'''
def
__init__
(
self
,
ip
=
get_ipython
()):
self
.
shell
=
ip
def
_pre_execute
(
self
):
pass
def
_post_execute
(
self
):
for
can
in
ROOT
.
gROOT
.
GetListOfCanvases
():
if
can
.
IsDrawn
():
can
.
Draw
()
can
.
ResetDrawn
()
def
register
(
self
):
self
.
shell
.
events
.
register
(
'
pre_execute
'
,
self
.
_pre_execute
)
self
.
shell
.
events
.
register
(
'
post_execute
'
,
self
.
_post_execute
)
captures
=
[
StreamCapture
(
sys
.
stderr
),
StreamCapture
(
sys
.
stdout
)
]
#Canvas
Capture()]
StreamCapture
(
sys
.
stdout
)
,
Capture
DrawnCanvases
()]
def
toCpp
():
'''
...
...
@@ -392,9 +430,11 @@ def setStyle():
# Here functions are defined to process C++ code
def
processCppCodeImpl
(
cell
):
cell
=
commentRemover
(
cell
)
ROOT
.
gInterpreter
.
ProcessLine
(
cell
)
def
declareCppCodeImpl
(
cell
):
cell
=
commentRemover
(
cell
)
ROOT
.
gInterpreter
.
Declare
(
cell
)
def
processCppCode
(
cell
):
...
...
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