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.8 #650

Merged
merged 10 commits into from
Jul 25, 2020
Merged

Python 3.8 #650

merged 10 commits into from
Jul 25, 2020

Conversation

Hoikas
Copy link
Member

@Hoikas Hoikas commented May 11, 2020

This updates the game engine and scripts to support Python 3. Note that the minimum required Python version is 3.73.8 due to the PyUnicode API changing to properly return const char* because Python.pak support requires the new initialization API from 3.8. From my limited testing, the game plays correctly, however a full playthough was not done.

This changeset deletes the in-repo copy of the Python stdlib. We ought to not be versioning external code that changes based off the Python version. The stdlib and the rest of the scripts are now copied to the runtime output directory at build time. Hopefully this will make generating working game clients easier.

This DOES NOT:

  • update the resource.dat generation scripts to Python 3. Per @Deledrius and my experimentation, these rely on fragile modules that are nearly impossible to trivally pip install on Python 3.
  • attempt to deal with the chaos of the duplicated get[thing]W() methods in the Python API

Note this extends the work done in #596 because it seems silly to replicate these changes on top of the other API changes found therein.

@Hoikas Hoikas force-pushed the py3 branch 14 times, most recently from fc968c9 to 930d8ef Compare May 13, 2020 00:25
@Hoikas Hoikas marked this pull request as ready for review May 13, 2020 00:33
@Hoikas Hoikas requested review from zrax and Deledrius May 13, 2020 00:42
@Hoikas
Copy link
Member Author

Hoikas commented May 13, 2020

:shipit:

@Hoikas
Copy link
Member Author

Hoikas commented May 14, 2020

I have pushed a fix for the issue in which junked python.pak files are created by plPythonPack.exe. Using python.pak is still broken however due to changes in Python 3's import machinery... Work will continue on this.

Copy link
Member

@zrax zrax left a comment

Choose a reason for hiding this comment

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

Some of these changes can be applied to Python 2.7, such as the removal of the string module and iterable.sort(key=...)... It might be worth breaking those out into a separate PR, since those cover a large amount of the review here...

CMakeLists.txt Outdated Show resolved Hide resolved
Scripts/CMakeLists.txt Show resolved Hide resolved
Scripts/Python/ki/__init__.py Outdated Show resolved Hide resolved
Scripts/Python/plasma/Plasma.py Outdated Show resolved Hide resolved
Scripts/Python/plasma/PlasmaTypes.py Show resolved Hide resolved
Scripts/Python/xEventTrigger.py Outdated Show resolved Hide resolved
Sources/Plasma/FeatureLib/pfPython/cyMiscGlue4.cpp Outdated Show resolved Hide resolved
@Hoikas Hoikas force-pushed the py3 branch 3 times, most recently from 81d0b7e to c279f9c Compare May 15, 2020 18:57
@Hoikas
Copy link
Member Author

Hoikas commented May 15, 2020

Updated to fix issues from review and add proper PEP 451 compliant import machinery for python.pak.

@Hoikas
Copy link
Member Author

Hoikas commented May 16, 2020

Rebased onto master, which now includes two commits that were previously part of this PR. See #651.

@Hoikas
Copy link
Member Author

Hoikas commented Jun 4, 2020

Rerequesting review specifically for b82d8d305b4ded.

@Hoikas Hoikas mentioned this pull request Jun 5, 2020
@Hoikas Hoikas marked this pull request as ready for review June 12, 2020 19:20
@Hoikas
Copy link
Member Author

Hoikas commented Jun 12, 2020

Reopening due to the merge of python 3.8 into vcpkg and successful testing of python.pak.

README.md Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp Outdated Show resolved Hide resolved
@Hoikas
Copy link
Member Author

Hoikas commented Jul 13, 2020

Updated to fix issues from review.

@Hoikas
Copy link
Member Author

Hoikas commented Jul 14, 2020

Blocking on H-uru/PlasmaPrefix#4.

Hoikas added 9 commits July 14, 2020 17:14
This updates the C++ code for API changes in Python 3. Note that this
does not attempt to fix issues like duplicated wide-string getter/setter
functions.
Run 2to3 fixers:
- unicode
- dict
- xrange
- long

Also manually fixed the abc metaclass usage to instead use `abc.ABC`.
Our CMake now exposes a "Scripts" target that will properly copy over
all of the scripts including dat, SDL, Python, and Python stdlib from
their corresponding location to the runtime output directory.
According to the Python documentation, calling `PyUnicode_AsUTF8AndSize`
will cache a UTF-8 version of the python string for future use. So let's
do that instead of reencoding UTF-16 or UTF-32 to UTF-8 each call to
`PyUnicode_AsSTString`.
This is required due to reports from multiple testers that the client
exits on loading StartUp. The issue is that Python 3 loads modules
during its initialization--before we have installed our PEP 451 import
machinery for python.pak. The previous code worked for us because we
have Python 3 installed on our systems, which is not a reasonable
assumption to have for our players. Python 3.8 adds APIs that allow us
to initialize just the "core" and use the API, then initialize the
interpreter itself once we have added the import machinery.
@Hoikas
Copy link
Member Author

Hoikas commented Jul 16, 2020

@zrax, @dpogue Is there anything else I need to do here?

@Deledrius
Copy link
Member

This looks ready to merge. Any objections?

@Deledrius Deledrius merged commit 88f2ab2 into H-uru:master Jul 25, 2020
@Hoikas
Copy link
Member Author

Hoikas commented Jul 25, 2020

💥 💥 💥

@Hoikas Hoikas deleted the py3 branch July 25, 2020 00:44
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.

3 participants