From 33295b129779e8e5e6d8b15829b5fdc0b07e421f Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 15 Oct 2016 00:44:56 -0700 Subject: [PATCH] Python: Python 3 support --- src/platform/python/CMakeLists.txt | 6 ++++-- src/platform/python/mgba/arm.py | 2 +- src/platform/python/mgba/core.py | 4 ++-- src/platform/python/mgba/gb.py | 2 +- src/platform/python/mgba/gba.py | 2 +- src/platform/python/mgba/image.py | 4 ++-- src/platform/python/mgba/lr35902.py | 4 ++-- src/platform/python/mgba/png.py | 4 ++-- src/platform/python/mgba/vfs.py | 2 +- src/platform/python/setup.py.in | 4 +++- 10 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/platform/python/CMakeLists.txt b/src/platform/python/CMakeLists.txt index 4945a793c..4a56b1474 100644 --- a/src/platform/python/CMakeLists.txt +++ b/src/platform/python/CMakeLists.txt @@ -1,3 +1,5 @@ +find_program(PYTHON python) + set(PY_INCLUDE_DIRS -I${CMAKE_SOURCE_DIR}/src) get_property(INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) get_property(COMPILE_DEFINITIONS DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) @@ -15,13 +17,13 @@ add_custom_command(OUTPUT _builder.h DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.h) add_custom_target(_builder.h ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_builder.h) -add_custom_target(${BINARY_NAME}-pylib COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py ${PY_COMPILE_DEFS} ${PY_INCLUDE_DIRS} +add_custom_target(${BINARY_NAME}-pylib COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py ${PY_COMPILE_DEFS} ${PY_INCLUDE_DIRS} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py DEPENDS _builder.h) add_custom_command(OUTPUT ${BINARY_NAME}/__init__.py COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME} - COMMAND python ${CMAKE_CURRENT_BINARY_DIR}/setup.py build + COMMAND ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py DEPENDS ${BINARY_NAME}-pylib) diff --git a/src/platform/python/mgba/arm.py b/src/platform/python/mgba/arm.py index 48878fc81..a594a6823 100644 --- a/src/platform/python/mgba/arm.py +++ b/src/platform/python/mgba/arm.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib class _ARMRegisters: def __init__(self, cpu): diff --git a/src/platform/python/mgba/core.py b/src/platform/python/mgba/core.py index 8e2350813..10b0ccd5d 100644 --- a/src/platform/python/mgba/core.py +++ b/src/platform/python/mgba/core.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib def find(path): core = lib.mCoreFind(path.encode('UTF-8')) @@ -31,7 +31,7 @@ def loadVF(vf): class Core: def __init__(self, native): - self._core = ffi.gc(native, self._deinit) + self._core = ffi.gc(native, native.deinit) success = bool(self._core.init(self._core)) if not success: raise RuntimeError("Failed to initialize core") diff --git a/src/platform/python/mgba/gb.py b/src/platform/python/mgba/gb.py index 8754a4476..1d141e966 100644 --- a/src/platform/python/mgba/gb.py +++ b/src/platform/python/mgba/gb.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib class GB: def __init__(self, native): diff --git a/src/platform/python/mgba/gba.py b/src/platform/python/mgba/gba.py index 9f8bd0a49..a425c5b42 100644 --- a/src/platform/python/mgba/gba.py +++ b/src/platform/python/mgba/gba.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib class GBA: def __init__(self, native): diff --git a/src/platform/python/mgba/image.py b/src/platform/python/mgba/image.py index ded9de9c6..907077433 100644 --- a/src/platform/python/mgba/image.py +++ b/src/platform/python/mgba/image.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib from . import png class Image: @@ -23,4 +23,4 @@ class Image: success = p.writeHeader(self) success = success and p.writePixels(self) p.writeClose() - return success \ No newline at end of file + return success diff --git a/src/platform/python/mgba/lr35902.py b/src/platform/python/mgba/lr35902.py index 3766eeaf8..6c1ffcddb 100644 --- a/src/platform/python/mgba/lr35902.py +++ b/src/platform/python/mgba/lr35902.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib class LR35902Core: def __init__(self, native): @@ -52,4 +52,4 @@ class LR35902Core: if key == 'sp': self._native.sp = value else: - self.__dict__[key] = value \ No newline at end of file + self.__dict__[key] = value diff --git a/src/platform/python/mgba/png.py b/src/platform/python/mgba/png.py index 75be631fb..bc1ff836c 100644 --- a/src/platform/python/mgba/png.py +++ b/src/platform/python/mgba/png.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib from . import vfs class PNG: @@ -21,4 +21,4 @@ class PNG: def writeClose(self): lib.PNGWriteClose(self._png, self._info) del self._png - del self._info \ No newline at end of file + del self._info diff --git a/src/platform/python/mgba/vfs.py b/src/platform/python/mgba/vfs.py index 1f1d0f8aa..158c07639 100644 --- a/src/platform/python/mgba/vfs.py +++ b/src/platform/python/mgba/vfs.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -from _pylib import ffi, lib +from ._pylib import ffi, lib import mmap import os diff --git a/src/platform/python/setup.py.in b/src/platform/python/setup.py.in index 133474831..045e6de4e 100644 --- a/src/platform/python/setup.py.in +++ b/src/platform/python/setup.py.in @@ -3,7 +3,7 @@ import re classifiers = [ "Programming Language :: Python :: 2", -# "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)" ] @@ -13,6 +13,8 @@ setup(name="${BINARY_NAME}", author_email="jeffrey@endrift.com", url="http://github.com/mgba-emu/mgba/", packages=["mgba"], + setup_requires=['cffi>=1.6'], + install_requires=['cffi>=1.6'], license="MPL 2.0", classifiers=classifiers ) \ No newline at end of file