diff --git a/build.py b/build.py index 420df995..d6a926f4 100755 --- a/build.py +++ b/build.py @@ -53,10 +53,6 @@ from buildtools.config import Config, msg, opj, posixjoin, loadETG, etg2sip, fi import buildtools.version as version -# which version of Python is running this script -PY2 = sys.version_info[0] == 2 -PY3 = sys.version_info[0] == 3 - # defaults PYVER = '2.7' @@ -1086,7 +1082,7 @@ def _removeSidebar(path): tag = soup.find('div', 'document') if tag: tag.attrs['class'] = ['document-no-sidebar'] - text = unicode(soup) if PY2 else str(soup) + text = str(soup) with textfile_open(filename, 'wt') as f: f.write(text) @@ -1507,9 +1503,6 @@ def cmd_build_wx(options, args): if options.jom: build_options.append('--jom') - if PY2: - build_options.append('--no_dpi_aware') - else: # Platform is something other than MSW if options.osx_carbon: diff --git a/buildtools/build_wxwidgets.py b/buildtools/build_wxwidgets.py index f1d41d37..d21ea1b3 100644 --- a/buildtools/build_wxwidgets.py +++ b/buildtools/build_wxwidgets.py @@ -18,8 +18,6 @@ import subprocess from buildtools import builder from buildtools.config import getVisCVersion -PY3 = sys.version_info[0] == 3 - # builder object wxBuilder = None @@ -427,8 +425,7 @@ def main(wxDir, args): setupFile = os.path.join(mswIncludeDir, "setup.h") with open(setupFile, "rb") as f: setupText = f.read() - if PY3: - setupText = setupText.decode('utf-8') + setupText = setupText.decode('utf-8') for flag in flags: setupText, subsMade = re.subn(flag + r"\s+?\d", "%s %s" % (flag, flags[flag]), setupText) @@ -437,8 +434,7 @@ def main(wxDir, args): sys.exit(1) with open(setupFile, "wb") as f: - if PY3: - setupText = setupText.encode('utf-8') + setupText = setupText.encode('utf-8') f.write(setupText) args = [] diff --git a/buildtools/config.py b/buildtools/config.py index dda3c675..c3662ef4 100644 --- a/buildtools/config.py +++ b/buildtools/config.py @@ -485,18 +485,8 @@ class Configuration(object): def build_locale_list(self, srcdir): # get a list of all files under the srcdir, to be used for install_data - if sys.version_info[0] == 2: - def walk_helper(lst, dirname, files): - for f in files: - filename = opj(dirname, f) - if not os.path.isdir(filename): - lst.append( (dirname, [filename]) ) - file_list = [] - os.path.walk(srcdir, walk_helper, file_list) - return file_list - else: - # TODO: Python3 version using os.walk generator - return [] + # TODO: Python3 version using os.walk generator + return [] def find_data_files(self, srcdir, *wildcards, **kw): @@ -916,8 +906,7 @@ def runcmd(cmd, getOutput=False, echoCmd=True, fatal=True, onError=None): if getOutput: outputEncoding = 'cp1252' if sys.platform == 'win32' else 'utf-8' output = sp.stdout.read() - if sys.version_info > (3,): - output = output.decode(outputEncoding) + output = output.decode(outputEncoding) output = output.rstrip() rval = sp.wait() @@ -936,11 +925,8 @@ def runcmd(cmd, getOutput=False, echoCmd=True, fatal=True, onError=None): def myExecfile(filename, ns): - if sys.version_info < (3,): - execfile(filename, ns) - else: - with open(filename, 'r') as f: - exec(f.read(), ns) + with open(filename, 'r') as f: + exec(f.read(), ns) def textfile_open(filename, mode='rt'): @@ -950,12 +936,7 @@ def textfile_open(filename, mode='rt'): mode parameter must include the 't' to put the stream into text mode. """ assert 't' in mode - if sys.version_info < (3,): - import codecs - mode = mode.replace('t', '') - return codecs.open(filename, mode, encoding='utf-8') - else: - return open(filename, mode, encoding='utf-8') + return open(filename, mode, encoding='utf-8') def getSipFiles(names): diff --git a/buildtools/distutils_hacks.py b/buildtools/distutils_hacks.py index eafd5983..cbd4f958 100644 --- a/buildtools/distutils_hacks.py +++ b/buildtools/distutils_hacks.py @@ -315,7 +315,7 @@ distutils.cygwinccompiler.CygwinCCompiler._compile = _compile # into the .pyd files as expected. So we'll strip out that option via # a monkey-patch of the msvc9compiler.MSVCCompiler.initialize method. -if os.name == 'nt' and sys.version_info >= (2,6): +if os.name == 'nt': import distutils.msvc9compiler _orig_initialize = distutils.msvc9compiler.MSVCCompiler.initialize diff --git a/etg/rawbmp.py b/etg/rawbmp.py index 699c8d88..bc464456 100644 --- a/etg/rawbmp.py +++ b/etg/rawbmp.py @@ -122,13 +122,10 @@ def addPixelDataBaseClass(module): X = property(lambda self: x) Y = property(lambda self: y) - import sys - rangeFunc = range if sys.version_info >= (3,) else xrange - pf = PixelFacade() - for y in rangeFunc(height): + for y in range(height): pixels.MoveTo(self, 0, y) - for x in rangeFunc(width): + for x in range(width): # We always generate the same pf instance, but it # accesses the pixels object which we use to iterate # over the pixel buffer. diff --git a/etgtools/extractors.py b/etgtools/extractors.py index 047d159d..fcd762c4 100644 --- a/etgtools/extractors.py +++ b/etgtools/extractors.py @@ -33,7 +33,7 @@ else: # methods, functions and other items in the C/C++ API being wrapped. #--------------------------------------------------------------------------- -class BaseDef(object): +class BaseDef: """ The base class for all element types and provides the common attributes and functions that they all share. @@ -1698,11 +1698,7 @@ def flattenNode(node, rstrip=True): # TODO: can we just use ElementTree.tostring for this function? if node is None: return "" - if sys.version_info < (3,): - strclass = basestring - else: - strclass = str - if isinstance(node, strclass): + if isinstance(node, str): return node text = node.text or "" for n in node: diff --git a/etgtools/generators.py b/etgtools/generators.py index ba94a662..6723a460 100644 --- a/etgtools/generators.py +++ b/etgtools/generators.py @@ -100,13 +100,7 @@ def wrapText(text, dontWrap: str = ''): # in the StringIO import io class Utf8EncodingStream(io.StringIO): - if sys.version_info < (3,): - def write(self, text): - if isinstance(text, str): - text = text.decode('utf-8') - return io.StringIO.write(self, text) - - + pass def textfile_open(filename, mode='rt'): @@ -116,12 +110,7 @@ def textfile_open(filename, mode='rt'): mode parameter must include the 't' to put the stream into text mode. """ assert 't' in mode - if sys.version_info < (3,): - import codecs - mode = mode.replace('t', '') - return codecs.open(filename, mode, encoding='utf-8') - else: - return open(filename, mode, encoding='utf-8') + return open(filename, mode, encoding='utf-8') #--------------------------------------------------------------------------- diff --git a/etgtools/sphinx_generator.py b/etgtools/sphinx_generator.py index 88591dba..b64ae2f3 100644 --- a/etgtools/sphinx_generator.py +++ b/etgtools/sphinx_generator.py @@ -20,12 +20,7 @@ import sys import shutil import textwrap -if sys.version_info < (3, ): - from StringIO import StringIO - string_base = basestring -else: - from io import StringIO - string_base = str +from io import StringIO import xml.etree.ElementTree as et @@ -146,7 +141,7 @@ class Node(object): :returns: The element text for the input `tag_name` or ``None``. """ - if isinstance(self.element, string_base): + if isinstance(self.element, str): return None return self.element.get(tag_name) @@ -268,7 +263,7 @@ class Node(object): if self.element is None: return text - if isinstance(self.element, string_base): + if isinstance(self.element, str): text = self.element else: text, tail = self.element.text, self.element.tail @@ -1381,7 +1376,7 @@ class Snippet(Node): if tag == 'sp': self.snippet += ' ' - if isinstance(element, string_base): + if isinstance(element, str): self.snippet += element else: if element.text: @@ -2006,7 +2001,7 @@ class XMLDocString(object): # Some of the Extractors (xml item) will set deprecated themselves, in which case it is set as a # non-empty string. In such cases, this branch will insert a deprecated section into the xml tree # so that the Node Tree (see classes above) will generate the deprecated tag on their own in self.RecurseXML - if hasattr(xml_item, 'deprecated') and xml_item.deprecated and isinstance(xml_item.deprecated, string_base): + if hasattr(xml_item, 'deprecated') and xml_item.deprecated and isinstance(xml_item.deprecated, str): element = et.Element('deprecated', kind='deprecated') element.text = xml_item.deprecated @@ -2128,7 +2123,7 @@ class XMLDocString(object): if element is None: return Node('', parent) - if isinstance(element, string_base): + if isinstance(element, str): rest_class = Paragraph(element, parent, self.kind) return rest_class @@ -2754,7 +2749,7 @@ class XMLDocString(object): name = convertToPython(name) stream.write('%-80s' % name) - if not isinstance(docstrings, string_base): + if not isinstance(docstrings, str): rest_class = self.RecurseXML(docstrings, self.root) docstrings = rest_class.Join() @@ -3394,7 +3389,7 @@ class SphinxGenerator(generators.DocsGeneratorBase): brief = memberVar.briefDoc briefDoc = None - if not isinstance(brief, string_base): + if not isinstance(brief, str): docstring = XMLDocString(memberVar) #docstring.current_module = self.current_module briefDoc = docstring.GetBrief() @@ -3541,7 +3536,7 @@ class SphinxGenerator(generators.DocsGeneratorBase): simple_docs = convertToPython(method.pyDocstring) else: brief = method.briefDoc - if not isinstance(brief, string_base): + if not isinstance(brief, str): docstring = XMLDocString(method) docstring.kind = 'method' docstring.current_module = self.current_module diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index 663bc0d9..dc4fca43 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -22,7 +22,6 @@ import textwrap from typing import Optional, Tuple -PY3 = sys.version_info[0] == 3 isWindows = sys.platform.startswith('win') magicMethods = { @@ -131,12 +130,8 @@ class FixWxPrefix(object): names = list() filename = 'wx/core.pyi' - if PY3: - with open(filename, 'rt', encoding='utf-8') as f: - text = f.read() - else: - with open(filename, 'r') as f: - text = f.read() + with open(filename, 'rt', encoding='utf-8') as f: + text = f.read() parseTree = ast.parse(text, filename) for item in parseTree.body: _processItem(item, names) diff --git a/packaging/setup.py b/packaging/setup.py index ef1b6c7b..5e82beea 100644 --- a/packaging/setup.py +++ b/packaging/setup.py @@ -15,7 +15,7 @@ # folder, so let's accommodate them... #--------------------------------------------------------------------------- -import sys, os, glob +import os, glob # Restructure the content of the tarball so things like pip or easy_install # know how to build stuff. To be compatible with those tools the main source @@ -39,10 +39,7 @@ for wc in ['wxWidgets/configure', # Now execute the real setup.py that was copied here in order to do whatever # command was trying to be done before. -if sys.version_info < (3,): - execfile('setup.py') -else: - with open('setup.py', 'r') as f: - source = f.read() - exec(source) +with open('setup.py', 'r') as f: + source = f.read() +exec(source) diff --git a/sphinxtools/inheritance.py b/sphinxtools/inheritance.py index acd7a803..18704ed3 100644 --- a/sphinxtools/inheritance.py +++ b/sphinxtools/inheritance.py @@ -24,13 +24,9 @@ from .constants import INHERITANCEROOT ENOENT = getattr(errno, 'ENOENT', 0) EPIPE = getattr(errno, 'EPIPE', 0) -if sys.version_info < (3, ): - string_base = basestring -else: - string_base = str -class InheritanceDiagram(object): +class InheritanceDiagram: """ Given a list of classes, determines the set of classes that they inherit from all the way to the root "object", and then is able to generate a @@ -239,7 +235,7 @@ class InheritanceDiagram(object): code = self.generate_dot(class_summary) # graphviz expects UTF-8 by default - if isinstance(code, string_base): + if isinstance(code, str): code = code.encode('utf-8') dot_args = ['dot'] diff --git a/sphinxtools/librarydescription.py b/sphinxtools/librarydescription.py index 56d48134..6fa28706 100644 --- a/sphinxtools/librarydescription.py +++ b/sphinxtools/librarydescription.py @@ -1,25 +1,17 @@ import sys import os import re - -if sys.version_info < (3,): - from StringIO import StringIO -else: - from io import StringIO +from io import StringIO from inspect import getmro, getclasstree, getdoc, getcomments from .utilities import makeSummary, chopDescription, writeSphinxOutput, PickleFile -from .utilities import findControlImages, formatExternalLink, isPython3 +from .utilities import findControlImages, formatExternalLink from .constants import object_types, MODULE_TO_ICON, DOXY_2_REST, SPHINXROOT from . import templates EPYDOC_PATTERN = re.compile(r'\S+{\S+}', re.DOTALL) -if sys.version_info < (3,): - reload(sys) - sys.setdefaultencoding('utf-8') - def make_class_tree(tree): @@ -1016,12 +1008,7 @@ class Property(ChildrenBase): class Attribute(ChildrenBase): def __init__(self, name, specs, value): - - if isPython3(): - specs = str(specs) - else: - specs = unicode(specs) - + specs = str(specs) start, end = specs.find("'"), specs.rfind("'") specs = specs[start+1:end] diff --git a/sphinxtools/modulehunter.py b/sphinxtools/modulehunter.py index f53ad678..7626614a 100644 --- a/sphinxtools/modulehunter.py +++ b/sphinxtools/modulehunter.py @@ -148,10 +148,7 @@ def analyze_params(obj, signature): pvalue = pvalue.strip() if pname in pevals: try: - if isPython3(): - peval = str(pevals[pname]) - else: - peval = unicode(pevals[pname]) + peval = str(pevals[pname]) except UnicodeDecodeError: peval = repr(pevals[pname]) except TypeError: @@ -216,7 +213,7 @@ def inspect_source(method_class, obj, source): def is_classmethod(instancemethod): """ Determine if an instancemethod is a classmethod. """ - # attribute = (isPython3() and ['__self__'] or ['im_self'])[0] + # attribute = (['__self__'] or ['im_self'])[0] # if hasattr(instancemethod, attribute): # return getattr(instancemethod, attribute) is not None # return False @@ -284,20 +281,11 @@ def describe_func(obj, parent_class, module_name): try: code = None if method in [object_types.METHOD, object_types.METHOD_DESCRIPTOR, object_types.INSTANCE_METHOD]: - if isPython3(): - code = obj.__func__.__code__ - else: - code = obj.im_func.func_code + code = obj.__func__.__code__ elif method == object_types.STATIC_METHOD: - if isPython3(): - code = obj.__func__.__code__ - else: - code = obj.im_func.func_code + code = obj.__func__.__code__ else: - if isPython3(): - code = obj.__code__ - else: - code = obj.func_code + code = obj.__code__ except AttributeError: code = None diff --git a/sphinxtools/postprocess.py b/sphinxtools/postprocess.py index 65d82512..0c66051d 100644 --- a/sphinxtools/postprocess.py +++ b/sphinxtools/postprocess.py @@ -25,9 +25,6 @@ from .constants import HTML_REPLACE, TODAY, SPHINXROOT, SECTIONS_EXCLUDE from .constants import CONSTANT_INSTANCES, WIDGETS_IMAGES_ROOT, SPHINX_IMAGES_ROOT from .constants import DOCSTRING_KEY -PY2 = sys.version_info[0] == 2 -PY3 = sys.version_info[0] == 3 - # ----------------------------------------------------------------------- # @@ -750,7 +747,7 @@ def removeHeaderImage(text, options): tag = soup.find('div', 'headerimage') if tag: tag.extract() - text = unicode(soup) if PY2 else str(soup) + text = str(soup) return text @@ -762,7 +759,7 @@ def tweakModuleIndex(text): href = tag['href'].split('.html#') if len(href) == 2 and href[0] == href[1]: tag['href'] = href[0] + '.html' - return unicode(soup) if PY2 else str(soup) + return str(soup) def tooltipsOnInheritance(text, class_summary): diff --git a/sphinxtools/utilities.py b/sphinxtools/utilities.py index d330bd49..1662aa34 100644 --- a/sphinxtools/utilities.py +++ b/sphinxtools/utilities.py @@ -16,14 +16,8 @@ import codecs import shutil import re -if sys.version_info < (3,): - import cPickle as pickle - from UserDict import UserDict - string_base = basestring -else: - import pickle - from collections import UserDict - string_base = str +import pickle +from collections import UserDict # Phoenix-specific imports from .templates import TEMPLATE_CONTRIB @@ -448,7 +442,7 @@ def findControlImages(elementOrString): """ from etgtools.tweaker_tools import removeWxPrefix - if isinstance(elementOrString, string_base): + if isinstance(elementOrString, str): class_name = py_class_name = elementOrString.lower() else: element = elementOrString @@ -860,12 +854,6 @@ def formatExternalLink(fullname, inheritance=False): return full_page -def isPython3(): - """ Returns ``True`` if we are using Python 3.x. """ - - return sys.version_info >= (3, ) - - def textfile_open(filename, mode='rt'): """ Simple wrapper around open() that will use codecs.open on Python2 and @@ -873,9 +861,4 @@ def textfile_open(filename, mode='rt'): mode parameter must include the 't' to put the stream into text mode. """ assert 't' in mode - if sys.version_info < (3,): - import codecs - mode = mode.replace('t', '') - return codecs.open(filename, mode, encoding='utf-8') - else: - return open(filename, mode, encoding='utf-8') + return open(filename, mode, encoding='utf-8') diff --git a/wx/lib/activexwrapper.py b/wx/lib/activexwrapper.py index bd1e4c21..d795d80d 100644 --- a/wx/lib/activexwrapper.py +++ b/wx/lib/activexwrapper.py @@ -24,7 +24,7 @@ except ImportError: if hasattr(sys, "frozen"): import os, win32api dllpath = os.path.join(win32api.GetSystemDirectory(), 'MFC71.DLL') - if sys.version[:3] >= '2.4' and not os.path.exists(dllpath): + if not os.path.exists(dllpath): message = "%s not found" % dllpath else: raise # original error message diff --git a/wx/lib/agw/aui/aui_constants.py b/wx/lib/agw/aui/aui_constants.py index b7add75d..fc499010 100644 --- a/wx/lib/agw/aui/aui_constants.py +++ b/wx/lib/agw/aui/aui_constants.py @@ -2594,16 +2594,7 @@ SWITCHER_TEXT_MARGIN_Y = 1 if __name__ == '__main__': # Easy image extraction. import sys - if sys.version_info[0] == 2: - PY2 = True - PY3 = False - elif sys.version_info[0] == 3: - PY2 = False - PY3 = True - if PY2: - answer = int(raw_input('Enter 1 to extract all bitmaps: ')) - elif PY3: - answer = int(input('Enter 1 to extract all bitmaps: ')) + answer = int(input('Enter 1 to extract all bitmaps: ')) if answer == 1: app = wx.App(0) import os @@ -2622,7 +2613,4 @@ if __name__ == '__main__': except Exception: pass app.MainLoop() - if PY2: - raw_input('Press Enter To Exit.') - elif PY3: - input('Press Enter To Exit.') \ No newline at end of file + input('Press Enter To Exit.') diff --git a/wx/py/sliceshell.py b/wx/py/sliceshell.py index f2d57936..dcfb918a 100755 --- a/wx/py/sliceshell.py +++ b/wx/py/sliceshell.py @@ -1008,12 +1008,9 @@ class SlicesShell(editwindow.EditWindow): """Execute the user's PYTHONSTARTUP script if they have one.""" if startupScript and os.path.isfile(startupScript): text = 'Startup script executed: ' + startupScript - if PY3: - self.push('print(%r)' % text) - self.push('with open(%r, "r") as f:\n' - ' exec(f.read())\n' % (startupScript)) - else: - self.push('print(%r); execfile(%r)' % (text, startupScript)) + self.push('print(%r)' % text) + self.push('with open(%r, "r") as f:\n' + ' exec(f.read())\n' % (startupScript)) self.interp.startupScript = startupScript else: self.push('') diff --git a/wx/py/tests/test_introspect.py b/wx/py/tests/test_introspect.py index 9c2f9775..87804e4b 100644 --- a/wx/py/tests/test_introspect.py +++ b/wx/py/tests/test_introspect.py @@ -8,8 +8,6 @@ import os import unittest from wx.py import introspect -PY3 = sys.version_info[0] == 3 - """ These unittest methods are preferred: ------------------------------------- @@ -394,21 +392,6 @@ class GetBaseObjectTestCase(unittest.TestCase): # Class with no init. (Bar, Bar, 0), ] - if not PY3: - values.extend([ - # Byte-compiled code. - (ham.func_code, ham.func_code, 0), - # Class with init. - (Foo, Foo.__init__.im_func, 1), - # Bound method. - (spam.foo, spam.foo.im_func, 1), - # Bound method with self named something else (spam). - (spam.bar, spam.bar.im_func, 1), - # Unbound method. (Do not drop the self argument.) - (eggs, eggs.im_func, 0), - # Callable instance. - (spam, spam.__call__.im_func, 1), - ]) for object, baseObject, dropSelf in values: result = introspect.getBaseObject(object) self.assertEqual(result, (baseObject, dropSelf)) @@ -674,16 +657,6 @@ class GetAttributeNamesTestCase(GetAttributeTestCase): # BrokenStr instance. brokenStr, ] - if not PY3: - self.items.extend([ - long(123), - unicode(""), - xrange(0), - # Byte-compiled code. - ham.func_code, - # Buffer. - buffer(''), - ]) def tearDown(self): self.items = None @@ -829,34 +802,11 @@ class Q(P): class GetConstructorTestCase(unittest.TestCase): - @unittest.skipIf(PY3, "Python2 specific test") - def test_getConstructor(self): - args = ('self', 'a', 'b', 'args', 'kwargs') - varnames = introspect.getConstructor(O).func_code.co_varnames - self.assertEqual(varnames, args) - varnames = introspect.getConstructor(P).func_code.co_varnames - self.assertEqual(varnames, args) - args = ('self', 'c', 'd') - varnames = introspect.getConstructor(Q).func_code.co_varnames - self.assertEqual(varnames, args) - def test_getConstructor_None(self): values = (N, 1, 'spam', {}, [], (), dir) for value in values: self.assertEqual(introspect.getConstructor(N), None) - @unittest.skipIf(PY3, "Python2 specific test") - def test_getConstructor_MultipleInheritance(self): - # Test old style inheritance rules. - args = ('self', 'a') - varnames = introspect.getConstructor(D1).func_code.co_varnames - self.assertEqual(varnames, args) - if 'object' in __builtins__: - # Test new style inheritance rules as well. - args = ('self', 'b') - varnames = introspect.getConstructor(D2).func_code.co_varnames - self.assertEqual(varnames, args) - if __name__ == '__main__': unittest.main() diff --git a/wx/svg/_nanosvg.pyx b/wx/svg/_nanosvg.pyx index d1cae1aa..3dbb1adb 100644 --- a/wx/svg/_nanosvg.pyx +++ b/wx/svg/_nanosvg.pyx @@ -46,8 +46,6 @@ from cpython.buffer cimport ( Py_buffer, PyObject_CheckBuffer, PyObject_GetBuffer, PyBUF_SIMPLE, PyBuffer_Release) -PY2 = sys.version_info[0] == 2 - #---------------------------------------------------------------------------- # Replicate the C enums and values for Python, dropping the leading 'N' diff --git a/wx/tools/img2py.py b/wx/tools/img2py.py index 258e72c7..f848b446 100644 --- a/wx/tools/img2py.py +++ b/wx/tools/img2py.py @@ -198,10 +198,7 @@ def img2py(image_file, python_file, while data: part = data[:72] data = data[72:] - if sys.version > '3': - output = ' %s' % part - else: - output = ' "%s"' % part + output = ' %s' % part if not data: output += ")" lines.append(output)