Skip to content

Commit

Permalink
Remove all use of six from codebase (#464)
Browse files Browse the repository at this point in the history
* remove all use of six from codebase

* remove six as a dependency

* fix failing test
  • Loading branch information
aaronayres35 authored Dec 4, 2020
1 parent af9c914 commit 130fb11
Show file tree
Hide file tree
Showing 54 changed files with 117 additions and 208 deletions.
1 change: 0 additions & 1 deletion ci/edmtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@

dependencies = {
"apptools",
"six",
"nose",
"coverage",
"numpy",
Expand Down
1 change: 0 additions & 1 deletion enable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'traits',
'traitsui',
'pyface',
'six',
'fonttools'
]

Expand Down
8 changes: 4 additions & 4 deletions enable/abstract_window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import reduce

# Major library imports
import six.moves as sm
from numpy import dot

# Enthought library imports
Expand Down Expand Up @@ -137,7 +137,7 @@ def _init_gc(self):
gc.clear(self.bgcolor_)
else:
# Fixme: should use clip_to_rects
update_union = sm.reduce(union_bounds, self._update_region)
update_union = reduce(union_bounds, self._update_region)
gc.clip_to_rect(*update_union)
return

Expand Down Expand Up @@ -268,7 +268,7 @@ def _handle_key_event(self, event_type, event):
if history is not None and len(history) > 0:
# Assemble all the transforms
transforms = [c.get_event_transform() for c in history]
total_transform = sm.reduce(dot, transforms[::-1])
total_transform = reduce(dot, transforms[::-1])
key_event.push_transform(total_transform)
elif self.mouse_owner_transform is not None:
key_event.push_transform(self.mouse_owner_transform)
Expand Down Expand Up @@ -317,7 +317,7 @@ def _handle_mouse_event(self, event_name, event, set_focus=False):
if history is not None and len(history) > 0:
# Assemble all the transforms
transforms = [c.get_event_transform() for c in history]
total_transform = sm.reduce(dot, transforms[::-1])
total_transform = reduce(dot, transforms[::-1])
mouse_event.push_transform(total_transform)
elif self.mouse_owner_transform is not None:
mouse_event.push_transform(self.mouse_owner_transform)
Expand Down
5 changes: 1 addition & 4 deletions enable/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
# subclasses_of
#-------------------------------------------------------------------------------

# Major library imports
import six.moves as sm

# Enthought library imports
from traits.api import TraitError

Expand Down Expand Up @@ -238,7 +235,7 @@ def send_event_to ( components, event_name, event ):
setattr( component, pre_event_name, event )
if event.handled:
return len( components )
for i in sm.range( len( components ) - 1, -1, -1 ):
for i in range( len( components ) - 1, -1, -1 ):
setattr( components[i], event_name, event )
if event.handled:
return i
Expand Down
8 changes: 3 additions & 5 deletions enable/constraints_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#------------------------------------------------------------------------------
from collections import deque

import six

# traits imports
from traits.api import Any, Bool, Callable, Dict, Either, Instance, List, \
Property
Expand Down Expand Up @@ -245,7 +243,7 @@ def __components_changed(self, new):
""" Make sure components that are added can be used with constraints.
"""
# Clear the component maps
for key, item in six.iteritems(self._component_map):
for key, item in self._component_map.items():
item.on_trait_change(self._component_size_hint_changed,
'layout_size_hint', remove=True)
self._component_map = {}
Expand Down Expand Up @@ -295,7 +293,7 @@ def _build_layout_table(self):
zero_offset = (0, 0)
offset_table = [zero_offset]
layout_table = []
queue = deque((0, child) for child in six.itervalues(self._component_map))
queue = deque((0, child) for child in self._component_map.values())

# Micro-optimization: pre-fetch bound methods and store globals
# as locals. This method is not on the code path of a resize
Expand Down Expand Up @@ -323,7 +321,7 @@ def _build_layout_table(self):
running_index += 1
if isinst(item, Container_):
if item.transfer_layout_ownership(self):
for child in six.itervalues(item._component_map):
for child in item._component_map.values():
push((running_index, child))

return offset_table, layout_table
Expand Down
7 changes: 2 additions & 5 deletions enable/coordinate_box.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

import six

# Enthought library imports
from traits.api import HasTraits, Enum, Instance, Property, Tuple

Expand Down Expand Up @@ -164,7 +161,7 @@ def _get_width(self):

def _set_width(self, val):

if isinstance(val, six.string_types):
if isinstance(val, str):
try:
val = float(val)
except:
Expand All @@ -179,7 +176,7 @@ def _get_height(self):
return self.bounds[1]

def _set_height(self, val):
if isinstance(val, six.string_types):
if isinstance(val, str):
try:
val = float(val)
except:
Expand Down
4 changes: 2 additions & 2 deletions enable/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
For a list of all the possible event suffixes, see interactor.py.
"""
import six.moves as sm
from functools import reduce

# Major library imports
from numpy import array, dot
Expand Down Expand Up @@ -104,7 +104,7 @@ def net_transform(self):
if len(self._transform_stack) == 0:
return affine.affine_identity()
else:
return sm.reduce(dot, self._transform_stack[::-1])
return reduce(dot, self._transform_stack[::-1])

def current_pointer_position(self):
"""
Expand Down
4 changes: 1 addition & 3 deletions enable/gadgets/vu_meter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import math

import six.moves as sm

from traits.api import Float, Property, List, Str, Range
from enable.api import Component
from kiva.trait_defs.kiva_font_trait import KivaFont
Expand Down Expand Up @@ -39,7 +37,7 @@ class VUMeter(Component):

# Values of the percentage-based ticks; these are drawn and labeled along
# the bottom of the curve axis.
percent_ticks = List(list(sm.range(0, 101, 20)))
percent_ticks = List(list(range(0, 101, 20)))

# Text to write in the middle of the VU Meter.
text = Str("VU")
Expand Down
5 changes: 1 addition & 4 deletions enable/layout/ab_constrainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
#------------------------------------------------------------------------------
from abc import ABCMeta

import six


@six.add_metaclass(ABCMeta)
class ABConstrainable(object):
class ABConstrainable(object, metaclass=ABCMeta):
""" An abstract base class for objects that can be laid out using
layout helpers.
Expand Down
24 changes: 9 additions & 15 deletions enable/layout/layout_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from collections import defaultdict
from uuid import uuid4

import six
import six.moves as sm

from kiwisolver import Variable, Constraint

from traits.api import HasTraits, Instance, Range
Expand Down Expand Up @@ -87,8 +84,7 @@ def is_spacer(item):
#------------------------------------------------------------------------------
# Deferred Constraints
#------------------------------------------------------------------------------
@six.add_metaclass(ABCMeta)
class DeferredConstraints(object):
class DeferredConstraints(object, metaclass=ABCMeta):
""" Abstract base class for objects that will yield lists of
constraints upon request.
Expand All @@ -107,9 +103,9 @@ def __or__(self, other):
strength.
"""
if isinstance(other, (float, six.integer_types)):
if isinstance(other, (float, int)):
self.default_string = float(other)
elif isinstance(other, six.string_types):
elif isinstance(other, str):
if other not in STRENGTHS:
raise ValueError('Invalid strength %r' % other)
self.default_strength = other
Expand Down Expand Up @@ -656,12 +652,12 @@ def _get_constraints(self, component):
row_vars = []
col_vars = []
cn_id = self.constraints_id
for idx in sm.range(num_rows + 1):
for idx in range(num_rows + 1):
name = 'row' + str(idx)
var = Variable('{0}|{1}'.format(cn_id, name))
row_vars.append(var)
constraints.append(var >= 0)
for idx in sm.range(num_cols + 1):
for idx in range(num_cols + 1):
name = 'col' + str(idx)
var = Variable('{0}|{1}'.format(cn_id, name))
col_vars.append(var)
Expand Down Expand Up @@ -722,7 +718,7 @@ def _get_constraints(self, component):
for cell in cells:
if cell.start_row == cell.end_row:
row_map[cell.start_row].append(cell.item)
for items in six.itervalues(row_map):
for items in row_map.values():
if len(items) > 1:
helpers.append(AlignmentHelper(self.row_align, *items))

Expand All @@ -734,7 +730,7 @@ def _get_constraints(self, component):
for cell in cells:
if cell.start_col == cell.end_col:
col_map[cell.start_col].append(cell.item)
for items in six.itervalues(row_map):
for items in row_map.values():
if len(items) > 1:
helpers.append(AlignmentHelper(self.col_align, *items))

Expand All @@ -748,8 +744,7 @@ def _get_constraints(self, component):
#------------------------------------------------------------------------------
# Abstract Constraint Factory
#------------------------------------------------------------------------------
@six.add_metaclass(ABCMeta)
class AbstractConstraintFactory(object):
class AbstractConstraintFactory(object, metaclass=ABCMeta):
""" An abstract constraint factory class. Subclasses must implement
the 'constraints' method implement which returns a LinearConstraint
instance.
Expand Down Expand Up @@ -1074,8 +1069,7 @@ def from_items(cls, items, anchor_name, spacing):
#------------------------------------------------------------------------------
# Spacers
#------------------------------------------------------------------------------
@six.add_metaclass(ABCMeta)
class Spacer(object):
class Spacer(object, metaclass=ABCMeta):
""" An abstract base class for spacers. Subclasses must implement
the 'constrain' method.
Expand Down
5 changes: 1 addition & 4 deletions enable/layout/linear_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
# ------------------------------------------------------------------------------
from abc import ABCMeta

import six

import kiwisolver as kiwi


@six.add_metaclass(ABCMeta)
class LinearSymbolic(object):
class LinearSymbolic(object, metaclass=ABCMeta):
""" An abstract base class for testing linear symbolic interfaces.
"""
Expand Down
6 changes: 2 additions & 4 deletions enable/qt4/base_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# been on my list of things to do.
#------------------------------------------------------------------------------

import six

# Qt imports.
from pyface.qt import QtCore, QtGui, QtOpenGL

Expand Down Expand Up @@ -371,14 +369,14 @@ def _create_key_event(self, event_type, event):
return None

if event_type == 'character':
key = six.text_type(event.text())
key = str(event.text())
else:
# Convert the keypress to a standard enable key if possible, otherwise
# to text.
key_code = event.key()
key = KEY_MAP.get(key_code)
if key is None:
key = six.unichr(key_code).lower()
key = chr(key_code).lower()

if not key:
return None
Expand Down
4 changes: 1 addition & 3 deletions enable/qt4/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import warnings

import six.moves as sm

from pyface.qt import QtCore

from ..toolkit_constants import key_names, mouse_wheel_axes_names, pointer_names
Expand Down Expand Up @@ -82,7 +80,7 @@
if len(pointer_names) != len(pointer_shapes):
warnings.warn("The Qt4 toolkit backend pointer map is out of sync!")

POINTER_MAP = dict(sm.zip(pointer_names, pointer_shapes))
POINTER_MAP = dict(zip(pointer_names, pointer_shapes))

KEY_MAP = {
QtCore.Qt.Key_Backspace: 'Backspace',
Expand Down
4 changes: 1 addition & 3 deletions enable/qt4/scrollbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
the standard Qt one.
"""

import six.moves as sm

from pyface.qt import QtCore, QtGui
from traits.api import Any, Bool, Enum, Float, Int, Property, Trait, TraitError

Expand Down Expand Up @@ -130,7 +128,7 @@ def _get_abs_coords(self, x, y):

def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
x_pos, y_pos = self.position
x_size, y_size = sm.map(int, self.bounds)
x_size, y_size = map(int, self.bounds)

qt_xpos, qt_ypos = self._get_abs_coords(x_pos, y_pos+y_size-1)

Expand Down
2 changes: 1 addition & 1 deletion enable/savage/compliance/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
renderers.
"""

from six import StringIO
from io import StringIO
import glob
import logging
import os
Expand Down
8 changes: 3 additions & 5 deletions enable/savage/compliance/drawer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import svg
import six
import six.moves as sm

import wx
import wx.py.shell
Expand Down Expand Up @@ -46,7 +44,7 @@ def OnPaint(self, evt):
class DrawFrame(wx.Frame):
def __init__(self, parent, *args, **kwargs):
wx.Frame.__init__(self, parent, *args, **kwargs)
self.pathOps = {k: v for (k,v) in six.iteritems(wx.GraphicsPath.__dict__) if k.startswith("Add")}
self.pathOps = {k: v for (k,v) in wx.GraphicsPath.__dict__.items() if k.startswith("Add")}
self.pathOps["CloseSubpath"] = wx.GraphicsPath.CloseSubpath
self.pathOps["MoveToPoint"] = wx.GraphicsPath.MoveToPoint
self.pathOps[""] = None
Expand Down Expand Up @@ -98,14 +96,14 @@ def OnPathChange(self, evt):
self.panel.SetPath(path)

def FillPath(self, path):
for row in sm.range(100):
for row in range(100):
#~ print row,
operation = self.grid.GetCellValue(row, 0)
if not operation:
return
#~ print operation,
args = []
for col in sm.range(1,20):
for col in range(1,20):
v = self.grid.GetCellValue(row, col)
if not v:
break
Expand Down
Loading

0 comments on commit 130fb11

Please sign in to comment.