Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Iliya Manolov
erp5
Commits
3196b18e
Commit
3196b18e
authored
Mar 01, 2017
by
Iliya Manolov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a bug where in Jupyter modules with periods(such as scipy.io) couldn't be imported...
parent
acf692cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
3 deletions
+41
-3
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
...teItem/portal_components/extension.erp5.JupyterCompile.py
+23
-3
bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
...ateItem/portal_components/test.erp5.testExecuteJupyter.py
+18
-0
No files found.
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
View file @
3196b18e
...
...
@@ -867,7 +867,13 @@ class ImportFixer(ast.NodeTransformer):
Return a AST.Function object representing a function with name `func_name`
and an empty body.
"""
func_body
=
"def %s(): pass"
%
func_name
dotless_func_name
=
''
for
symbol
in
func_name
:
if
symbol
is
'.'
:
dotless_func_name
=
dotless_func_name
+
'dot'
else
:
dotless_func_name
=
dotless_func_name
+
symbol
func_body
=
"def %s(): pass"
%
dotless_func_name
return
ast
.
parse
(
func_body
).
body
[
0
]
def
newReturnDict
(
self
,
module_names
):
...
...
@@ -887,7 +893,14 @@ class ImportFixer(ast.NodeTransformer):
Return an AST.Expr representaion an `environment.define` call receiving
`func_name` (as an expression) and `'func_name'` (as string).
"""
code_string
=
"environment.define(%s, '%s')"
%
(
func_name
,
func_name
)
dotless_func_name
=
''
for
symbol
in
func_name
:
if
symbol
is
'.'
:
dotless_func_name
=
dotless_func_name
+
'dot'
else
:
dotless_func_name
=
dotless_func_name
+
symbol
code_string
=
"environment.define(%s, '%s')"
%
(
dotless_func_name
,
func_name
)
tree
=
ast
.
parse
(
code_string
)
return
tree
.
body
[
0
]
...
...
@@ -897,12 +910,19 @@ class ImportFixer(ast.NodeTransformer):
user about the import of a module named `module_name` and instructs him
on how to fix it.
"""
dotless_func_name
=
''
for
symbol
in
function_name
:
if
symbol
is
'.'
:
dotless_func_name
=
dotless_func_name
+
'dot'
else
:
dotless_func_name
=
dotless_func_name
+
symbol
warning
=
(
"print '"
"WARNING: Your imported from the module %s without "
"using the environment object, which is not recomended. "
"Your import was automatically converted to use such method."
"The setup function was named as: %s_setup.
\
\
n"
"'"
)
%
(
module_name
,
function
_name
)
"'"
)
%
(
module_name
,
dotless_func
_name
)
tree
=
ast
.
parse
(
warning
)
return
tree
.
body
[
0
]
...
...
bt5/erp5_data_notebook/TestTemplateItem/portal_components/test.erp5.testExecuteJupyter.py
View file @
3196b18e
...
...
@@ -857,3 +857,21 @@ print dig
self
.
assertEquals
(
result
[
'status'
],
'ok'
)
self
.
assertEquals
(
result
[
'code_result'
].
strip
(),
'0123456789'
)
def
testDotImport
(
self
):
'''
This test guarantees that "import a.b" works in Jupyter.
'''
self
.
login
(
'dev_user'
)
import_code
=
'''
import scipy.io
'''
reference
=
'Test.Notebook.EnvironmentObject.Errors.Import'
result
=
self
.
portal
.
Base_executeJupyter
(
reference
=
reference
,
python_expression
=
import_code
)
self
.
tic
()
result
=
json
.
loads
(
result
)
self
.
assertEquals
(
result
[
'status'
],
'ok'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment