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

Python 3 compatibility fixes #369

Merged
merged 16 commits into from
Aug 3, 2017
Merged

Conversation

jdeschenes
Copy link
Contributor

The unit test pass in python 3.6. This has not yet been completely tested in python. I will do another pass once I have gone over enable.

The examples have not been run as well. So I may make further modifications.

There is an issue in python 3 in the image plot. This is caused by a bug in enable. I skipped those tests.

jmdeschenes added 11 commits September 9, 2016 14:28
chaco/legend.py Outdated
@@ -355,7 +358,7 @@ def get_preferred_size(self):
if len(self.plots) == 0:
return [0, 0]

plot_names, visible_plots = map(list, zip(*sorted(self.plots.items())))
plot_names, visible_plots = list(sm.map(list, sm.zip(*sorted(six.iteritems(self.plots)))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably do with some unpacking. Alternatively, can we just use the standard Python constructs here and write the RHS as list(map(list, zip(*sorted(self.plots))))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your approach will not work. You need to have the items() in there

x = {'b': 1, 'a': 3}

assert sorted(x) == ['a', 'b']
assert sorted(x.items()) == [('a', 3), ('b', 1)]

For standard python contructs. See my comment in enthought/traits#374

It's more or less the same issue. I would prefer to keep the iterator version whenever possible.

Let me know your decision.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misunderstood. Thanks for the clarification, and let's keep it like you had it originally.

@@ -1,4 +1,6 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a from __future__ import print_function here?

@@ -350,15 +354,19 @@ def estimate_width(self, start, end, numlabels=None, char_width=None,
elif char_width:
avg_size = len("%g%g" % (start, end)) / 2.0
initial_estimate = round(fill_ratio * char_width / avg_size)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems orthogonal to the cleanup, can you describe what the issue is here? If the issue is that numlabels and char_width should not be both None, perhaps a ValueError("num_labels and char_width should not both be None.") would be more appropriate.

@@ -3,8 +3,8 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs a from __future__ import print_function.

Copy link
Contributor

@jvkersch jvkersch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdeschenes This is looking very good already, thanks for doing this! I left some general comments here and here, pointing out similar issues as @mdickinson reported for Traits. It also looks as if there are some changes that affect functionality, if possible it would be good to submit those separately (it will making reviewing easier). If there any areas (particularly with the demos) where the rest of the conversion is problematic, please let me know!

@@ -42,7 +42,7 @@ def test_strftimeEx_04():
# The format "%(ms_)" uses floor().
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs a from __future__ import print_function at the top of the module.

@@ -2,11 +2,11 @@
from itertools import starmap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs a from __future__ import print_function at the top of the module.

@@ -108,48 +113,56 @@ def plot_comparison(input_image, expected_image, **plot_kwargs):
plt.show()


@unittest.skipIf(six.PY3, "Bug in the image plotter in python 3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unexpected, is that new?

Copy link
Contributor Author

@jdeschenes jdeschenes Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a pretty old enthought/enable#95(See also enthought/enable#283). There are probably more related issues on github. I have the same issues on Windows so it is not strictly a gcc or clang issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, can you add a reference to the issue in the skip message?

@@ -78,7 +78,8 @@ def draw(self, gc, view_bounds=None):
if self.is_listener:
tmp = self._get_screen_pts()
elif self.is_interactive:
tmp = self._last_position
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this (and some of the other changes in this module) changes the functionality. Can you explain why this is necessary? If this fixes a bug, it would probably be good to split it off from the current PR and submit as a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I pulled in my branch #205 as I found it helped quite a bit and it looked like it will not be implemented anytime soon. I reverted changes in latest commit.

@@ -247,6 +247,8 @@ def panning_mouse_leave(self, event):
return self._end_pan(event)

def _start_pan(self, event, capture_mouse=True):
if event.control_down:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a functionality change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that... This has been reverted.

@@ -1,10 +1,11 @@
from cStringIO import StringIO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of the bundled sphinx extensions in this folder might not be Python3 compatible... (Just a comment in passing, no need to take any action)


# We first map to screen because the selection is stored as coordinates
# in data space
screen_pts = lasso_tool.plot.map_screen(selection)

# Now map each point into the grid index
for x, y in screen_pts:
print("\t", lasso_tool.plot.map_index((x, y)))
# for x, y in screen_pts:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the commented-out code here?

@@ -13,7 +13,7 @@
"""

# Major library imports
from scipy.misc import lena
from scipy.misc import face
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+100

from chaco.tools.api import SelectedZoomState
import numpy

class CaeZoomTool(ZoomTool):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cae?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, this should not have been part of the commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, looked like a pretty nifty tool ;-)

@jdeschenes
Copy link
Contributor Author

Sorry about that, looks like I bundled more changes(I am using this branch) than strictly necessary. I will do a pass and remove functional changes.

* used `from __future__ import print_function` on all files with print
functions
* Removed usage of `six.u`. Python 3.2 will not be supported
* Fixed an error message in formatters.py
* Forgot a `end=" "` in scales_test_case.py
* Removed a trailing backslash in plot_maker.py
* Removed integration of changes in line_inspector.py
* Removed changes from pan_tool.py
* traitsdoc.py had wrong import format
* Uncommented code in image_lasso.py
* Uncommented code in financial_plot.py
* Removed changes from multiaxis_using_Plot.py
* Removed changes from two_plots.py
@jdeschenes
Copy link
Contributor Author

jdeschenes commented Jul 21, 2017

I think I need to comment on some of the functional changes that I put there by mistake.

For multiaxis_using_Plot.py:

  1. Using the zoom tool with ctrl is doing a pan at the same time(pan_tool.py.) Strangely, this doesn't happen in two_plots.py. I think a code change may be necessary here. My approach was to subclass PanTool and ignore the pan move if my modifiers were pressed.
  2. The Box on the ZoomTool does not appear
  3. The ZoomTool is not doing the correct zoom(See issue ZoomTool doesn't play well with secondary axis #366) The CaeZoomTool has this fixed, but only partially... Using the mouse wheel to zoom off will not do what is right.

For financial_plot.py

  1. The font does not render properly on my machine. There is a warning on font_manager.py in kiva. That's a complete separate issue. Here is the related kiva/fonttools/fontmanager.py:findfont unable to find suitable fonts enable#259
    These changes definitively don't belong in this pull request.

@jvkersch
Copy link
Contributor

@jdeschenes Thanks for addressing the comments. Would you mind merging master in and resolving any merge conflicts? It would be good to start getting Travis test results on this.

# Conflicts:
#	chaco/api.py
@jdeschenes
Copy link
Contributor Author

The merge has just been done.

except ImportError:
# TO TEST
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this explicit raise?

@@ -52,7 +52,9 @@ def get_build_docset():
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
d = {}
execfile(os.path.join('..', '..', 'chaco', '_version.py'), d)
exec(compile(open(os.path.join('..', '..', 'chaco', '_version.py')).read(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you isolate the os.path.join('..', '..', 'chaco', '_version.py') into a local variable for re-use?

@jvkersch
Copy link
Contributor

@jdeschenes I left two tiny comments, but otherwise this looks very good to me. If you fix up those two items (and have nothing more to add), then I think this is good to go.

@jdeschenes
Copy link
Contributor Author

@jvkersch I fixed the issues you mentionned. I think this is ready to go!

@jvkersch
Copy link
Contributor

@jdeschenes I'm following along with the Enable review, and I think it would be good here too to use .items(), .values(), etc. instead of six.iteritems(...), six.itervalues(...), and so on. Would you be able to make that change? If not, I will pick this up separately (and apologies for bringing this up at the last minute).

@jdeschenes
Copy link
Contributor Author

@jvkersch I think I have corrected everything. Let me know if there is anything else!

@jvkersch
Copy link
Contributor

jvkersch commented Aug 3, 2017

@jdeschenes I think this looks good to go!

Thanks a lot for doing this (and for tackling the other repos, too). This will improve developer experience by a lot!

@jvkersch jvkersch merged commit 7c61319 into enthought:master Aug 3, 2017
rkern added a commit that referenced this pull request Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants