Finally break ties with python2
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 2 Oct 2018 08:35:06 +0000 (10:35 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 8 Oct 2018 07:29:02 +0000 (09:29 +0200)
13 files changed:
README
make_dist.sh
run_unittests.sh
setup.py
src/cnfvar.py
src/text_helpers.py
src/type_helpers.py
templates/template.py
templates/test_template.py
test/test_buffer.py
test/test_log_read.py
test/test_text_helpers.py
test/test_type_helpers.py

diff --git a/README b/README
index 58ae1a0..b815c4c 100644 (file)
--- 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.
index 9cbc60e..e24e841 100755 (executable)
@@ -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/
index 5d54a24..bb662e2 100755 (executable)
@@ -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 <info@intra2net.com>
 
-python2 -m unittest discover test && python3 -m unittest discover test
+python3 -m unittest discover test
index 79c2766..863e765 100644 (file)
--- 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",
+      ],
      )
index af95c04..02ec34e 100644 (file)
@@ -100,8 +100,6 @@ implementation
 -------------------------------------------------------------------------------
 """
 
-from __future__ import print_function
-
 import functools
 import sys
 import json
index 987e56f..668dd8b 100644 (file)
@@ -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
index 123f5a4..eb74968 100644 (file)
 
 """
 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)
index a15d052..65b25ea 100644 (file)
@@ -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."""
 
index cf9bb63..51d29f1 100644 (file)
@@ -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
index 82a8ad6..084e2bc 100644 (file)
@@ -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
 
index 3e89fb4..951b4c7 100644 (file)
@@ -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
index ef03c7c..66b4d5d 100644 (file)
@@ -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 *
index 731a3ab..c9cb289 100644 (file)
@@ -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