Programmatically generate SVG (vector) images, animations, and interactive Jupyter widgets

Fix OSError message when importing CairoSVG (#10)

Changed files
+36 -4
drawSvg
+19
README.md
···
An interactive [Jupyter notebook](https://jupyter.org) widget, `drawSvg.widgets.DrawingWidget`, is included that can update drawings based on mouse events.
# Install
+
drawSvg is available on PyPI:
```
$ pip3 install drawSvg
+
```
+
+
## Prerequisites
+
+
Cairo needs to be installed separately. When Cairo is installed, drawSvg can output PNG or other image formats in addition to SVG. See platform-specific [instructions for Linux, Windows, and macOS from Cairo](https://www.cairographics.org/download/). Below are some examples for installing Cairo on Linux distributions and macOS.
+
+
**Ubuntu**
+
+
```
+
$ sudo apt-get install libcairo2
+
```
+
+
**macOS**
+
+
Using [homebrew](https://brew.sh/):
+
+
```
+
$ brew install cairo
```
# Examples
+17 -4
drawSvg/raster.py
···
import io
+
import warnings
+
from .missing import MissingModule
+
try:
import cairosvg
-
except (ImportError, OSError):
-
import warnings
-
from .missing import MissingModule
-
msg = 'CairoSVG will need to be installed to rasterize images: Install with `pip3 install cairosvg`'
+
except OSError as e:
+
msg = (
+
'Failed to import CairoSVG. '
+
'drawSvg will be unable to output PNG or other raster image formats. '
+
'See https://github.com/cduck/drawSvg#prerequisites for more details.\n'
+
'Original OSError: {}'.format(e)
+
)
+
cairosvg = MissingModule(msg)
+
warnings.warn(msg, RuntimeWarning)
+
except ImportError as e:
+
msg = (
+
'CairoSVG will need to be installed to rasterize images: Install with `pip3 install cairosvg`\n'
+
'Original ImportError: {}'.format(e)
+
)
cairosvg = MissingModule(msg)
warnings.warn(msg, RuntimeWarning)