Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PyCXX dependency for core extension modules #3646

Merged
merged 18 commits into from Oct 18, 2014
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Expand Up @@ -24,8 +24,8 @@ matrix:

install:
- pip install -q --use-mirrors nose python-dateutil $NUMPY pep8 pyparsing pillow
- sudo apt-get update && sudo apt-get -qq install inkscape libav-tools
# We use --no-install-recommends to avoid pulling in additional large latex docs that we don't need
- sudo apt-get update && sudo apt-get -qq install inkscape libav-tools gdb
# We use --no-install-recommends to avoid pulling in additional large latex docs that we don't need
- if [[ $BUILD_DOCS == true ]]; then sudo apt-get install -qq --no-install-recommends dvipng texlive-latex-base texlive-latex-extra texlive-fonts-recommended graphviz; fi
- if [[ $BUILD_DOCS == true ]]; then pip install sphinx numpydoc linkchecker; fi
- python setup.py install
Expand All @@ -37,11 +37,12 @@ script:
- echo Testing using 8 processes
# Generate the font caches in a single process before starting the
# multiple processes
- gcc --version
- python -c "from matplotlib import font_manager"
- if [[ $BUILD_DOCS == false ]]; then export MPL_REPO_DIR=$PWD; fi # pep8-conformance test of the examples
- if [[ $BUILD_DOCS == false ]]; then mkdir ../tmp_test_dir; fi
- if [[ $BUILD_DOCS == false ]]; then cd ../tmp_test_dir; fi
- if [[ $BUILD_DOCS == false ]]; then python ../matplotlib/tests.py -sv --processes=8 --process-timeout=300 $TEST_ARGS; fi
- if [[ $BUILD_DOCS == false ]]; then gdb -return-child-result -batch -ex r -ex bt --args python ../matplotlib/tests.py -sv --processes=8 --process-timeout=300 $TEST_ARGS; fi
- if [[ $BUILD_DOCS == true ]]; then cd doc; python make.py html --small; fi
# We don't build the LaTeX docs here, so linkchecker will complain
- if [[ $BUILD_DOCS == true ]]; then touch build/html/Matplotlib.pdf; fi
Expand Down
7 changes: 1 addition & 6 deletions examples/pylab_examples/agg_buffer_to_array.py
Expand Up @@ -8,12 +8,7 @@
fig.canvas.draw()

# grab the pixel buffer and dump it into a numpy array
buf = fig.canvas.buffer_rgba()
l, b, w, h = fig.bbox.bounds
# The array needs to be copied, because the underlying buffer
# may be reallocated when the window is resized.
X = np.frombuffer(buf, np.uint8).copy()
X.shape = h,w,4
X = np.array(fig.canvas.renderer._renderer)

# now display the array X as an Axes in a new figure
fig2 = plt.figure()
Expand Down
1 change: 0 additions & 1 deletion examples/pylab_examples/mathtext_demo.py 100644 → 100755
Expand Up @@ -24,5 +24,4 @@

ax.set_title(r'$\Delta_i^j \hspace{0.4} \mathrm{versus} \hspace{0.4} \Delta_{i+1}^j$', fontsize=20)


show()
7 changes: 7 additions & 0 deletions lib/matplotlib/__init__.py
Expand Up @@ -1405,6 +1405,13 @@ def tk_window_focus():

def test(verbosity=1):
"""run the matplotlib test suite"""
try:
import faulthandler
except ImportError:
pass
else:
faulthandler.enable()

old_backend = rcParams['backend']
try:
use('agg')
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_base.py
Expand Up @@ -2063,8 +2063,8 @@ def draw(self, renderer=None, inframe=False):
for z, im in zorder_images]

l, b, r, t = self.bbox.extents
width = mag * ((round(r) + 0.5) - (round(l) - 0.5))
height = mag * ((round(t) + 0.5) - (round(b) - 0.5))
width = int(mag * ((round(r) + 0.5) - (round(l) - 0.5)))
height = int(mag * ((round(t) + 0.5) - (round(b) - 0.5)))
im = mimage.from_images(height,
width,
ims)
Expand Down
28 changes: 15 additions & 13 deletions lib/matplotlib/backends/backend_agg.py
Expand Up @@ -127,15 +127,19 @@ def draw_path_collection(self, *kl, **kw):
return self._renderer.draw_path_collection(*kl, **kw)

def _update_methods(self):
#self.draw_path = self._renderer.draw_path # see below
#self.draw_markers = self._renderer.draw_markers
#self.draw_path_collection = self._renderer.draw_path_collection
self.draw_quad_mesh = self._renderer.draw_quad_mesh
self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle
self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles
self.draw_image = self._renderer.draw_image
self.copy_from_bbox = self._renderer.copy_from_bbox
self.tostring_rgba_minimized = self._renderer.tostring_rgba_minimized
self.get_content_extents = self._renderer.get_content_extents

def tostring_rgba_minimized(self):
extents = self.get_content_extents()
bbox = [[extents[0], self.height - (extents[1] + extents[3])],
[extents[0] + extents[2], self.height - extents[1]]]
region = self.copy_from_bbox(bbox)
return np.array(region), extents

def draw_path(self, gc, path, transform, rgbFace=None):
"""
Expand Down Expand Up @@ -203,7 +207,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):

#print x, y, int(x), int(y), s
self._renderer.draw_text_image(
font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc)
font, np.round(x - xd), np.round(y + yd) + 1, angle, gc)

def get_text_width_height_descent(self, s, prop, ismath):
"""
Expand Down Expand Up @@ -354,7 +358,7 @@ def restore_region(self, region, bbox=None, xy=None):
else:
ox, oy = xy

self._renderer.restore_region2(region, x1, y1, x2, y2, ox, oy)
self._renderer.restore_region(region, x1, y1, x2, y2, ox, oy)

else:
self._renderer.restore_region(region)
Expand Down Expand Up @@ -394,7 +398,7 @@ def post_processing(image, dpi):

width, height = int(self.width), int(self.height)

buffer, bounds = self._renderer.tostring_rgba_minimized()
buffer, bounds = self.tostring_rgba_minimized()

l, b, w, h = bounds

Expand All @@ -407,7 +411,6 @@ def post_processing(image, dpi):
img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255.,
self.dpi)
image = fromarray(img, 1)
image.flipud_out()

gc = self.new_gc()
self._renderer.draw_image(gc,
Expand Down Expand Up @@ -505,12 +508,13 @@ def print_raw(self, filename_or_obj, *args, **kwargs):
original_dpi = renderer.dpi
renderer.dpi = self.figure.dpi
if is_string_like(filename_or_obj):
filename_or_obj = open(filename_or_obj, 'wb')
fileobj = open(filename_or_obj, 'wb')
close = True
else:
fileobj = filename_or_obj
close = False
try:
renderer._renderer.write_rgba(filename_or_obj)
fileobj.write(renderer._renderer.buffer_rgba())
finally:
if close:
filename_or_obj.close()
Expand All @@ -528,9 +532,7 @@ def print_png(self, filename_or_obj, *args, **kwargs):
else:
close = False
try:
_png.write_png(renderer._renderer.buffer_rgba(),
renderer.width, renderer.height,
filename_or_obj, self.figure.dpi)
_png.write_png(renderer._renderer, filename_or_obj, self.figure.dpi)
finally:
if close:
filename_or_obj.close()
Expand Down
4 changes: 0 additions & 4 deletions lib/matplotlib/backends/backend_cairo.py
Expand Up @@ -167,8 +167,6 @@ def draw_image(self, gc, x, y, im):
# bbox - not currently used
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))

im.flipud_out()

rows, cols, buf = im.color_conv (BYTE_FORMAT)
surface = cairo.ImageSurface.create_for_data (
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
Expand All @@ -183,8 +181,6 @@ def draw_image(self, gc, x, y, im):
ctx.paint()
ctx.restore()

im.flipud_out()

def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# Note: x,y are device/display coords, not user-coords, unlike other
# draw_* methods
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/backends/backend_gdk.py
Expand Up @@ -109,7 +109,6 @@ def draw_image(self, gc, x, y, im):
# int(w), int(h))
# set clip rect?

im.flipud_out()
rows, cols, image_str = im.as_rgba_str()

image_array = np.fromstring(image_str, np.uint8)
Expand All @@ -120,7 +119,7 @@ def draw_image(self, gc, x, y, im):
width=cols, height=rows)

array = pixbuf_get_pixels_array(pixbuf)
array[:,:,:] = image_array
array[:,:,:] = image_array[::-1]

gc = self.new_gc()

Expand All @@ -138,9 +137,6 @@ def draw_image(self, gc, x, y, im):
int(x), int(y), cols, rows,
gdk.RGB_DITHER_NONE, 0, 0)

# unflip
im.flipud_out()


def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
x, y = int(x), int(y)
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/backends/backend_macosx.py
Expand Up @@ -110,10 +110,8 @@ def get_image_magnification(self):
return self.gc.get_image_magnification()

def draw_image(self, gc, x, y, im):
im.flipud_out()
nrows, ncols, data = im.as_rgba_str()
gc.draw_image(x, y, nrows, ncols, data)
im.flipud_out()

def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
# todo, handle props, angle, origins
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/backends/backend_mixed.py
Expand Up @@ -121,7 +121,6 @@ def stop_rasterizing(self):
if w > 0 and h > 0:
image = frombuffer(buffer, w, h, True)
image.is_grayscale = False
image.flipud_out()
gc = self._renderer.new_gc()
# TODO: If the mixedmode resolution differs from the figure's
# dpi, the image must be scaled (dpi->_figdpi). Not all
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/backends/backend_pdf.py
Expand Up @@ -1241,6 +1241,7 @@ def _rgb(self, im):

rgba = np.fromstring(s, np.uint8)
rgba.shape = (h, w, 4)
rgba = rgba[::-1]
rgb = rgba[:, :, :3]
a = rgba[:, :, 3:]
return h, w, rgb.tostring(), a.tostring()
Expand All @@ -1249,6 +1250,7 @@ def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
rgbat = im.as_rgba_str()
rgba = np.fromstring(rgbat[2], np.uint8)
rgba.shape = (rgbat[0], rgbat[1], 4)
rgba = rgba[::-1]
rgba_f = rgba.astype(np.float32)
r = rgba_f[:, :, 0]
g = rgba_f[:, :, 1]
Expand All @@ -1258,7 +1260,6 @@ def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):

def writeImages(self):
for img, pair in six.iteritems(self.images):
img.flipud_out()
if img.is_grayscale:
height, width, data = self._gray(img)
self.beginStream(
Expand Down Expand Up @@ -1294,8 +1295,6 @@ def writeImages(self):
self.currentstream.write(data)
self.endStream()

img.flipud_out()

def markerObject(self, path, trans, fillp, strokep, lw, joinstyle,
capstyle):
"""Return name of a marker XObject representing the given path."""
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_pgf.py
Expand Up @@ -14,6 +14,8 @@
import weakref
import warnings

import numpy as np

import matplotlib as mpl
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase
Expand Down Expand Up @@ -619,9 +621,7 @@ def draw_image(self, gc, x, y, im):
fname = os.path.splitext(os.path.basename(self.fh.name))[0]
fname_img = "%s-img%d.png" % (fname, self.image_counter)
self.image_counter += 1
im.flipud_out()
rows, cols, buf = im.as_rgba_str()
_png.write_png(buf, cols, rows, os.path.join(path, fname_img))
_png.write_png(np.array(im)[::-1], os.path.join(path, fname_img))

# reference the image in the pgf picture
writeln(self.fh, r"\begin{pgfscope}")
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/backends/backend_ps.py
Expand Up @@ -414,13 +414,14 @@ def _rgb(self, im):

rgba = np.fromstring(s, np.uint8)
rgba.shape = (h, w, 4)
rgb = rgba[:,:,:3]
rgb = rgba[::-1,:,:3]
return h, w, rgb.tostring()

def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
rgbat = im.as_rgba_str()
rgba = np.fromstring(rgbat[2], np.uint8)
rgba.shape = (rgbat[0], rgbat[1], 4)
rgba = rgba[::-1]
rgba_f = rgba.astype(np.float32)
r = rgba_f[:,:,0]
g = rgba_f[:,:,1]
Expand Down Expand Up @@ -472,8 +473,6 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
interpreted as the coordinate of the transform.
"""

im.flipud_out()

h, w, bits, imagecmd = self._get_image_h_w_bits_command(im)
hexlines = b'\n'.join(self._hex_lines(bits)).decode('ascii')

Expand Down Expand Up @@ -524,9 +523,6 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
""" % locals()
self._pswriter.write(ps)

# unflip
im.flipud_out()

def _convert_path(self, path, transform, clip=False, simplify=None):
ps = []
last_points = None
Expand Down
10 changes: 2 additions & 8 deletions lib/matplotlib/backends/backend_svg.py
Expand Up @@ -800,10 +800,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
self.writer.start('a', attrib={'xlink:href': url})
if rcParams['svg.image_inline']:
bytesio = io.BytesIO()
im.flipud_out()
rows, cols, buffer = im.as_rgba_str()
_png.write_png(buffer, cols, rows, bytesio)
im.flipud_out()
_png.write_png(np.array(im)[::-1], bytesio)
oid = oid or self._make_id('image', bytesio)
attrib['xlink:href'] = (
"data:image/png;base64,\n" +
Expand All @@ -812,10 +809,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
self._imaged[self.basename] = self._imaged.get(self.basename,0) + 1
filename = '%s.image%d.png'%(self.basename, self._imaged[self.basename])
verbose.report( 'Writing image file for inclusion: %s' % filename)
im.flipud_out()
rows, cols, buffer = im.as_rgba_str()
_png.write_png(buffer, cols, rows, filename)
im.flipud_out()
_png.write_png(np.array(im)[::-1], filename)
oid = oid or 'Im_' + self._make_id('image', filename)
attrib['xlink:href'] = filename

Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_webagg_core.py
Expand Up @@ -143,8 +143,7 @@ def get_diff_image(self):
# TODO: We should write a new version of write_png that
# handles the differencing inline
_png.write_png(
output.tostring(),
output.shape[1], output.shape[0],
output,
self._png_buffer)

# Swap the renderer frames
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/delaunay/_delaunay.cpp
Expand Up @@ -6,7 +6,7 @@
#include "VoronoiDiagramGenerator.h"
#include "delaunay_utils.h"
#include "natneighbors.h"
#include "numpy/noprefix.h"
#include "numpy/ndarrayobject.h"

// support numpy 1.6 - this macro got renamed and deprecated at once in 1.7
#ifndef NPY_ARRAY_IN_ARRAY
Expand Down Expand Up @@ -123,7 +123,7 @@ static PyObject* getMesh(int npoints, double *x, double *y)
int tri0, tri1, reg0, reg1;
double tri0x, tri0y, tri1x, tri1y;
int length, numtri, i, j;
intp dim[MAX_DIMS];
npy_intp dim[NPY_MAXDIMS];
int *edge_db_ptr, *tri_edges_ptr, *tri_nbrs_ptr;
double *vertices_ptr;
VoronoiDiagramGenerator vdg;
Expand Down Expand Up @@ -221,7 +221,7 @@ static PyObject* getMesh(int npoints, double *x, double *y)
static PyObject *linear_planes(int ntriangles, double *x, double *y, double *z,
int *nodes)
{
intp dims[2];
npy_intp dims[2];
PyObject *planes;
int i;
double *planes_ptr;
Expand Down Expand Up @@ -286,7 +286,7 @@ static PyObject *linear_interpolate_grid(double x0, double x1, int xsteps,
int rowtri, coltri, tri;
PyObject *z;
double *z_ptr;
intp dims[2];
npy_intp dims[2];

dims[0] = ysteps;
dims[1] = xsteps;
Expand Down Expand Up @@ -596,7 +596,7 @@ static PyObject *nn_interpolate_method(PyObject *self, PyObject *args)
double x0, x1, y0, y1, defvalue;
int xsteps, ysteps;
int npoints, ntriangles;
intp dims[2];
npy_intp dims[2];

if (!PyArg_ParseTuple(args, "ddiddidOOOOOO", &x0, &x1, &xsteps,
&y0, &y1, &ysteps, &defvalue, &pyx, &pyy, &pyz, &pycenters, &pynodes,
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/figure.py
Expand Up @@ -1045,8 +1045,8 @@ def draw(self, renderer):
ims = [(im.make_image(mag), im.ox, im.oy, im.get_alpha())
for im in self.images]

im = _image.from_images(self.bbox.height * mag,
self.bbox.width * mag,
im = _image.from_images(int(self.bbox.height * mag),
int(self.bbox.width * mag),
ims)

im.is_grayscale = False
Expand Down