Skip to content

Commit

Permalink
Merge pull request #94 from mrmundt/remove_under_py27
Browse files Browse the repository at this point in the history
Remove < Python 2.7 references + Replace _find_packages in setup.py
  • Loading branch information
jsiirola committed Mar 25, 2020
2 parents cf34c0a + 32597b6 commit ad6043c
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 191 deletions.
2 changes: 0 additions & 2 deletions pyutilib/component/app/tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

class Test(unittest.TestCase):

@unittest.skipIf(sys.version_info[:2] < (2, 6), "Skipping tests because configuration output is not guaranteed to be sorted") # yapf: disable
def test_app1a(self):
pyutilib.subprocess.run(sys.executable + " " + currdir + os.sep +
"app1a.py " + currdir)
self.assertFileEqualsBaseline(currdir + "config1.out",
currdir + "config1.txt")

@unittest.skipIf(sys.version_info[:2] < (2, 6), "Skipping tests because configuration output is not guaranteed to be sorted") # yapf: disable
def test_app1b(self):
pyutilib.subprocess.run(sys.executable + " " + currdir + os.sep +
"app1b.py " + currdir)
Expand Down
6 changes: 1 addition & 5 deletions pyutilib/component/config/plugin_ConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

__all__ = ['Configuration_ConfigParser']

import sys
import os.path
try:
from ordereddict import OrderedDict
Expand Down Expand Up @@ -58,10 +57,7 @@ def load(self, filename):

def save(self, filename, config, header=None):
"""Save configuration information to the specified file."""
if sys.version_info[:2] == (2, 6):
parser = _configParser(dict_type=OrderedDict)
else:
parser = _configParser()
parser = _configParser()
for (section, option, value) in config:
if not parser.has_section(section):
parser.add_section(section)
Expand Down
2 changes: 0 additions & 2 deletions pyutilib/component/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_load4(self):
except ConfigurationError:
pass

@unittest.skipIf(sys.version_info[:2] < (2, 6), "Skipping tests because configuration output is not guaranteed to be sorted") # yapf: disable
def test_load5(self):
"""Test load method"""
PluginGlobals.add_env("testing.config_loading")
Expand Down Expand Up @@ -149,7 +148,6 @@ def __init__(self):
PluginGlobals.remove_env(
"testing.config_loading", cleanup=True, singleton=False)

@unittest.skipIf(sys.version_info[:2] < (2, 6), "Skipping tests because configuration output is not guaranteed to be sorted") # yapf: disable
def test_save1(self):
"""Test save method"""
config = Configuration()
Expand Down
64 changes: 22 additions & 42 deletions pyutilib/math/numtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,28 @@
Definitions of mathematical constants
"""

import sys
import math

if sys.version_info < (2, 6):
""" Definition of infinity """
infinity = float(1e3000)
""" Definition of NaN """
nan = infinity / infinity

def is_nan(x):
"""
Returns true if the argument is a float and it does not equal itself
"""
return type(x) is float and x != x

def is_finite(val):
"""
Returns true if the argument is a float or int and it is not infinite or NaN
"""
return type(val) in (float, int) and val not in (infinity, -infinity,
nan)

else:
""" Definition of infinity """
infinity = float('inf')
""" Definition of NaN """
nan = infinity / infinity

def is_nan(x):
"""
Returns true if the argument is a float and it does not equal itself
"""
try:
return math.isnan(x)
except TypeError:
return False

def is_finite(x):
"""
Returns true if the argument is a float or int and it is not infinite or NaN
"""
try:
return not math.isinf(x)
except TypeError:
return False
""" Definition of infinity """
infinity = float('inf')
""" Definition of NaN """
nan = infinity / infinity

def is_nan(x):
"""
Returns true if the argument is a float and it does not equal itself
"""
try:
return math.isnan(x)
except TypeError:
return False

def is_finite(x):
"""
Returns true if the argument is a float or int and it is not infinite or NaN
"""
try:
return not math.isinf(x)
except TypeError:
return False
12 changes: 5 additions & 7 deletions pyutilib/misc/archivereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'GzipFileArchiveReader', 'BZ2FileArchiveReader']

import os
import sys
import tempfile
import shutil
import posixpath
Expand All @@ -23,12 +22,11 @@
tarfile_available = False
gzip_available = False
bz2_available = False
if sys.version_info[:2] >= (2, 6):
try:
import zipfile
zipfile_available = True
except:
pass
try:
import zipfile
zipfile_available = True
except:
pass
try:
import tarfile
tarfile_available = True
Expand Down
16 changes: 0 additions & 16 deletions pyutilib/misc/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,9 @@ def get_desired_chars_from_file(f, nchars, l=""):
return retBuf


if sys.version_info[:2] == (3, 2):
#
# This fixes a bug in Python 3.2's implementation of GzipFile.
#
class MyGzipFile(gzip.GzipFile):

def read1(self, n):
return self.read(n)


def open_possibly_compressed_file(filename):
if not os.path.exists(filename):
raise IOError("cannot find file `" + filename + "'")
if sys.version_info[:2] < (2, 6) and zipfile.is_zipfile(filename):
raise IOError("cannot unpack a ZIP file with Python %s" %
'.'.join(map(str, sys.version_info)))
try:
is_zipfile = zipfile.is_zipfile(filename)
except:
Expand All @@ -82,9 +69,6 @@ def open_possibly_compressed_file(filename):
elif filename.endswith('.gz'):
if sys.version_info < (3, 0):
return gzip.open(filename, "r")
elif sys.version_info[:2] == (3, 2):
return io.TextIOWrapper(
MyGzipFile(filename), encoding='utf-8', newline='')
else:
return io.TextIOWrapper(
gzip.open(filename, 'r'), encoding='utf-8', newline='')
Expand Down
2 changes: 0 additions & 2 deletions pyutilib/misc/tests/test_archivereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#

import os
import sys
import fnmatch
import posixpath

Expand Down Expand Up @@ -51,7 +50,6 @@ def test_ArchiveReaderFactory_zip(self):
os.path.join(testdatadir, 'archive_flat.zip'))
self.assertTrue(isinstance(archive, ZipArchiveReader))

#@unittest.skipIf(sys.version_info[:2] < (2,7), "Skipping due to bug in python 2.5 and 2.6")
def test_ArchiveReaderFactory_file(self):
archive = ArchiveReaderFactory(os.path.join(testdatadir, 'fileC.txt'))
self.assertTrue(isinstance(archive, FileArchiveReader))
Expand Down
6 changes: 1 addition & 5 deletions pyutilib/misc/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,7 @@ def test_generate_custom_documentation(self):
item_end= "endItem\n",
)

# re.sub(flags=) was introduced in 2.7
if sys.version_info[:2] < (2,7):
stripped_reference = re.sub('\{[^\}]*\}','',reference)
else:
stripped_reference = re.sub('\{[^\}]*\}','',reference,flags=re.M)
stripped_reference = re.sub('\{[^\}]*\}','',reference,flags=re.M)
#print(test)
self.assertEqual(test, stripped_reference)

Expand Down
6 changes: 0 additions & 6 deletions pyutilib/misc/tests/test_smap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#

import os
import sys
from os.path import abspath, dirname
currdir = dirname(abspath(__file__)) + os.sep
import pyutilib.th as unittest
Expand All @@ -13,11 +12,6 @@

class Test(unittest.TestCase):

def setUp(self):
if sys.version_info[:2] < (2, 6):
self.skipTest(
"SparseMapping not fully defined for Python 2.4 and 2.5")

def test1(self):
# Validate behavior for empty sparse map
smap = pyutilib.misc.SparseMapping()
Expand Down
18 changes: 7 additions & 11 deletions pyutilib/subprocess/processmngr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

_mswindows = sys.platform.startswith('win')

if sys.version_info[0:2] >= (2, 5):
if _mswindows:
import ctypes
if _mswindows:
import ctypes

# Note: on many python interpreters, WindowsError is only defined on
# Windows. Since we want to trap it below, we will declare a local
Expand Down Expand Up @@ -102,14 +101,11 @@ def kill_process(process, sig=signal.SIGTERM, verbose=False):
if GlobalData.debug or verbose:
print("Killing process %d with signal %d" % (pid, sig))
if _mswindows:
if sys.version_info[0:2] < (2, 5):
os.system("taskkill /t /f /pid " + repr(pid))
else:
PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE,
False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)
PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE,
False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)
else:
#
# Kill process and all its children
Expand Down
17 changes: 4 additions & 13 deletions pyutilib/th/pyunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@
import sys
import filecmp
import re
if sys.version_info[:2] < (2, 7):
try:
import unittest2 as unittest
main = unittest.main
using_unittest2 = True
except ImportError:
import unittest
main = unittest.main
using_unittest2 = False
else:
import unittest
using_unittest2 = True
main = unittest.main

import unittest
using_unittest2 = True
main = unittest.main

from six import iteritems, itervalues, PY2

Expand Down
Loading

0 comments on commit ad6043c

Please sign in to comment.