Skip to content

Commit

Permalink
Common Python 2 / 3 code base without 2to3
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeil committed Jul 22, 2014
1 parent 3edc7f1 commit 5b3324e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -36,5 +36,9 @@ distribute-*.tar.gz
.*.swp
*~

.project
.pydevproject
.settings

# Mac OSX
.DS_Store
8 changes: 5 additions & 3 deletions aplpy/aplpy.py
Expand Up @@ -3,6 +3,7 @@
from distutils import version
import os
import operator
from functools import reduce

import matplotlib

Expand All @@ -11,6 +12,7 @@

import matplotlib.pyplot as mpl
import mpl_toolkits.axes_grid.parasite_axes as mpltk
from astropy.extern import six

WCS_TYPES = []
HDU_TYPES = []
Expand Down Expand Up @@ -183,7 +185,7 @@ def __init__(self, data, hdu=0, figure=None, subplot=(1, 1, 1),
if not 'figsize' in kwargs:
kwargs['figsize'] = (10, 9)

if isinstance(data, basestring) and data.split('.')[-1].lower() in ['png', 'jpg', 'tif']:
if isinstance(data, six.string_types) and data.split('.')[-1].lower() in ['png', 'jpg', 'tif']:

try:
from PIL import Image
Expand Down Expand Up @@ -324,7 +326,7 @@ def __init__(self, data, hdu=0, figure=None, subplot=(1, 1, 1),

def _get_hdu(self, data, hdu, north, convention=None, dimensions=[0, 1], slices=[]):

if isinstance(data, basestring):
if isinstance(data, six.string_types):

filename = data

Expand Down Expand Up @@ -1577,7 +1579,7 @@ def save(self, filename, dpi=None, transparent=False, adjust_bbox=True, max_dpi=
explicitly. Should be one of 'eps', 'ps', 'pdf', 'svg', 'png'.
'''

if isinstance(filename, basestring) and format is None:
if isinstance(filename, six.string_types) and format is None:
format = os.path.splitext(filename)[1].lower()[1:]

if dpi is None and format in ['eps', 'ps', 'pdf']:
Expand Down
4 changes: 2 additions & 2 deletions aplpy/contour_util.py
Expand Up @@ -33,9 +33,9 @@ def transform(contours, wcs_in, wcs_out, filled=False, overlap=False):
continue

if filled:
polygons_out.append(Path(np.array(zip(xp_out, yp_out)), codes=polygon.codes))
polygons_out.append(Path(np.array(list(zip(xp_out, yp_out))), codes=polygon.codes))
else:
polygons_out.append(zip(xp_out, yp_out))
polygons_out.append(list(zip(xp_out, yp_out)))

if filled:
contour.set_paths(polygons_out)
Expand Down
4 changes: 2 additions & 2 deletions aplpy/grid.py
Expand Up @@ -354,7 +354,7 @@ def plot_grid_y(ax, grid_x, grid_y, gy, alpha=0.5):
x_world = math_util.complete_range(grid_x_min, grid_x_max, 100)
y_world = np.repeat(gy, len(x_world))
x_pix, y_pix = wcs_util.world2pix(wcs, x_world, y_world)
lines_out.append(zip(x_pix, y_pix))
lines_out.append(list(zip(x_pix, y_pix)))

return lines_out

Expand Down Expand Up @@ -412,7 +412,7 @@ def plot_grid_x(ax, grid_x, grid_y, gx, alpha=0.5):
y_world = math_util.complete_range(grid_y_min, grid_y_max, 100)
x_world = np.repeat(gx, len(y_world))
x_pix, y_pix = wcs_util.world2pix(wcs, x_world, y_world)
lines_out.append(zip(x_pix, y_pix))
lines_out.append(list(zip(x_pix, y_pix)))

return lines_out

Expand Down
12 changes: 7 additions & 5 deletions aplpy/overlays.py
Expand Up @@ -9,6 +9,8 @@
from matplotlib.patches import FancyArrowPatch
from matplotlib.font_manager import FontProperties

from astropy.extern import six

from . import wcs_util
from .decorators import auto_refresh

Expand Down Expand Up @@ -203,7 +205,7 @@ def show(self, length, label=None, corner='bottom right', frame=False, borderpad
except:
pass

if isinstance(corner, basestring):
if isinstance(corner, six.string_types):
corner = corners[corner]

self._scalebar = AnchoredSizeBar(self._ax.transData, length, label, corner, \
Expand Down Expand Up @@ -470,13 +472,13 @@ def show(self, major='BMAJ', minor='BMIN', \
See the matplotlib documentation for more details.
'''

if isinstance(major, basestring):
if isinstance(major, six.string_types):
major = self._header[major]

if isinstance(minor, basestring):
if isinstance(minor, six.string_types):
minor = self._header[minor]

if isinstance(angle, basestring):
if isinstance(angle, six.string_types):
angle = self._header[angle]

degrees_per_pixel = wcs_util.degperpix(self._wcs)
Expand All @@ -497,7 +499,7 @@ def show(self, major='BMAJ', minor='BMIN', \
except:
pass

if isinstance(corner, basestring):
if isinstance(corner, six.string_types):
corner = corners[corner]

self._beam = AnchoredEllipse(self._ax.transData, \
Expand Down
3 changes: 2 additions & 1 deletion aplpy/regions.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import, print_function, division

from astropy.extern import six
from astropy import log

from .decorators import auto_refresh
Expand Down Expand Up @@ -90,7 +91,7 @@ def ds9(region_file, header, zorder=3, **kwargs):
raise ImportError("The pyregion package is required to load region files")

# read region file
if isinstance(region_file, basestring):
if isinstance(region_file, six.string_types):
rr = pyregion.open(region_file)
elif isinstance(region_file, pyregion.ShapeList):
rr = region_file
Expand Down
3 changes: 2 additions & 1 deletion aplpy/rgb.py
Expand Up @@ -8,6 +8,7 @@
import shutil

import numpy as np
from astropy.extern import six
from astropy import log
from astropy.io import fits

Expand Down Expand Up @@ -128,7 +129,7 @@ def make_rgb_image(data, output, indices=(0, 1, 2), \
except ImportError:
raise ImportError("The Python Imaging Library (PIL) is required to make an RGB image")

if isinstance(data, basestring):
if isinstance(data, six.string_types):

image = fits.getdata(data)
image_r = image[indices[0], :, :]
Expand Down
5 changes: 3 additions & 2 deletions aplpy/tests/test_save.py
@@ -1,7 +1,8 @@
import os
import sys
from astropy.extern import six

if sys.version_info[0] > 2:
if six.PY3:
from io import BytesIO as StringIO
else:
from StringIO import StringIO
Expand All @@ -15,7 +16,7 @@


def is_format(filename, format):
if isinstance(filename, basestring):
if isinstance(filename, six.string_types):
f = open(filename, 'rb')
else:
f = filename
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -104,7 +104,7 @@
long_description=LONG_DESCRIPTION,
cmdclass=cmdclassd,
zip_safe=False,
use_2to3=True,
use_2to3=False,
classifiers=[
"Development Status :: 4 - Beta",
"Programming Language :: Python",
Expand Down

0 comments on commit 5b3324e

Please sign in to comment.