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

Remove six and require py38 and above #72

Merged
merged 2 commits into from
Oct 11, 2022
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ not provided by Python. Read the [documentation](https://tendo.readthedocs.org/e

## Requirements and compatibility

- python 3.6 or newer
- python 3.8 or newer
- tox for running tests

## Related projects and packages
Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ classifier =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
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
Expand All @@ -38,7 +36,7 @@ keywords =

[options]
use_scm_version = True
python_requires = >=3.6
python_requires = >=3.8
package_dir =
= src
packages = find:
Expand Down
4 changes: 2 additions & 2 deletions src/tendo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
'execfile2', 'singleton', 'ansiterm', '__version__')


if sys.hexversion < 0x02050000:
sys.exit("Python 2.5 or newer is required by tendo module.")
if sys.hexversion < 0x03080000:
sys.exit("Python 3.8 or newer is required by tendo module.")
6 changes: 2 additions & 4 deletions src/tendo/ansiterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ class CONSOLE_CURSOR_INFO(ctypes.Structure):
import re
import threading

from six import text_type

def to_int(number, default):
return number and int(number) or default
wlock = threading.Lock()

STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12

class AnsiTerm(object):
class AnsiTerm:

def __init__(self):
self.encoding = sys.stdout.encoding
Expand Down Expand Up @@ -254,7 +252,7 @@ def write(self, text):
cmd_func(self, param)
else:
chars_written = c_int()
if isinstance(txt, text_type):
if isinstance(txt, str):
windll.kernel32.WriteConsoleW(
self.hconsole, txt, len(txt), byref(chars_written), None)
else:
Expand Down
3 changes: 1 addition & 2 deletions src/tendo/colorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import copy
import logging
import os
import six
import sys


Expand Down Expand Up @@ -120,7 +119,7 @@ def new(*args):
color = '\x1b[0m' # normal
try:
new_args[
1].msg = color + six.text_type(new_args[1].msg) + '\x1b[0m' # normal
1].msg = color + str(new_args[1].msg) + '\x1b[0m' # normal
except Exception as e:
raise e
return fn(*new_args)
Expand Down
2 changes: 1 addition & 1 deletion src/tendo/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SingleInstanceException(BaseException):
pass


class SingleInstance(object):
class SingleInstance:

"""Class that can be instantiated only once per machine.

Expand Down
3 changes: 1 addition & 2 deletions src/tendo/tee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import os
import pipes
from six import string_types
import subprocess
import sys
import time
Expand Down Expand Up @@ -97,7 +96,7 @@ def nop(msg):

if not logger:
mylogger = nop
elif isinstance(logger, string_types):
elif isinstance(logger, str):
f = codecs.open(logger, "a+b", 'utf_8')
mylogger = filelogger
elif isinstance(logger, (types.FunctionType, types.MethodType, types.BuiltinFunctionType)):
Expand Down
2 changes: 1 addition & 1 deletion src/tendo/tests/test_colorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ def test_colorer():
expected_lines = ['WARNING: a warning\n', 'ERROR: some error\n', 'INFO: some info\n', 'DEBUG: some info\n']
line_no = 0
for line in open(tmp_file).readlines():
assert(line == expected_lines[line_no])
assert line == expected_lines[line_no]
line_no += 1
16 changes: 5 additions & 11 deletions src/tendo/tests/test_unicode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import inspect
import pytest
import tempfile
import six
import os
import filecmp
import shutil
from tendo.unicode import open


@pytest.fixture
Expand All @@ -14,10 +14,7 @@ def dir():


def test_read_utf8(dir):
if six.PY2:
mode = "rU"
else:
mode = "r"
mode = "r"
f = open(os.path.join(dir, "assets/utf8.txt"), mode)
f.readlines()
f.close()
Expand All @@ -26,10 +23,7 @@ def test_read_utf8(dir):

def test_read_invalid_utf8(dir):
with pytest.raises(UnicodeDecodeError):
if six.PY2:
mode = "rU"
else:
mode = "r"
mode = "r"
f = open(os.path.join(dir, "assets/utf8-invalid.txt"), mode)
f.readlines()
f.close()
Expand All @@ -39,8 +33,8 @@ def test_write_on_existing_utf8(dir):
(ftmp, fname_tmp) = tempfile.mkstemp()
shutil.copyfile(os.path.join(dir, "assets/utf8.txt"), fname_tmp)
f = open(fname_tmp, "a") # encoding not specified, should use utf-8
f.write(six.u(
"\u0061\u0062\u0063\u0219\u021B\u005F\u1E69\u0073\u0323\u0307\u0073\u0307\u0323\u005F\u0431\u0434\u0436\u005F\u03B1\u03B2\u03CE\u005F\u0648\u062A\u005F\u05D0\u05E1\u05DC\u005F\u6C38\U0002A6A5\u9EB5\U00020000"))
f.write(
"\u0061\u0062\u0063\u0219\u021B\u005F\u1E69\u0073\u0323\u0307\u0073\u0307\u0323\u005F\u0431\u0434\u0436\u005F\u03B1\u03B2\u03CE\u005F\u0648\u062A\u005F\u05D0\u05E1\u05DC\u005F\u6C38\U0002A6A5\u9EB5\U00020000")
f.close()
passed = filecmp.cmp(
os.path.join(dir, "assets/utf8-after-append.txt"), fname_tmp, shallow=False)
Expand Down
17 changes: 10 additions & 7 deletions src/tendo/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import sys

import six
"""
Author: Sorin Sbarnea

Expand All @@ -15,6 +14,10 @@
open_old = open


def b(s):
return s.encode("latin-1")


def open(filename, mode='r', bufsize=-1, fallback_encoding='utf_8'):
"""This replaces Python original function with an improved version that is Unicode aware.

Expand Down Expand Up @@ -46,24 +49,24 @@ def open(filename, mode='r', bufsize=-1, fallback_encoding='utf_8'):
aBuf = bytes(f.read(4))
f.close()
except Exception:
aBuf = six.b('')
if six.binary_type(aBuf[:3]) == six.b('\xEF\xBB\xBF'):
aBuf = b('')
if bytes(aBuf[:3]) == b('\xEF\xBB\xBF'):
f = codecs.open(filename, mode, "utf_8")
f.seek(3, 0)
f.BOM = codecs.BOM_UTF8
elif six.binary_type(aBuf[:2]) == six.b('\xFF\xFE'):
elif bytes(aBuf[:2]) == b('\xFF\xFE'):
f = codecs.open(filename, mode, "utf_16_le")
f.seek(2, 0)
f.BOM = codecs.BOM_UTF16_LE
elif six.binary_type(aBuf[:2]) == six.b('\xFE\xFF'):
elif bytes(aBuf[:2]) == b('\xFE\xFF'):
f = codecs.open(filename, mode, "utf_16_be")
f.seek(2, 0)
f.BOM = codecs.BOM_UTF16_BE
elif six.binary_type(aBuf[:4]) == six.b('\xFF\xFE\x00\x00'):
elif bytes(aBuf[:4]) == b('\xFF\xFE\x00\x00'):
f = codecs.open(filename, mode, "utf_32_le")
f.seek(4, 0)
f.BOM = codecs.BOM_UTF32_LE
elif six.binary_type(aBuf[:4]) == six.b('\x00\x00\xFE\xFF'):
elif bytes(aBuf[:4]) == b('\x00\x00\xFE\xFF'):
f = codecs.open(filename, mode, "utf_32_be")
f.seek(4, 0)
f.BOM = codecs.BOM_UTF32_BE
Expand Down