Python 3 Support

Bug #1154010 reported by Jordan Farrell
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Simple Game Code
Fix Committed
High
Jordan Farrell

Bug Description

On build SGC v0.2 fails with:$ python3 setup.py build
  File "setup.py", line 4
    except ImportError, err:
                      ^
SyntaxError: invalid syntax

I am sure that if it is failing at this level then it will probably fail with many more errors. If the maintainers feels open to it, I could run 2-to-3 and build it as a feature branch. But curious if this should be done on v0.2 or if we should look at making the changes to a future branch such as v0.3 or v0.4.
Thanks.

Tags: python3

Related branches

Sam Bull (dreamsorcerer)
Changed in simplegc:
status: New → Triaged
importance: Undecided → Critical
importance: Critical → High
Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Just to repeat publicly what I emailed you:
Yes, run it through 2to3 and see if it ports easily. I won't be able to test it myself until I get Pygame running on Python 3.

0.3/4 hasn't begun development yet, so use the current version if you're in a hurry. I'll try to keep them both working through the 0.3/4 development cycle, and I'll probably drop support for Python2 at the end of the 0.4 release cycle.

Changed in simplegc:
assignee: nobody → Jordan Farrell (wolfrage)
Revision history for this message
Jordan Farrell (feralbytes) wrote :

Revision 350 should say "now".
Now I am running into this error:
  File "/usr/local/lib/python3.2/dist-packages/SimpleGC-0.2-py3.2.egg/sgc/surface.py", line 39, in __init__
    _locals.Font.set_fonts()
  File "/usr/local/lib/python3.2/dist-packages/SimpleGC-0.2-py3.2.egg/sgc/widgets/_locals.py", line 289, in set_fonts
    cls._fonts["widget"].replace(cls._create_font("Arial", 16))
  File "/usr/local/lib/python3.2/dist-packages/SimpleGC-0.2-py3.2.egg/sgc/widgets/_locals.py", line 239, in replace
    self._font = font
AttributeError: '_Font' object attribute '_font' is read-only

I believe it is related to this: http://stackoverflow.com/questions/820671/python-slots-and-attribute-is-read-only
Please advise what you would like to do in order to resolve this error? Should _font be an instance variable not a class variable?

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

OK, if moving the '_font = None' line into the init function works, then go with that, otherwise we'll figure something else out.

def __init__(self):
  self._font = None

Revision history for this message
Jordan Farrell (feralbytes) wrote :

Sam Bull, with your approval Revision 352 fixes the above error. Furether testing still needed.

Revision history for this message
Jordan Farrell (feralbytes) wrote :

OK so with that last change everything seems stable. No problems I am going to read more of your documentation and will start building some of the GUI elements that I wanted. If I encounter any errors I will report back. But if I don't encounter any errors then I would recommend merging after a couple of weeks.
Just to be sure though do you have any large scripts that I could test on my version, they will have to be Python 3 compatable?

Revision history for this message
Jordan Farrell (feralbytes) wrote :

OK got an error I am working on now:
self.btn_new_game.remove()
  File "/usr/local/lib/python3.2/dist-packages/SimpleGC-0.2-py3.2.egg/sgc/widgets/base_widget.py", line 197, in remove
    remove_widget_order(self)
  File "/usr/local/lib/python3.2/dist-packages/SimpleGC-0.2-py3.2.egg/sgc/widgets/_locals.py", line 393, in remove_widget_order
    del focus_order[num]
TypeError: list indices must be integers, not float

Revision history for this message
Jordan Farrell (feralbytes) wrote :

Revision 353 fixes the above error, used round() func from Python core to prevent floats. May find more like this as I implement more widgets.

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

The problem is that '/' in Python 3 does float division, just replace it with '//' and that should fix it cleanly. I'm suprised 2to3 didn't catch that.

Revision history for this message
Jordan Farrell (feralbytes) wrote :

All of the test scripts except the android one are currently passing on my system. I will go through each file in the next few days to look for any of the other potential errors that 2to3 may have missed or caused and that may be hidden. I could not test the android code because I don't have a device setup with Python3 on Android since it is still beta. But I looked over the file and it looks like it will be unaffected. After the 2to3 and some testing in my game I will go back and try the code in Python 2.7 to ensure compatability.

Revision history for this message
Jordan Farrell (feralbytes) wrote :

For follow up to revision 356: # FIXME: What exception type will json.load() produce?
I want to make sure that I am catching the correct exception rather then a blanket exception catch.
So it should raise a TypeError, correct?

Traceback (most recent call last):
  File "test.py", line 74, in <module>
    menu = MainMenu(menu=menu_file)
  File "../sgc/widgets/base_widget.py", line 96, in __init__
    self.config(init=None, **kwargs)
  File "../sgc/widgets/base_widget.py", line 151, in config
    self._config(**kwargs)
  File "../sgc/widgets/menu.py", line 96, in _config
    self._config_menu(menu_data, self._menus[-1])
  File "../sgc/widgets/menu.py", line 109, in _config_menu
    menu._title = Simple(Font["title"].render(data[0][2:], True, Font.col))
TypeError: '_io.TextIOWrapper' object is not subscriptable

Revision history for this message
Jordan Farrell (feralbytes) wrote :

For revision 356 of my branch it should be a ValueError, did a test to confirm.
ValueError: No JSON object could be decoded
Revision 364 reflects the change.

Changed in simplegc:
status: Triaged → In Progress
Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Can you double-check the changes to the import statements. I'm sure simple importing should work the same as Python 2, I don't see why 2to3 has changed all the import lines. Can you test if it works without the changes?

Revision history for this message
Jordan Farrell (feralbytes) wrote :

I will rollback the import changes one at a time and see what Python3 gives me. But since that was the initial error with Python3 I imagine it will again cause syntax import errors. I will report back and investigate options also. May take a day or two.

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Targeting to 0.4 as this is when I plan to merge, and begin replacing Python 2.

Changed in simplegc:
milestone: none → 0.4
Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Hey,

If you've got 5 minutes spare, I've just made the 0.2.1 release, if you
want to merge rev 355 into your branch, and sort out any Py3
conversions, I'll add a Py3 version, for the new release.

Revision history for this message
Jordan Farrell (feralbytes) wrote :

Ok I will merge Rev 355, then give it a few tests, should be complete latter tonight. I should have more time next week to finish work on the Py3 branch.

Revision history for this message
Jordan Farrell (feralbytes) wrote :

Rev 355 merged in Py3 branch, conflicts and 2-to-3 errors corrected, branch is now passing test.py and running in my game again. Please see latest revisions up to Rev 368. Should be ready to have a Python 3 package made. In the next few days I will continue to fix the import statements back to original.

Revision history for this message
Jordan Farrell (feralbytes) wrote :

A heads up to Windows users of SGC-py3. I still need to finish fixing the import statements, but I was busy building a Windows installer for my game. In doing so, when I installed the dependency that is SGC using the py3 branch on Windows I got an exit code of other than 0, probably 1. SGC still ran on the target Windows system though with limited testing. I will re-create the scenario after the rest of my installer is complete and get to the core of the problem.
Specificly this function from my installer returned the other than 0 status code:
def setup_sgc():
    base_dir = os.getcwd()
    sgc_dir = os.path.join(base_dir, 'sgc-0.2.1-py3')
    sgc_setup = sgc_dir + os.sep + 'setup.py'
    args = [sys.executable, sgc_setup, 'install']
    startupinfo = None
    if os.name == 'nt':
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    subprocess.check_output(args, universal_newlines=True,
        startupinfo=startupinfo)

I will get a full traceback during re-creation.

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Right, if you fix it, make an announcement to the Pygame mailing list, as that is where most users are likely to be.

Changed in simplegc:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.