Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
Jupyter Docker Stacks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Jupyter Docker Stacks
Commits
42103bab
Commit
42103bab
authored
Jul 11, 2016
by
Peter Parente
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch to import hook from @minrk
parent
acca69d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
2 deletions
+57
-2
scipy-notebook/Dockerfile
scipy-notebook/Dockerfile
+2
-2
scipy-notebook/mplimporthook.py
scipy-notebook/mplimporthook.py
+55
-0
No files found.
scipy-notebook/Dockerfile
View file @
42103bab
...
...
@@ -64,8 +64,8 @@ RUN ln -s $CONDA_DIR/envs/python2/bin/pip $CONDA_DIR/bin/pip2 && \
ln
-s
$CONDA_DIR
/bin/pip
$CONDA_DIR
/bin/pip3
# Configure ipython kernel to use matplotlib inline backend by default
RUN
mkdir
-p
$HOME
/.ipython/profile_default
&&
\
echo
"c.InteractiveShellApp.matplotlib = 'inline'"
>
$HOME
/.ipython/profile_default/ipython_kernel_config.py
RUN
mkdir
-p
$HOME
/.ipython/profile_default
/startup
COPY
mplimporthook.py $HOME/.ipython/profile_default/startup/
USER
root
...
...
scipy-notebook/mplimporthook.py
0 → 100644
View file @
42103bab
"""Startup script for IPython kernel.
Installs an import hook to configure the matplotlib backend on the fly.
Originally from @minrk at
https://github.com/minrk/profile_default/blob/master/startup/mplimporthook.py
Repurposed for docker-stacks to address repeat bugs like
https://github.com/jupyter/docker-stacks/issues/235.
"""
import
sys
from
IPython
import
get_ipython
class
MatplotlibFinder
(
object
):
"""Import hook that notices when matplotlib.pyplot or pylab is imported
and tries to configure the matplotlib backend appropriately for the
environment.
"""
_called
=
False
def
find_module
(
self
,
fullname
,
path
=
None
):
if
self
.
_called
:
# already handled
return
if
fullname
not
in
(
'pylab'
,
'matplotlib.pyplot'
):
# not matplotlib
return
# don't call me again
self
.
_called
=
True
try
:
# remove myself from the import hooks
sys
.
meta_path
=
[
loader
for
loader
in
sys
.
meta_path
if
loader
is
not
self
]
except
ValueError
:
pass
ip
=
get_ipython
()
if
ip
is
None
:
# not in an interactive environment
return
if
ip
.
pylab_gui_select
:
# backend already selected
return
if
hasattr
(
ip
,
'kernel'
):
# default to inline in kernel environments
ip
.
enable_matplotlib
(
'inline'
)
else
:
print
(
'enabling matplotlib'
)
ip
.
enable_matplotlib
()
# install the finder immediately
sys
.
meta_path
.
insert
(
0
,
MatplotlibFinder
())
\ No newline at end of file
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