Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 support #54

Merged
merged 20 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e103d38
Switch to `provides` from `implements`.
pradyunsg May 12, 2014
bb4f5c6
Change all `file` calls into `open` calls.
pradyunsg May 15, 2014
2818389
Added Python 3 compatibility with 2to3. Corrected 1 test.
pradyunsg May 20, 2014
703a9d0
Removed unused debugging code.
pradyunsg May 27, 2014
4d10d21
Several Python3 fixes.
prabhuramachandran Aug 20, 2015
238f572
Set use_2to3 always.
prabhuramachandran Aug 20, 2015
3139216
Skip `persistence.spickle` tests on py3k for now.
prabhuramachandran Aug 20, 2015
0813d7e
Fix a couple of uses of the sort method.
prabhuramachandran Aug 30, 2015
b0e24f2
BUG: Handle case of tuple with references.
prabhuramachandran Sep 7, 2015
146fac9
Get tests passing in Python 2.x and 3.x.
prabhuramachandran Sep 30, 2015
f5c199e
Merge branch 'master' of github.com:enthought/apptools into feature/p…
prabhuramachandran Oct 1, 2015
226bf4c
Fix silly error in test.
prabhuramachandran Oct 1, 2015
0cdde58
Get tests passing on Python 2.6.
prabhuramachandran Oct 1, 2015
6db4cd9
Fix test code for Python3 when TVTK is not available.
prabhuramachandran Oct 1, 2015
d5b0a84
Fix test error that shows only in Python3.
prabhuramachandran Oct 1, 2015
84c35ce
Don't import from API to prevent unnecessary UI imports.
prabhuramachandran Oct 1, 2015
d060e32
Get all apptools.io.h5 tests passing on Python 3.
prabhuramachandran Oct 1, 2015
76cacd7
Try using latest pyface for Python 3.x builds.
prabhuramachandran Oct 1, 2015
44d38ef
No longer allow failures on Python 3.x.
prabhuramachandran Oct 1, 2015
78e2117
Update as per PR comments, update CHANGES.
prabhuramachandran Oct 1, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ addons:
- ccache
- swig
- libhdf5-serial-dev
matrix:
allow_failures:
- python: 3.4
cache:
apt: true
directories:
Expand Down
5 changes: 3 additions & 2 deletions apptools/appscripting/bind_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@


# Enthought library imports.
from traits.api import Any, HasTraits, implements, Str
from traits.api import Any, HasTraits, provides, Str

# Local imports.
from i_bind_event import IBindEvent


@provides(IBindEvent)
class BindEvent(HasTraits):
"""The default implementation of the bind event interface."""

implements(IBindEvent)


#### 'IBindEvent' interface ###############################################

Expand Down
3 changes: 2 additions & 1 deletion apptools/appscripting/script_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from scriptable_type import make_object_scriptable


@provides(IScriptManager)
class _BoundObject(HasTraits):
"""The base class for any object that can be bound to a name."""

Expand Down Expand Up @@ -294,7 +295,7 @@ class ScriptManager(HasTraits):
IScriptManager.
"""

implements(IScriptManager)


#### 'IScriptManager' interface ###########################################

Expand Down
5 changes: 3 additions & 2 deletions apptools/help/help_plugin/action/demo_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Enthought library imports.
from envisage.api import IExtensionPointUser, IExtensionRegistry
from pyface.workbench.action.workbench_action import WorkbenchAction
from traits.api import Instance, implements, Property
from traits.api import Instance, provides, Property
from pyface.api import ImageResource
from apptools.help.help_plugin.api import HelpCode

Expand All @@ -32,6 +32,7 @@
from util import get_sys_prefix_relative_filename

# Implementation of the ImageResource class to be used for the DocAction class.
@provides(IExtensionPointUser)
class DemoImageResource(ImageResource):
""" Implementation of the ImageResource class to be used for the DemoAction
class.
Expand All @@ -44,7 +45,7 @@ class DemoImageResource(ImageResource):
class DemoAction(WorkbenchAction):
"""
"""
implements(IExtensionPointUser)


### Action interface ##############################################

Expand Down
5 changes: 3 additions & 2 deletions apptools/help/help_plugin/action/doc_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Enthought library imports.
from envisage.api import IExtensionPointUser, IExtensionRegistry
from pyface.workbench.action.workbench_action import WorkbenchAction
from traits.api import Instance, implements, Property
from traits.api import Instance, provides, Property
from pyface.api import ImageResource

from apptools.help.help_plugin.api import HelpDoc
Expand All @@ -35,6 +35,7 @@
PARENT = '.'.join(__name__.split('.')[:-2])

# Implementation of the ImageResource class to be used for the DocAction class.
@provides(IExtensionPointUser)
class DocImageResource(ImageResource):
""" Implementation of the ImageResource class to be used for the DocAction
class.
Expand All @@ -46,7 +47,7 @@ class DocImageResource(ImageResource):
class DocAction(WorkbenchAction):
""" (Pyface) Action for displaying a help doc.
"""
implements(IExtensionPointUser)


### Action interface ##############################################

Expand Down
5 changes: 3 additions & 2 deletions apptools/help/help_plugin/action/example_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Enthought library imports.
from envisage.api import IExtensionPointUser, IExtensionRegistry
from pyface.workbench.action.workbench_action import WorkbenchAction
from traits.api import Instance, implements, Property
from traits.api import Instance, provides, Property

from apptools.help.help_plugin.api import HelpCode
from apptools.help.help_plugin.examples_preferences import \
Expand All @@ -33,10 +33,11 @@
# This module's parent package.
PARENT = '.'.join(__name__.split('.')[:-2])

@provides(IExtensionPointUser)
class ExampleAction(WorkbenchAction):
""" (Pyface) Action for displaying a help example.
"""
implements(IExtensionPointUser)


### IExtensionPointUser interface
extension_registry = Property(Instance(IExtensionRegistry))
Expand Down
2 changes: 1 addition & 1 deletion apptools/help/help_plugin/examples_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


from apptools.preferences.api import PreferencesHelper
from traits.api import Either, Enum, File, Str, implements
from traits.api import Either, Enum, File, Str, provides

# This module's package.
PKG = '.'.join(__name__.split('.')[:-1])
Expand Down
5 changes: 3 additions & 2 deletions apptools/help/help_plugin/help_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
# Thanks for using Enthought open source!

from apptools.preferences.api import PreferencesHelper
from traits.api import File, Str, implements
from traits.api import File, Str, provides

from i_help_code import IHelpCode

@provides(IHelpCode)
class HelpCode(PreferencesHelper):
""" The implementation for help codes.

A help code is defined by a UI label and a filename.
"""
implements(IHelpCode)


#### IHelpCode interface / Preferences #####################################

Expand Down
5 changes: 3 additions & 2 deletions apptools/help/help_plugin/help_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
# Thanks for using Enthought open source!

from apptools.preferences.api import PreferencesHelper
from traits.api import Either, File, Str, implements, Bool
from traits.api import Either, File, Str, provides, Bool

from i_help_doc import IHelpDoc

@provides(IHelpDoc)
class HelpDoc(PreferencesHelper):
""" The implementation for help docs.

A help doc is defined by a UI label, a filename, and a viewer program.
"""
implements(IHelpDoc)


#### IHelpDoc interface / Preferences ######################################

Expand Down
5 changes: 3 additions & 2 deletions apptools/help/help_plugin/help_submenu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Enthought library imports.
from envisage.api import IExtensionPointUser, IExtensionRegistry
from pyface.action.api import Group, MenuManager
from traits.api import Any, implements, Instance, List, Property
from traits.api import Any, provides, Instance, List, Property

# Local imports.
from action.doc_action import DocAction
Expand All @@ -34,13 +34,14 @@
# This module's package.
PKG = '.'.join(__name__.split('.')[:-1])

@provides(IExtensionPointUser)
class HelpSubmenuManager(MenuManager):
""" Base class for managers of submenus of the Help menu.

This class is adapted from
pyface.ui.workbench.action.view_menu_manager.ViewMenuManager.
"""
implements(IExtensionPointUser)


### IExtensionPointUser interface
extension_registry = Property(Instance(IExtensionRegistry))
Expand Down
2 changes: 1 addition & 1 deletion apptools/io/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def create_file(self, contents=''):
if self.exists:
raise ValueError("file %s already exists" % self.path)

f = file(self.path, 'w')
f = open(self.path, 'w')
f.write(contents)
f.close()

Expand Down
6 changes: 4 additions & 2 deletions apptools/io/h5/dict_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def __init__(self, h5_group, auto_flush=True):
# Load dict data from the file node.
dict_node = getattr(h5_group, self._pyobject_data_node)
with closing(filenode.open_node(dict_node)) as f:
self._pyobject_data = json.load(f, object_hook=self._object_hook)
self._pyobject_data = json.loads(
f.read().decode('ascii'), object_hook=self._object_hook
)

#--------------------------------------------------------------------------
# Dictionary interface
Expand Down Expand Up @@ -172,7 +174,7 @@ def _create_pyobject_node(cls, pyt_file, node_path, data=None):

kwargs = dict(where=node_path, name=cls._pyobject_data_node)
with closing(filenode.new_node(pyt_file, **kwargs)) as f:
json.dump(out_data, f)
f.write(json.dumps(out_data).encode('ascii'))

@classmethod
def _get_pyt_group(self, group):
Expand Down
5 changes: 4 additions & 1 deletion apptools/io/h5/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def test_iteritems():
node_paths.append('/')
iter_paths = []

for path, node in h5.iteritems():
# 2to3 converts the iteritems blindly to items which is incorrect,
# so we resort to this ugliness.
items = getattr(h5, 'iteritems')()
for path, node in items:
iter_paths.append(path)

assert set(node_paths) == set(iter_paths)
Expand Down
2 changes: 1 addition & 1 deletion apptools/io/h5/tests/test_table_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_getitem():
def test_keys():
description = [('hello', 'int'), ('world', 'int'), ('Qux1', 'bool')]
with temp_h5_file() as h5:
keys = set(zip(*description)[0])
keys = set(list(zip(*description))[0])
h5table = H5TableNode.add_to_h5file(h5, NODE, description)
assert set(h5table.keys()) == keys

Expand Down
8 changes: 4 additions & 4 deletions apptools/io/tests/file_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_copy(self):
# Create the file.
f.create_file(content)
self.assertEqual(f.exists, True)
self.failUnlessRaises(ValueError, f.create_file, content)
self.assertRaises(ValueError, f.create_file, content)

self.assertEqual(f.children, None)
self.assertEqual(f.ext, '.txt')
Expand Down Expand Up @@ -161,10 +161,10 @@ def test_create_file(self):
# Create the file.
f.create_file(content)
self.assertEqual(f.exists, True)
self.assertEqual(file(f.path).read(), content)
self.assertEqual(open(f.path).read(), content)

# Try to create it again.
self.failUnlessRaises(ValueError, f.create_file, content)
self.assertRaises(ValueError, f.create_file, content)

return

Expand All @@ -179,7 +179,7 @@ def test_delete(self):
# Create the file.
f.create_file(content)
self.assertEqual(f.exists, True)
self.failUnlessRaises(ValueError, f.create_file, content)
self.assertRaises(ValueError, f.create_file, content)

self.assertEqual(f.children, None)
self.assertEqual(f.ext, '.txt')
Expand Down
10 changes: 5 additions & 5 deletions apptools/io/tests/folder_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_copy(self):
# Create the folder.
f.create_folder()
self.assertEqual(f.exists, True)
self.failUnlessRaises(ValueError, f.create_folder)
self.assertRaises(ValueError, f.create_folder)

self.assertEqual(len(f.children), 0)
self.assertEqual(f.ext, '')
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_create_folder(self):
self.assertEqual(parent.children[0].path, join('data', 'sub'))

# Try to create it again.
self.failUnlessRaises(ValueError, f.create_folder)
self.assertRaises(ValueError, f.create_folder)

return

Expand All @@ -197,15 +197,15 @@ def test_create_folders(self):

# Attempt to create the folder with 'create_folder' which requires
# that all intermediate folders exist.
self.failUnlessRaises(OSError, f.create_folder)
self.assertRaises(OSError, f.create_folder)

# Create the folder.
f.create_folders()
self.assertEqual(f.exists, True)
self.assertEqual(File('data/sub').exists, True)

# Try to create it again.
self.failUnlessRaises(ValueError, f.create_folders)
self.assertRaises(ValueError, f.create_folders)

return

Expand All @@ -218,7 +218,7 @@ def test_delete(self):
# Create the folder.
f.create_folder()
self.assertEqual(f.exists, True)
self.failUnlessRaises(ValueError, f.create_folder)
self.assertRaises(ValueError, f.create_folder)

self.assertEqual(len(f.children), 0)
self.assertEqual(f.ext, '')
Expand Down
4 changes: 2 additions & 2 deletions apptools/naming/object_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def load(self, path):
""" Loads an object from a file. """

# Unpickle the object.
f = file(path, 'rb')
f = open(path, 'rb')
try:
try:
obj = sweet_pickle.load(f)
Expand Down Expand Up @@ -84,7 +84,7 @@ def save(self, path, obj):
actual_path = path

# Pickle the object.
f = file(actual_path, 'wb')
f = open(actual_path, 'wb')
try:
sweet_pickle.dump(obj, f, 1)
# cPickle.dump(obj, f, 1)
Expand Down
2 changes: 1 addition & 1 deletion apptools/naming/py_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _get_reference(self):
def _is_bound(self, name):
""" Is a name bound in this context? """

return self.namespace.has_key(name)
return name in self.namespace

def _lookup(self, name):
""" Looks up a name in this context. """
Expand Down
4 changes: 2 additions & 2 deletions apptools/naming/pyfs_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _save_attributes(self):

path = join(self.path, self.ATTRIBUTES_FILE)

f = file(path, 'wb')
f = open(path, 'wb')
cPickle.dump(self._attributes, f, 1)
f.close()

Expand Down Expand Up @@ -552,7 +552,7 @@ def __attributes_default(self):

attributes_file = File(join(self.path, self.ATTRIBUTES_FILE))
if attributes_file.is_file:
f = file(attributes_file.path, 'rb')
f = open(attributes_file.path, 'rb')
attributes = cPickle.load(f)
f.close()

Expand Down
Loading