RSS <== blog page - 2/3 ==> Blog automation (4) documentation (8) example (2) latex (2) notebook (4) sphinx (10)


blog page - 2/3

Issue with module babel

2015-08-17

I went through the following issue with the latest version of babel (2.0). It happens when I try to generate the documentation for this module. It gave me the following exception:

  File "c:\python34_x64\lib\site-packages\sphinx\__init__.py", line 51, in main
    sys.exit(build_main(argv))
  File "c:\python34_x64\lib\site-packages\sphinx\__init__.py", line 61, in build_main
    from sphinx import cmdline
  File "c:\python34_x64\lib\site-packages\sphinx\cmdline.py", line 23, in <module>
    from sphinx.application import Sphinx
  File "c:\python34_x64\lib\site-packages\sphinx\application.py", line 37, in <module>
    from sphinx.builders import BUILTIN_BUILDERS
  File "c:\python34_x64\lib\site-packages\sphinx\builders\__init__.py", line 23, in <module>
    from sphinx.util import i18n, path_stabilize
  File "c:\python34_x64\lib\site-packages\sphinx\util\i18n.py", line 15, in <module>
    from babel.messages.pofile import read_po
  File "c:\python34_x64\lib\site-packages\babel\messages\__init__.py", line 12, in <module>
    from babel.messages.catalog import *
  File "c:\python34_x64\lib\site-packages\babel\messages\catalog.py", line 23, in <module>
    from babel.dates import format_datetime
  File "c:\python34_x64\lib\site-packages\babel\dates.py", line 28, in <module>
    from babel.util import UTC, LOCALTZ
  File "c:\python34_x64\lib\site-packages\babel\util.py", line 278, in <module>
    from babel import localtime
  File "c:\python34_x64\lib\site-packages\babel\localtime\__init__.py", line 21, in <module>
    from babel.localtime._win32 import _get_localzone
  File "c:\python34_x64\lib\site-packages\babel\localtime\_win32.py", line 18, in <module>
    tz_names = get_global('windows_zone_mapping')
  File "c:\python34_x64\lib\site-packages\babel\core.py", line 58, in get_global
    _global_data = pickle.load(fileobj)
TypeError: an integer is required (got type str)

The exception disappeared after I reverted to babel 1.3.

post

Convert a notebook into slides

2015-05-16

I thought it would be easy to convert a notebook into slides. I would just have to execute nbconvert. I went through two issues. The first one came from reveal.js. My first tries did not work. I decided to take the version included in the module sphinxjp.themes.revealjs and I also updated the output of nbconvert to remove external links as much as possible.

The second issue was that all my notebooks did not include any metadata indicated to indicate whether or not a new slide or subslide should start. So I create a simple function which does that on a notebook add_tag_slide. It does not overwrite existing metadata but start new slides for every section and new subslide if the current one becomes too long:

from pyquickhelper.ipythonhelper import read_nb
nb = read_nb("your notebook.ipynb")
nb.add_tag_slide()
nb.to_json("the modified notebook.ipynb")

It is too simple to be perfect, it is difficult to guess the size of the rendering of some objects (images, javascript...). You can check the results for this notebook: example pyquickhelper. That what the function nb2slides is doing first and then converts it into slides:

from pyquickhelper import nb2slides
nb2slides(("your notebook.ipynb", "convert.slides.html")

post

Add a custom menu to the notebook

2015-05-14

The function add_notebook_menu add HTML and Javascript to the notebook to create links to all sections in the notebook:

from pyquickhelper.ipythonhelper import add_notebook_menu
add_notebook_menu(menu_id="main_menu")

You can see what it looks like in notebook Example of a notebook with a fixed index. The trick consists in running:

from pyquickhelper.ipythonhelper import add_notebook_menu
add_notebook_menu(format="rst")

The menu can be then copy pasted into a text cell. It won’t be refreshed anymore but it will be converted as part of the notebook into RST, HTML or slides format.

post

Create a script to read this blog

2015-05-10

The module now includes a function write_module_scripts creates a script auto_rss_server.py which grabs the latest blog post from this stream, runs a server and opens the default browser to read them. It uses the module pyrsslocal. Here is the code to read this blog:

from pyquickhelper import write_module_scripts, __blog__
write_module_scripts("blog", blog_list=__blog__)

The blog list can be replaced by any other one. Here is its content:

<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
    <head>
        <title>blog</title>
    </head>
    <body>
        <outline text="pyquickhelper"
            title="pyquickhelper"
            type="rss"
            xmlUrl="http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/_downloads/rss.xml"
            htmlUrl="http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/blog/main_0000.html" />
    </body>
</opml>

post

Frequent commands and automation

2015-05-06

The script setup.py accepts several options such as install or build. It also accepts unittest to run the unit tests or build_sphinx to build the documentation. It usually requires to have a command line windows opened as well as an editor to write programs. On Windows, the module now produces a series of scripts to automate tasks such as running the unit tests, building the documentation. They are not included in the sources anymore but the can be obtained by typing:

python setup.py build_script

The scripts can now be produced for every module using pyquickhelper to automate setup, unit tests and documentation.

post

Visualize differences between two files in a notebook

2015-04-23

It is now possible to visualize the differences between two files directly from a notebook:

../_images/diffview1.png

See function create_visual_diff_through_html_files.

post

Producing a version for Python 2.7 from Python 3

2015-04-17

I tried to make most of the unit tests run under Python 2.7. Most of the function deals with strings for the documentation and it is a real pain to think again about str, unicode, bytes. Some of the functions only works in Python 3 but the goal was more to see what needed to be done.

The first issue came from exception:

try:
    something
except Exception as e:
    raise Exception("other message") from e

This syntax is not available and to avoid losing it, I decided to have two separate versions of the same module. I created a function py3to2_convert_tree <pyquickhelper.pycode.py3to2.py3to2_convert_tree> which copies the source and deals with this case (it removes everything it can).

I also had an issue with code like isinstance(v, long) as the long type does not exists. So I added the string int #long# to be replaced by long by a function. The one I use the most is str  #unicode# replaced by unicode.

The second issue is the function open. I usually use the following trick:

if sys.version_info[0]==2:
    from codecs import open

It does not solve everything (strings become unicode) and will melt with strings because I do not use u"..." which I could implement in the function py3to2_convert_tree <pyquickhelper.pycode.py3to2.py3to2_convert_tree>.

Running out of courage, I disabled some unit tests because they were not passing due to the encoding issues. I had to add in some files but maybe I should have added that everywhere:

from __future__ import print_function

The following is added everywhere:

from __future__ import unicode_literals

post

Migration to IPython 3.1

2015-04-16

It took me some time to do the migration to IPython 3.1. The code which automatically generates the documentation had to be updated to follow the new format of the notebooks. I had to redo the configuration of ipython to have the graph inline... I hope ipython does not rename itself into jupyter. The design is better but the notebooks crash from time to time. I guess the code becomes better each time a migration happens. But it takes quite some time. However, the changes are not reversible. Ipython needs to be updated otherwise the automated generation of the documentation will not work. For Jenkins, just remind that the server needs your credentials othewise it does not easily find pandoc.

post

Conversion to latex is taking for ever

2015-04-16

The unit tests are now scheduled using Jenkins. When the documentation is generated for the first time after a fresh installation of the machine (latex, sphinx...), the compilation can take for ever. This is due to extra packages needed by latex. When the process is run from a command line, a windows shows up asking for approval before going on installing the missing latex packages. As this command line is showing up in the output, it is just needed to executed from a command line window to import the missing package. After this short break, the latex compilation runs fine on Jenkins.

post

Anaconda does not have the latest version of Sphinx

2015-04-16

As of today, when I type conda update sphinx, The Anaconda distribution does not upgrade to 1.3 and I need it to get the extension sphinx.ext.napoleon. So I need to type pip install sphinx --upgrade instead.

post


RSS <== blog page - 2/3 ==> 2015-04 (8) 2015-05 (4) 2015-08 (2) 2015-10 (1) 2015-12 (3) 2016-01 (1) 2016-02 (3) 2016-04 (1) 2016-06 (1)