Skip to content

Commit

Permalink
Merge pull request #48 from desihub/py3basestring
Browse files Browse the repository at this point in the history
Be compatible with py2 and py3 without 2to3.  Fixes #47.
  • Loading branch information
dkirkby authored Sep 12, 2016
2 parents c69a1e5 + 309b013 commit c56e339
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion specsim/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 5 additions & 1 deletion specsim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions specsim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion specsim/tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -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, \
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions specsim/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c56e339

Please sign in to comment.