Skip to content

Commit

Permalink
Drop support for Python 2.7 and 3.6 (#274)
Browse files Browse the repository at this point in the history
Also add 3.10 to the list of supported versions
  • Loading branch information
adamreeve committed Jun 15, 2022
1 parent 38d31ae commit c283ecb
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 116 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Install tox
run: pip install tox
- name: Run pycodestyle
Expand All @@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['2.7', '3.6', '3.7', '3.8', '3.9']
python: ['3.7', '3.8', '3.9', '3.10']
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Create package
run: python setup.py sdist
- name: Publish package
Expand Down
8 changes: 0 additions & 8 deletions build_docs.sh

This file was deleted.

24 changes: 7 additions & 17 deletions nptdms/common.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import itertools
try:
long
except NameError:
# Python 3
long = int
try:
zip_longest = itertools.izip_longest
except AttributeError:
# Python 3
zip_longest = itertools.zip_longest
from itertools import zip_longest


toc_properties = {
'kTocMetaData': (long(1) << 1),
'kTocRawData': (long(1) << 3),
'kTocDAQmxRawData': (long(1) << 7),
'kTocInterleavedData': (long(1) << 5),
'kTocBigEndian': (long(1) << 6),
'kTocNewObjList': (long(1) << 2)
'kTocMetaData': (1 << 1),
'kTocRawData': (1 << 3),
'kTocDAQmxRawData': (1 << 7),
'kTocInterleavedData': (1 << 5),
'kTocBigEndian': (1 << 6),
'kTocNewObjList': (1 << 2)
}


Expand Down
2 changes: 1 addition & 1 deletion nptdms/export/pandas_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import OrderedDict
import numpy as np
from nptdms.utils import OrderedDict


def from_tdms_file(tdms_file, time_index=False, absolute_time=False, scaled_data=True):
Expand Down
6 changes: 3 additions & 3 deletions nptdms/reader.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
""" Lower level TDMS reader API that allows finer grained reading of data
"""

from collections import OrderedDict
import logging
import os
import numpy as np
import struct

from nptdms import types
from nptdms.common import ObjectPath, toc_properties
from nptdms.utils import Timer, OrderedDict
from nptdms.common import toc_properties
from nptdms.utils import Timer
from nptdms.base_segment import RawChannelDataChunk
from nptdms.tdms_segment import TdmsSegment, SegmentIndexCache
from nptdms.log import log_manager
Expand Down
4 changes: 2 additions & 2 deletions nptdms/tdms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
This module contains the public facing API for reading TDMS files
"""

from collections import defaultdict
from collections import defaultdict, OrderedDict
import numpy as np

from nptdms import scaling, types
from nptdms.utils import Timer, OrderedDict, cached_property
from nptdms.utils import Timer, cached_property
from nptdms.log import log_manager
from nptdms.common import ObjectPath
from nptdms.reader import TdmsReader
Expand Down
5 changes: 1 addition & 4 deletions nptdms/test/test_tdmsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import sys
from nptdms import tdmsinfo
from nptdms.test.util import GeneratedFile, basic_segment
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch


def test_tdmsinfo(capsys):
Expand Down
21 changes: 7 additions & 14 deletions nptdms/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
from nptdms import tdms


try:
long
except NameError:
# Python 3
long = int


def string_hexlify(input_string):
"""Return hex string representation of string"""
return binascii.hexlify(input_string.encode('utf-8')).decode('utf-8')
Expand Down Expand Up @@ -235,20 +228,20 @@ def add_segment(self, toc, metadata, data, incomplete=False, binary_data=False,
data_bytes = data if binary_data else _hex_to_bytes(data)
if toc is not None:
lead_in = b'TDSm'
toc_mask = long(0)
toc_mask = 0
for toc_item in toc:
if toc_item == "kTocMetaData":
toc_mask = toc_mask | long(1) << 1
toc_mask = toc_mask | 1 << 1
elif toc_item == "kTocRawData":
toc_mask = toc_mask | long(1) << 3
toc_mask = toc_mask | 1 << 3
elif toc_item == "kTocDAQmxRawData":
toc_mask = toc_mask | long(1) << 7
toc_mask = toc_mask | 1 << 7
elif toc_item == "kTocInterleavedData":
toc_mask = toc_mask | long(1) << 5
toc_mask = toc_mask | 1 << 5
elif toc_item == "kTocBigEndian":
toc_mask = toc_mask | long(1) << 6
toc_mask = toc_mask | 1 << 6
elif toc_item == "kTocNewObjList":
toc_mask = toc_mask | long(1) << 2
toc_mask = toc_mask | 1 << 2
else:
raise ValueError("Unrecognised TOC value: %s" % toc_item)
lead_in += struct.pack('<i', toc_mask)
Expand Down
5 changes: 1 addition & 4 deletions nptdms/test/writer/test_tdms_segment.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""Test TdmsSegment"""

from collections import OrderedDict
from datetime import datetime
import pytest
try:
from collections import OrderedDict
except ImportError:
OrderedDict = dict
import numpy as np

from nptdms.writer import ChannelObject, TdmsSegment, read_properties_dict
Expand Down
22 changes: 2 additions & 20 deletions nptdms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
import logging
import time

try:
from collections import OrderedDict
except ImportError:
try:
# ordereddict available on pypi for Python < 2.7
from ordereddict import OrderedDict
except ImportError:
# Otherwise fall back on normal dict
OrderedDict = dict


def cached_property(func):
""" Wraps a method on a class to make it a property and caches the result the first time it is evaluated
Expand Down Expand Up @@ -44,21 +34,13 @@ def __init__(self, log, description):
def __enter__(self):
if not self._enabled:
return self
try:
self._start_time = time.perf_counter()
except AttributeError:
# Python < 3.3
self._start_time = time.clock()
self._start_time = time.perf_counter()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if not self._enabled:
return
try:
end_time = time.perf_counter()
except AttributeError:
# Python < 3.3
end_time = time.clock()
end_time = time.perf_counter()

elapsed_time = (end_time - self._start_time) * 1.0e3
self._log.info("{0}: Took {1} ms".format(self._description, elapsed_time))
21 changes: 4 additions & 17 deletions nptdms/writer.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
"""Module for writing TDMS files"""

try:
from collections import OrderedDict
except ImportError:
OrderedDict = dict
from collections import OrderedDict
from datetime import datetime
from io import UnsupportedOperation
import numpy as np
from nptdms.common import toc_properties, ObjectPath
from nptdms.types import *


try:
long
except NameError:
# Python 3
long = int
unicode = str


class TdmsWriter(object):
"""Writes to a TDMS file.
Expand Down Expand Up @@ -144,7 +133,7 @@ def leadin(self, toc, metadata_size):
leadin = []
leadin.append(Bytes(b'TDSm'))

toc_mask = long(0)
toc_mask = 0
for toc_flag in toc:
toc_mask = toc_mask | toc_properties[toc_flag]
leadin.append(Int32(toc_mask))
Expand Down Expand Up @@ -281,7 +270,7 @@ def _to_tdms_value(value):
return value
if isinstance(value, bool) or isinstance(value, np.bool_):
return Boolean(value)
if isinstance(value, (int, long)):
if isinstance(value, int):
return to_int_property_value(value)
if isinstance(value, float):
return DoubleFloat(value)
Expand All @@ -291,8 +280,6 @@ def _to_tdms_value(value):
return TimeStamp(value)
if isinstance(value, str):
return String(value)
if isinstance(value, unicode):
return String(value)
if isinstance(value, bytes):
return String(value)
raise TypeError("Unsupported property type for %r" % value)
Expand Down Expand Up @@ -372,7 +359,7 @@ def _to_np_array(data):


def _infer_dtype(data):
if data and isinstance(data[0], (int, long)):
if data and isinstance(data[0], int):
max_value = max(data)
min_value = min(data)
if max_value >= 2**63 and min_value >= 0:
Expand Down
14 changes: 0 additions & 14 deletions run_tests.sh

This file was deleted.

3 changes: 0 additions & 3 deletions setup.cfg

This file was deleted.

7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ def read_version():
'Development Status :: 4 - Beta',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Scientific/Engineering',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'Intended Audience :: Science/Research',
Expand All @@ -45,7 +43,6 @@ def read_version():
'pytest>=3.1.0',
'hypothesis',
'pytest-benchmark',
'mock<4.0;python_version<"3.4"',
'thermocouples_reference',
'scipy',
],
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,36,37,38,39},pycodestyle
envlist = py{37,38,39,310},pycodestyle

[pycodestyle]
max-line-length = 120
Expand Down

0 comments on commit c283ecb

Please sign in to comment.