Skip to content

Commit

Permalink
Merge pull request #7 from sot/py3
Browse files Browse the repository at this point in the history
Python 3 compatibilty
  • Loading branch information
taldcroft authored Jan 20, 2017
2 parents 628310f + c1f1b2f commit 5d9acf0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 91 deletions.
12 changes: 7 additions & 5 deletions Ska/tdb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from .tdb import *

__version__ = '3.5.1'


def test(*args, **kwargs):
import os
import pytest
pkg_path = os.path.dirname(__file__)
os.chdir(pkg_path)
pytest.main(list(args), **kwargs)
'''
Run py.test unit tests.
'''
import testr
return testr.test(*args, **kwargs)
25 changes: 20 additions & 5 deletions Ska/tdb/tdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import glob

import numpy as np
import six

from .version import version as __version__

__all__ = ['msids', 'tables', '__version__', 'set_tdb_version', 'get_tdb_version',
__all__ = ['msids', 'tables', 'set_tdb_version', 'get_tdb_version',
'TableView', 'MsidView']


Expand Down Expand Up @@ -128,10 +127,26 @@ class TableView(object):
tables['tpp']['TEPHIN'] # Point pair for TEPHIN
"""
def __init__(self, data):
self.data = data
if six.PY2 or isinstance(data, np.void):
# np.void case is when TableView is passed a table row, in which case
# it has already been converted to string.
self.data = data

else:
# Convert numpy bytes (S) to string (U) within structured array
dtypes = []
for name, typestr in data.dtype.descr:
typestr = re.sub(r'S', 'U', typestr)
dtypes.append((name, typestr))
out = np.ndarray(len(data), dtype=dtypes)
for name in data.dtype.names:
# Note that numpy doesn't require explicit decode encoding to
# be specified.
out[name] = data[name]
self.data = out

def __getitem__(self, item):
if isinstance(item, basestring):
if isinstance(item, six.string_types):
item = item.upper()
if (item not in self.data.dtype.names and
'MSID' in self.data.dtype.names):
Expand Down
63 changes: 0 additions & 63 deletions Ska/tdb/version.py

This file was deleted.

26 changes: 8 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand

from Ska.tdb.version import version
from Ska.tdb import __version__


class PyTest(TestCommand):
user_options = [('args=', 'a', "Arguments to pass to py.test")]

def initialize_options(self):
TestCommand.initialize_options(self)
self.args = []

def run_tests(self):
import pytest
errno = pytest.main(self.args)
sys.exit(errno)
try:
from testr.setup_helper import cmdclass
except ImportError:
cmdclass = {}


setup(name='Ska.tdb',
author='Tom Aldcroft',
url="http://cxc.harvard.edu/mta/ASPECT/tool_doc/pydocs/Ska.tdb",
description='Access to Chandra Telemetry Database (TDB)',
author_email='aldcroft@head.cfa.harvard.edu',
version=version,
author_email='taldcroft@cfa.harvard.edu',
version=__version__,
zip_safe=False,
packages=['Ska', 'Ska.tdb', 'Ska.tdb.tests'],
package_dir={'Ska.tdb': 'Ska/tdb'},
tests_require=['pytest'],
cmdclass={'test': PyTest}
cmdclass=cmdclass,
)

0 comments on commit 5d9acf0

Please sign in to comment.