##// END OF EJS Templates
Backport PR #10788: None...
Backport PR #10788: None The filename was generated taking the last digits of a randomly generated number between 0 and 1, if the number is small enough, it's repr ends with `e-5`, or less (the probability is actually close to 1/1000 because the biggest number we can get with e-5 is (1e-4 - epsilon). We actually did hit that on our CI: - https://ci.appveyor.com/project/IPython/ipython/build/1.0.839/job/mk4l08s295ynkfs5 ``` ====================================================================== ERROR: test_run_submodule_with_absolute_import (IPython.core.tests.test_run.TestMagicRunWithPackage) ---------------------------------------------------------------------- Traceback (most recent call last): File "c:\python36-x64\lib\site-packages\IPython\core\tests\test_run.py", line 455, in test_run_submodule_with_absolute_import self.check_run_submodule('absolute') File "c:\python36-x64\lib\site-packages\IPython\core\tests\test_run.py", line 450, in check_run_submodule self.assertEqual(_ip.user_ns['x'], self.value, KeyError: 'x' -------------------- >> begin captured stdout << --------------------- File "C:\Users\appveyor\AppData\Local\Temp\1\tmp4asmvv33\tmpqpswwe9n\tmp065832886952393e-05\absolute.py", line 2 from tmp065832886952393e-05.sub import x ^ SyntaxError: invalid syntax ``` Actually pick a random string now we should have less chance of being invalid identifier.

File last commit:

r22310:b51ccffc
r23902:0c08982d
Show More
display.py
65 lines | 2.1 KiB | text/x-python | PythonLexer
"""Simple magics for display formats"""
#-----------------------------------------------------------------------------
# Copyright (c) 2012 The IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Our own packages
from IPython.core.display import display, Javascript, Latex, SVG, HTML
from IPython.core.magic import (
Magics, magics_class, cell_magic
)
#-----------------------------------------------------------------------------
# Magic implementation classes
#-----------------------------------------------------------------------------
@magics_class
class DisplayMagics(Magics):
"""Magics for displaying various output types with literals
Defines javascript/latex/svg/html cell magics for writing
blocks in those languages, to be rendered in the frontend.
"""
@cell_magic
def js(self, line, cell):
"""Run the cell block of Javascript code
Alias of `%%javascript`
"""
self.javascript(line, cell)
@cell_magic
def javascript(self, line, cell):
"""Run the cell block of Javascript code"""
display(Javascript(cell))
@cell_magic
def latex(self, line, cell):
"""Render the cell as a block of latex
The subset of latex which is support depends on the implementation in
the client. In the Jupyter Notebook, this magic only renders the subset
of latex defined by MathJax
[here](https://docs.mathjax.org/en/v2.5-latest/tex.html)."""
display(Latex(cell))
@cell_magic
def svg(self, line, cell):
"""Render the cell as an SVG literal"""
display(SVG(cell))
@cell_magic
def html(self, line, cell):
"""Render the cell as a block of HTML"""
display(HTML(cell))