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

Python 3 compatibilty #7

Merged
merged 2 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)