From 309b0130e08943e006932eadad5e85a92a1f1ab6 Mon Sep 17 00:00:00 2001 From: Stephen Bailey Date: Thu, 8 Sep 2016 17:06:47 -0700 Subject: [PATCH] compatible with py2 and py3 without 2to3 --- setup.py | 2 +- specsim/camera.py | 2 +- specsim/config.py | 6 +++++- specsim/simulator.py | 4 ++++ specsim/tests/test_transform.py | 4 +++- specsim/transform.py | 4 ++++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 2b8da72..4331b32 100755 --- a/setup.py +++ b/setup.py @@ -116,7 +116,7 @@ long_description=LONG_DESCRIPTION, cmdclass=cmdclassd, zip_safe=False, - use_2to3=True, + use_2to3=False, entry_points=entry_points, **package_info ) diff --git a/specsim/camera.py b/specsim/camera.py index 613a88b..2f7919a 100644 --- a/specsim/camera.py +++ b/specsim/camera.py @@ -191,7 +191,7 @@ def __init__(self, name, wavelength, throughput, row_size, # Fill sparse matrix arrays. sparse_start = 0 - for i in xrange(matrix_stop - matrix_start): + for i in range(matrix_stop - matrix_start): eval_slice = slice(eval_start[i], eval_stop[i]) w = self._wavelength[eval_slice] dw = self._wavelength_bin_size[eval_slice] diff --git a/specsim/config.py b/specsim/config.py index 93be13c..8e807ab 100644 --- a/specsim/config.py +++ b/specsim/config.py @@ -41,6 +41,10 @@ import astropy.coordinates import astropy.time +try: + basestring #- exists in py2 +except NameError: + basestring = str #- for py3 # Extract a number from a string with optional leading and # trailing whitespace. @@ -370,7 +374,7 @@ def load_table(self, parent, column_names, interpolate=True, as_dict=False): # Look for parent.table.path first. paths.append(os.path.join(self.abs_base_path, node.path)) except AttributeError: - path_keys = node.paths.keys() + path_keys = list(node.paths.keys()) for key in path_keys: path = getattr(node.paths, key) paths.append(os.path.join(self.abs_base_path, path)) diff --git a/specsim/simulator.py b/specsim/simulator.py index 2163c40..6ed085b 100644 --- a/specsim/simulator.py +++ b/specsim/simulator.py @@ -30,6 +30,10 @@ import specsim.source import specsim.observation +try: + basestring #- exists in py2 +except NameError: + basestring = str #- for py3 class Simulator(object): """Manage the simulation of a source, atmosphere and instrument. diff --git a/specsim/tests/test_transform.py b/specsim/tests/test_transform.py index f2880dd..9f3bcd6 100644 --- a/specsim/tests/test_transform.py +++ b/specsim/tests/test_transform.py @@ -1,5 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst +from __future__ import absolute_import, division, print_function + from astropy.tests.helper import pytest, remote_data from ..transform import altaz_to_focalplane, focalplane_to_altaz, \ observatories, create_observing_model, sky_to_altaz, altaz_to_sky, \ @@ -180,7 +182,7 @@ def test_alt_warn_pressure_array(): altaz_to_sky(alt, 0*u.deg, obs_model) alt = np.array([alt0 - 1, alt0 + 1]) * u.deg with pytest.raises(UserWarning): - print altaz_to_sky(alt[:, np.newaxis], 0*u.deg, obs_model).shape + print(altaz_to_sky(alt[:, np.newaxis], 0*u.deg, obs_model).shape) @remote_data diff --git a/specsim/transform.py b/specsim/transform.py index 42278a8..fe926cf 100644 --- a/specsim/transform.py +++ b/specsim/transform.py @@ -50,6 +50,10 @@ import astropy.constants from astropy import units as u +try: + basestring #- exists in py2 +except NameError: + basestring = str #- for py3 observatories = { 'APO': astropy.coordinates.EarthLocation.from_geodetic(