Skip to content

Commit a8a08ed

Browse files
committed
Remove six and pkg_resources
Now that Python 2 support has ended they are no longer needed.
1 parent 5bae5ef commit a8a08ed

File tree

8 files changed

+19
-52
lines changed

8 files changed

+19
-52
lines changed

preditor/about_module.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
import textwrap
77

8-
import six
98
from future.utils import with_metaclass
109

1110
import preditor
@@ -52,11 +51,7 @@ def generate(cls, instance=None):
5251
text = plug.text()
5352
except Exception as error:
5453
text = "Error processing: {}".format(error)
55-
if six.PY3:
56-
text = textwrap.indent(text, cls.indent)
57-
else:
58-
text = ['{}{}'.format(cls.indent, line) for line in text.split('\n')]
59-
text = "\n".join(text)
54+
text = textwrap.indent(text, cls.indent)
6055

6156
# Build the output string including the version information if provided.
6257
if version is not None:

preditor/delayable_engine/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,13 @@
44
import warnings
55
import weakref
66
from collections import OrderedDict
7+
from collections.abc import MutableSet
78

8-
import six
99
from Qt import QtCompat
1010
from Qt.QtCore import QObject, QTimer, Signal
1111

1212
from .delayables import Delayable
1313

14-
try:
15-
from collections.abc import MutableSet
16-
except ImportError:
17-
# Due to the older versions of six installed by default with DCC's like
18-
# Maya 2020, we can't rely on six.moves.collections_abc, so handle
19-
# the py 2.7 import
20-
from collections import MutableSet
21-
2214

2315
# https://stackoverflow.com/a/7829569
2416
class OrderedSet(MutableSet):
@@ -108,7 +100,7 @@ def add_delayable(self, delayable):
108100
Raises:
109101
KeyError: A invalid key identifier string was passed.
110102
"""
111-
if isinstance(delayable, six.string_types):
103+
if isinstance(delayable, str):
112104
if delayable in self.delayables:
113105
# Don't replace the instance if a string is passed
114106
return
@@ -276,7 +268,7 @@ def remove_delayable(self, delayable):
276268
delayable (Delayable or str): A Delayable instance or the key identifier.
277269
Remove this delayable from the current documents if it was added.
278270
"""
279-
if isinstance(delayable, six.string_types):
271+
if isinstance(delayable, str):
280272
if delayable not in self.delayables:
281273
return
282274
delayable = self.delayables[delayable]

preditor/gui/group_tab_widget/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import re
55

6-
import six
76
from Qt.QtCore import Qt
87
from Qt.QtGui import QIcon
98
from Qt.QtWidgets import QHBoxLayout, QMessageBox, QToolButton, QWidget
@@ -104,7 +103,7 @@ def add_new_tab(self, group, title="Workbox", group_fmt=None):
104103
if isinstance(group, int):
105104
group_title = self.tabText(group)
106105
parent = self.widget(group)
107-
elif isinstance(group, six.string_types):
106+
elif isinstance(group, str):
108107
group_title = group
109108
index = self.index_for_text(group)
110109
if index != -1:

preditor/gui/level_buttons.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import types
55
from functools import partial
66

7-
import six
87
from Qt.QtGui import QIcon
98
from Qt.QtWidgets import QAction, QMenu, QToolButton
109

@@ -182,10 +181,7 @@ def setLevel(self, level):
182181
# Emit our signal
183182
self.level_changed.emit(level=level)
184183

185-
if six.PY3:
186-
root.setLevel = types.MethodType(setLevel, root)
187-
else:
188-
root.setLevel = types.MethodType(setLevel, root, type(root))
184+
root.setLevel = types.MethodType(setLevel, root)
189185

190186
return root
191187

preditor/gui/loggerwindow.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from functools import partial
1212

1313
import __main__
14-
import six
1514
from Qt import QtCompat, QtCore, QtWidgets
1615
from Qt.QtCore import QByteArray, Qt, QTimer, Signal, Slot
1716
from Qt.QtGui import QCursor, QFont, QIcon, QTextCursor
@@ -428,7 +427,7 @@ def workbox_for_name(cls, name, show=False, visible=False):
428427
workbox = logger.current_workbox()
429428

430429
# If name is a string, find first tab with that name
431-
elif isinstance(name, six.string_types):
430+
elif isinstance(name, str):
432431
split = name.split('/', 1)
433432
if len(split) < 2:
434433
return None
@@ -792,7 +791,7 @@ def recordPrefs(self, manual=False):
792791
'wordWrap': self.uiWordWrapACT.isChecked(),
793792
'clearBeforeRunning': self.uiClearBeforeRunningACT.isChecked(),
794793
'uiSelectTextACT': self.uiSelectTextACT.isChecked(),
795-
'toolbarStates': six.text_type(self.saveState().toHex(), 'utf-8'),
794+
'toolbarStates': str(self.saveState().toHex(), 'utf-8'),
796795
'consoleFont': self.console().font().toString(),
797796
'uiAutoSaveSettingssACT': self.uiAutoSaveSettingssACT.isChecked(),
798797
'uiAutoPromptACT': self.uiAutoPromptACT.isChecked(),

preditor/plugins.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import logging
44

5-
import six
6-
7-
if six.PY3:
8-
from importlib_metadata import EntryPoint, entry_points
9-
else:
10-
import pkg_resources
5+
from importlib_metadata import EntryPoint, entry_points
116

127
_logger = logging.getLogger(__name__)
138

@@ -109,12 +104,8 @@ def logging_handlers(self, name=None):
109104
@classmethod
110105
def iterator(cls, group=None, name=None):
111106
"""Iterates over the requested entry point yielding results."""
112-
if six.PY3:
113-
for ep in entry_points().select(group=group):
114-
yield ep
115-
else:
116-
for ep in pkg_resources.iter_entry_points(group, name=name):
117-
yield ep
107+
for ep in entry_points().select(group=group):
108+
yield ep
118109

119110
@classmethod
120111
def from_string(cls, value, name="", group=""):
@@ -123,8 +114,5 @@ def from_string(cls, value, name="", group=""):
123114
Example:
124115
cls = from_string("preditor.gui.errordialog:ErrorDialog")
125116
"""
126-
if six.PY3:
127-
ep = EntryPoint(name=name, value=value, group=group)
128-
else:
129-
ep = pkg_resources.EntryPoint(name, value)
117+
ep = EntryPoint(name=name, value=value, group=group)
130118
return ep.load()

preditor/scintilla/documenteditor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from contextlib import contextmanager
2020
from functools import partial
2121

22-
import six
2322
from PyQt5.Qsci import QsciScintilla
2423
from PyQt5.QtCore import QTextCodec
2524
from Qt import QtCompat
@@ -284,7 +283,7 @@ def commentToggle(self, doWhich=None):
284283
"""
285284

286285
# If called by 'triggered' signal, clear out passed argument.
287-
if not isinstance(doWhich, six.string_types):
286+
if not isinstance(doWhich, str):
288287
doWhich = None
289288

290289
comment, result = self.commentCheck()

tests/test_stream.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55

66
import pytest
7-
import six
87

98
from preditor.stream import STDERR, STDOUT, Director, Manager, install_to_std
109

@@ -16,13 +15,13 @@ def manager():
1615

1716
@pytest.fixture
1817
def stdout(manager):
19-
old_stream = six.StringIO()
18+
old_stream = io.StringIO()
2019
return Director(manager, "test_out", old_stream=old_stream)
2120

2221

2322
@pytest.fixture
2423
def stderr(manager):
25-
old_stream = six.StringIO()
24+
old_stream = io.StringIO()
2625
return Director(manager, "test_err", old_stream=old_stream)
2726

2827

@@ -75,8 +74,8 @@ def __getattribute__(self, name):
7574
# the name/encoding of the windows pythonw.exe default streams
7675
orig_stdout = sys.stdout
7776
orig_stderr = sys.stderr
78-
sys.stdout = NamedTextIOWrapper(six.BytesIO(), name='nul', encoding='cp1252')
79-
sys.stderr = NamedTextIOWrapper(six.BytesIO(), name='nul', encoding='cp1252')
77+
sys.stdout = NamedTextIOWrapper(io.BytesIO(), name='nul', encoding='cp1252')
78+
sys.stderr = NamedTextIOWrapper(io.BytesIO(), name='nul', encoding='cp1252')
8079
try:
8180
# Build a director here that will grab the nul streams
8281
# so we can check that they don't store them in .old_stream
@@ -196,8 +195,8 @@ def test_install_to_std():
196195
# restore the original FLO's so we don't break other tests.
197196
stdout = sys.stdout
198197
stderr = sys.stderr
199-
temp_out = six.StringIO()
200-
temp_err = six.StringIO()
198+
temp_out = io.StringIO()
199+
temp_err = io.StringIO()
201200
sys.stdout = temp_out
202201
sys.stderr = temp_err
203202
try:

0 commit comments

Comments
 (0)