Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Convert Python 2 to 3 using Futurize Conservatively #5

Merged
merged 13 commits into from
Aug 10, 2018

Conversation

danyeaw
Copy link
Contributor

@danyeaw danyeaw commented Jul 21, 2018

This PR takes a conservative approach and only adds Python 3 compatibility using the futurize library. I was also not able to get etk.docking to work with Python 2.7 based on namespace collision caused by the period in the name, so I refactored the project in to a more standard (for today) project structure.

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
@@ -20,12 +20,13 @@


from __future__ import absolute_import
from builtins import object
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you explicitly importing from the builtins module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Futurize backported 18 builtins from Python 3 to Python 2. If someone is running with Py3, it has no effect, but with Py2 it pulls in the Py3 backported versions. This is actually one of the strengths of this approach that it provides this extra "future" module with these builtins.

The other main option is called python-modernize which converts Py2 code into a common subset of Python 2 and 3, with six as a run-time dependency, futurize converts Py2 code into (almost) standard Py3 code, with future as a run-time dependency.

Because future provides more backported Py3 behaviours, the code resulting from futurize is more likely to work identically on both Py3 and Py2 with less additional manual porting effort. The disadvantages is that well I guess we pollute the namespace slightly, and that future only support Python 2.6, 2.7, and 3.3+. Six supports more backwards compatibility, but 2.6 is already end of life, and 2.7 will be soon.

I tried python-modernize first, and I think python-future is really a nice way to go.

For more information, here is the python-future explanation.

@danyeaw
Copy link
Contributor Author

danyeaw commented Jul 30, 2018

@amolenaar and @dieterv, any thoughts? Are you still interested in maintaining etk.docking? Are there concerns with my PR?

@amolenaar
Copy link
Collaborator

Apart from my question it looks good.

@danyeaw
Copy link
Contributor Author

danyeaw commented Aug 1, 2018

@amolenaar Excellent, did you see my response?

@amolenaar
Copy link
Collaborator

@dieterv, @danyeaw It may be an idea to move this code inside the Gaphor repo, or at least move it to the Gaphor organization.

@danyeaw This lib relies heavily on the X-Window DND functionality, via the GDK library. With hindsight this was not the best option. If it is possible to implement a custom (in-app) protocol, that would be way better for portability and usability.

@@ -0,0 +1,9 @@
# Install
simplegeneric
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think future should be added as a dependency as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I hadd to tweak the examples in docs/examples a little, due to the new naming of the toplevel package (etkdocking), but it works just fine.

@amolenaar amolenaar merged commit 99f5df6 into dieterv:master Aug 10, 2018
@danyeaw
Copy link
Contributor Author

danyeaw commented Aug 12, 2018

@amolenaar @dieterv I agree that transferring it to the Gaphor organization would help maintain the project and better streamline the updates we need.

@amolenaar Agreed that this isn't ideal. Do you think it would be better to remove dependence on these lower level APIs prior to trying to upgrade Gaphor to PyGObject?

@danyeaw danyeaw deleted the futurize-conservative branch August 12, 2018 02:02
@amolenaar
Copy link
Collaborator

@danyeaw In a previous attempt to port gaphor to gtk3 I ran into trouble with DnD. I was missing some apis. It may be better to create some shortcuts in order to get stuff workibg faster.

@danyeaw
Copy link
Contributor Author

danyeaw commented Aug 15, 2018

@amolenaar Do you have any guidance on an approach? Should I try to rip out all of etkdocking prior to updating Gaphor to use PyGObject? Should I just try to just replace the DND functionality?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants