From 2b141a0a49f0c4c7782f48454829c212787f0819 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 2 Oct 2018 10:35:06 +0200 Subject: [PATCH] Finally break ties with python2 --- README | 2 ++ make_dist.sh | 1 - run_unittests.sh | 4 ++-- setup.py | 4 ++++ src/cnfvar.py | 2 -- src/text_helpers.py | 2 -- src/type_helpers.py | 41 ++++------------------------------------- templates/template.py | 2 -- templates/test_template.py | 3 --- test/test_buffer.py | 2 -- test/test_log_read.py | 2 -- test/test_text_helpers.py | 2 -- test/test_type_helpers.py | 2 -- 13 files changed, 12 insertions(+), 57 deletions(-) diff --git a/README b/README index 58ae1a0..b815c4c 100644 --- a/README +++ b/README @@ -1,5 +1,7 @@ Library of common python code for Intra2net +Target: python3.3+ + To create a source tar.gz and spec file, run ./make_dist.sh This uses python distutils with info in setup.py. diff --git a/make_dist.sh b/make_dist.sh index 9cbc60e..e24e841 100755 --- a/make_dist.sh +++ b/make_dist.sh @@ -33,6 +33,5 @@ cat dist/pyi2ncommon.spec >> ./pyi2ncommon.spec echo "" >> ./pyi2ncommon.spec echo "%check" >> ./pyi2ncommon.spec #echo "echo \"unittests disabled for now...\"" >> ./pyi2ncommon.spec -echo "PYTHONPATH=./src:\$PYTHONPATH && python2 -m unittest discover test" >> ./pyi2ncommon.spec echo "PYTHONPATH=./src:\$PYTHONPATH && python3 -m unittest discover test" >> ./pyi2ncommon.spec mv ./pyi2ncommon.spec dist/ diff --git a/run_unittests.sh b/run_unittests.sh index 5d54a24..bb662e2 100755 --- a/run_unittests.sh +++ b/run_unittests.sh @@ -1,6 +1,6 @@ #!/bin/sh -# run unittest suite using python2 and python3 +# run unittest suite using python3 # The software in this package is distributed under the GNU General # Public License version 2 (with a special exception described below). @@ -22,4 +22,4 @@ # # Copyright (c) 2016-2018 Intra2net AG -python2 -m unittest discover test && python3 -m unittest discover test +python3 -m unittest discover test diff --git a/setup.py b/setup.py index 79c2766..863e765 100644 --- a/setup.py +++ b/setup.py @@ -41,4 +41,8 @@ setup(name='pyi2ncommon', # 'doc/index.rst', 'doc/modules.rst', 'doc/conf.py', # 'doc/about_docu.rst'], license='GPLv2 + linking exception', + classifiers=[ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + ], ) diff --git a/src/cnfvar.py b/src/cnfvar.py index af95c04..02ec34e 100644 --- a/src/cnfvar.py +++ b/src/cnfvar.py @@ -100,8 +100,6 @@ implementation ------------------------------------------------------------------------------- """ -from __future__ import print_function - import functools import sys import json diff --git a/src/text_helpers.py b/src/text_helpers.py index 987e56f..668dd8b 100644 --- a/src/text_helpers.py +++ b/src/text_helpers.py @@ -35,8 +35,6 @@ References: * https://en.wikipedia.org/wiki/ANSI_escape_code """ -from __future__ import print_function - try: from builtins import print as _builtin_print except ImportError: # different name in py2 diff --git a/src/type_helpers.py b/src/type_helpers.py index 123f5a4..eb74968 100644 --- a/src/type_helpers.py +++ b/src/type_helpers.py @@ -20,18 +20,11 @@ """ Helpers for type checking and conversion, like isstr(x), is_file_obj(x) - -Provides abstraction from difference between PY2 and PY3 """ -from __future__ import print_function import sys from io import IOBase -# determine python version -PY3 = sys.version_info.major == 3 -PY2 = sys.version_info.major == 2 - def isstr(var): """ determines if the given var is a (regular/unicode/raw) string or not @@ -48,18 +41,12 @@ def isstr(var): (https://pythonhosted.org/six) """ - if PY3: - return isinstance(var, str) - else: - return isinstance(var, basestring) + return isinstance(var, str) def is_str_or_byte(var): """ returns true for str, unicode and byte objects """ - if PY3: - return isinstance(var, (str, bytes)) - else: - return isinstance(var, basestring) + return isinstance(var, (str, bytes)) def is_unicode(var): @@ -68,11 +55,7 @@ def is_unicode(var): py2: return True for type unicode but not type str py3: return True for type str but not type bytes """ - - if PY2: - return isinstance(var, unicode) - else: - return isinstance(var, str) + return isinstance(var, str) def is_file_obj(var): @@ -81,20 +64,4 @@ def is_file_obj(var): just checks whether given var is subclass of io.IOBase, which is also True for 'file-like objects' like StringIO """ - return isinstance(var, IOBase) or (PY2 and isinstance(var, file)) - - -def main(): - """ Main function, called when running file as script - - just tells you what python version you are running (2 or 3) - """ - if PY3: - print('is python3') - else: - print('is python2') -# end: function main - - -if __name__ == '__main__': - main() + return isinstance(var, IOBase) diff --git a/templates/template.py b/templates/template.py index a15d052..65b25ea 100644 --- a/templates/template.py +++ b/templates/template.py @@ -38,8 +38,6 @@ inside code comments (except maybe for third-party contributions). .. warning:: This is a warning """ -from __future__ import print_function - THE_CONSTANT = None """Some constant with docstring *AFTER* the constant.""" diff --git a/templates/test_template.py b/templates/test_template.py index cf9bb63..51d29f1 100644 --- a/templates/test_template.py +++ b/templates/test_template.py @@ -27,9 +27,6 @@ Should be able run from python2 and python3! For help see :py:mod:`unittest` """ -from __future__ import print_function -from __future__ import absolute_import - import unittest # relative import of tested module ensures we do not test installed version diff --git a/test/test_buffer.py b/test/test_buffer.py index 82a8ad6..084e2bc 100644 --- a/test/test_buffer.py +++ b/test/test_buffer.py @@ -27,8 +27,6 @@ Should be able run from python2 and python3! For help see :py:mod:`unittest` """ -from __future__ import absolute_import - import unittest from math import log, floor diff --git a/test/test_log_read.py b/test/test_log_read.py index 3e89fb4..951b4c7 100644 --- a/test/test_log_read.py +++ b/test/test_log_read.py @@ -23,8 +23,6 @@ Creates own thread to write data to a log file """ -from __future__ import absolute_import - import unittest from threading import Thread from tempfile import mkstemp diff --git a/test/test_text_helpers.py b/test/test_text_helpers.py index ef03c7c..66b4d5d 100644 --- a/test/test_text_helpers.py +++ b/test/test_text_helpers.py @@ -27,8 +27,6 @@ Should be able run from python2 and python3! For help see :py:mod:`unittest` """ -from __future__ import absolute_import - import unittest from src.text_helpers import * diff --git a/test/test_type_helpers.py b/test/test_type_helpers.py index 731a3ab..c9cb289 100644 --- a/test/test_type_helpers.py +++ b/test/test_type_helpers.py @@ -27,8 +27,6 @@ Should be run from python2 and python3! For help see :py:mod:`unittest` """ -from __future__ import absolute_import - import unittest from src.type_helpers import is_unicode, isstr -- 1.7.1