From 24660dd63563bd373724b61eb79f893c2a006700 2012-09-29 19:12:23 From: Matthias BUSSONNIER Date: 2012-09-29 19:12:23 Subject: [PATCH] a few fixes - default back tom Mathjax2.0 - install to profile by default - fix in doc - fix bad return --- diff --git a/IPython/external/mathjax.py b/IPython/external/mathjax.py index 93c15fb..97dbb9d 100644 --- a/IPython/external/mathjax.py +++ b/IPython/external/mathjax.py @@ -1,6 +1,12 @@ """Utility function for installing MathJax javascript library into the notebook's 'static' directory, for offline use. + Authors: + + * Min RK + * Mark Sienkiewicz + * Matthias Bussonnier + To download and install MathJax: From Python: @@ -33,11 +39,6 @@ To find the directory where IPython would like MathJax installed: # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- -# Authors: -# -# * Min RK -# * Mark Sienkiewicz at Space Telescope Science Institute (command line invocation) -# #----------------------------------------------------------------------------- # Imports @@ -50,16 +51,13 @@ import tarfile import urllib2 import zipfile -from IPython.frontend.html import notebook as nbmod - #----------------------------------------------------------------------------- # #----------------------------------------------------------------------------- # Where mathjax will be installed. -static = os.path.join(os.path.dirname(os.path.abspath(nbmod.__file__)), 'static') -dest = os.path.join(static, 'mathjax') +dest = os.path.join(locate_profile('default'), 'static') ## @@ -67,11 +65,11 @@ dest = os.path.join(static, 'mathjax') def check_perms(replace=False): if not os.access(static, os.W_OK): - raise IOError("Need have write access to %s"%static) + raise IOError("Need have write access to %s" % static) if os.path.exists(dest): if replace: if not os.access(dest, os.W_OK): - raise IOError("Need have write access to %s"%dest) + raise IOError("Need have write access to %s" % dest) print "removing previous MathJax install" shutil.rmtree(dest) return True @@ -116,8 +114,8 @@ def extract_zip( fd, dest ) : ## -def install_mathjax(tag='v1.1', replace=False, fd=None, extractor=extract_tar ): - """Download and install MathJax for offline use. +def install_mathjax(tag='v2.0', replace=False, file=None, extractor=extract_tar ): + """Download and/or install MathJax for offline use. This will install mathjax to the 'static' dir in the IPython notebook package, so it will fail if the caller does not have write access @@ -130,20 +128,24 @@ def install_mathjax(tag='v1.1', replace=False, fd=None, extractor=extract_tar ): replace : bool [False] Whether to remove and replace an existing install. - tag : str ['v1.1'] + tag : str ['v2.0'] Which tag to download. Default is 'v1.1', the current stable release, but alternatives include 'v1.1a' and 'master'. + file : file like object [ defualt to content of https://github.com/mathjax/MathJax/tarball/#{tag}] + File handle from which to untar/unzip/... mathjax + extractor : function + Method tu use to untar/unzip/... `file` """ if not check_perms(replace) : return - if fd is None : + if file is None : # download mathjax mathjax_url = "https://github.com/mathjax/MathJax/tarball/%s"%tag print "Downloading mathjax source from %s"%mathjax_url response = urllib2.urlopen(mathjax_url) - fd = response.fp + file = response.fp print "Extracting to %s"%dest extractor( fd, dest ) @@ -161,7 +163,7 @@ def test_func( remove ) : print "ok" if remove : shutil.rmtree( dest ) - return 0 + return status ## @@ -190,7 +192,7 @@ def main( args ) : if '-test' in args : return test_func( replace ) - # do it + # do it if len(args) == 0 : # This is compatible with the interface documented in ipython 0.13 install_mathjax( replace=replace ) @@ -230,7 +232,7 @@ python -m IPython.external.mathjax -test -r # download and install mathjax from command line: -python -m IPython.external.mathjax +python -m IPython.external.mathjax python -m IPython.external.mathjax -test -r # download and install from within python @@ -249,14 +251,14 @@ python -m IPython.external.mathjax -test -r # (this is the url used internally by install_mathjax) # The file it offers is mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz -python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz +python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz python -m IPython.external.mathjax -test - # note no -r + # note no -r # install it again while it is already there -python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz +python -m IPython.external.mathjax mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz # says "offline MathJax apparently already installed" python -m IPython.external.mathjax ~/mathjax-MathJax-v1.1-0-g5a7e4d7.tar.gz diff --git a/docs/source/install/install.txt b/docs/source/install/install.txt index 96985df..0be2f0d 100644 --- a/docs/source/install/install.txt +++ b/docs/source/install/install.txt @@ -357,8 +357,9 @@ For unusual needs, IPython can tell you what directory it wants to find MathJax python -m IPython.external.mathjax -d -All of these options require write access to the IPython install directory, so if -you have a system-wide Python install, it may need to be done with ``sudo``. +By default Mathjax will be installed in your ipython profile directory, but you +can make system wide install, please refere to the documentation and helper function +of IPython.external.mathjax Browser Compatibility ---------------------