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

Update project to Python3 (2.7 -> 3.6) #91

Merged
merged 9 commits into from
Apr 21, 2019
Merged

Update project to Python3 (2.7 -> 3.6) #91

merged 9 commits into from
Apr 21, 2019

Conversation

Nebual
Copy link
Collaborator

@Nebual Nebual commented Apr 19, 2019

May want to review commit-by-commit.

The 2to3 tool handled most of the quick replacements, however there were 2 main areas it wasn't able to detect which required some care:

  1. / -> // when we specifically want integer math. In Python2, 5 / 2 == 2, whereas 5 / 2.0 == 2.5. As of Python3, / always means float math, and // always means integer math - but lots of our code was relying on resulting ints (and Pyglet would blow up upon being given floats...)
  2. Handling of str vs bytes, especially relevant as this project makes heavy use of raw bytes operations in both the saving/loading and networking.

Additionally, as Python3.5 added support for (compile-time) type hints, I added a number of them to help clarify the distinction between str and bytes. Cython uses those type hints instead of needing a separate .pyd definitions file, which seems nice.

Everything appears to work about as well as on Python2, with likely a few bugs/inaccuracies fixed due to Python3's generally stricter handling, and possibly a few new crashes caused by that strictness.

As py2exe doesn't seem to support the latest Python3.x, I've updated setup.py to use cx_Freeze, which can also produce all-dependencies-bundled zips, helping #71 along

Closes #87
Closes #78

@r58Playz
Copy link

Great! I'm tired of typing C:/Python27/python.exe as I have both python 2.7 and python 3.7 installed.

@r58Playz
Copy link

There still are some errors, though.

@Nebual
Copy link
Collaborator Author

Nebual commented Apr 19, 2019

There still are some errors, though.

Can you be more specific?

This project is rather stale and had several issues on master, so this branch is focused on specifically Python3 related errors, I ignored the "crash on block break due to audio" for example as that happened on python2 (though I then fixed it on master, so git checkout python3 && git merge origin/master should fix that).

@r58Playz
Copy link

Like a TypeError when trying to place a block, and lots of server errors while trying to handle another server error.

I can fix the block-break animations, though.

@r58Playz
Copy link

The crash on block break due to audio just needs a rename:

pyglet.audio.ManagedSoundPlayer to pyglet.audio.Player

@r58Playz
Copy link

I guess the errors are happening because I'm using Python 3.7.

Does this work for Python 3.7?

@Nebual
Copy link
Collaborator Author

Nebual commented Apr 20, 2019

I patched ManagedSoundPlayer on master, though I was still getting periodic segfaults, so I disabled audio.

Python 3.7 works for me, though I did accidentally try loading the python3 branch with python2, resulting in a corrupted save file that I then had to manually delete. https://pyglet.readthedocs.io/en/pyglet-1.2-maintenance/api/pyglet/resource/pyglet.resource.get_settings_path.html shows where the saves are.

@r58Playz
Copy link

I just deleted the get_settings_path part and set it to a folder called "pyCraft".

@r58Playz
Copy link

Oh, and the TypeError I was getting earlier was cannot assign a string of slice 24 to a string of slice 48.

@r58Playz
Copy link

r58Playz commented Apr 20, 2019

Another error, right when I connected to a server. `TypeError: can't concat str to bytes

@r58Playz
Copy link

r58Playz commented Apr 20, 2019

Everything's working.

@Nebual
Copy link
Collaborator Author

Nebual commented Apr 21, 2019

In the interest of getting master to a working state, I'm going to merge this now.

@Nebual Nebual merged commit 5ee58e4 into master Apr 21, 2019
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.

Python3 support?? Segmentation Fault on Ubuntu
2 participants