Pregunta

I have a setup.py that use py2app, and I want to run 2to3 to convert python script to Python 3 compatible before build the app. I used option setup(use_2to3=True), but it did not call 2to3. So now I use a Makefile to work around this problem. Any pythonic solution? The setup.py is below. Please help.

import sys
from setuptools import setup
from plistlib import Plist
plist = Plist.fromFile('Info.plist')
OPTIONS = {
    'iconfile': 'python.icns',
    'plist': plist
}
if sys.version_info.major < 3:
    app = "PyInterpreter.py"
else:
    app = "build/PyInterpreter.py"

setup(
    name="PyInterpreter",
    app=[app],
    data_files=["English.lproj"],
    options={'py2app': OPTIONS},
    setup_requires=["py2app"],
    use_2to3=True,
)

Thanks.

¿Fue útil?

Solución

py2app does not support use_2to3, and likely never will unless someone contributes a patch (I'm the maintainer of py2app).

The cleanest solution to use 2to3 is to call it yourself, for example in a custom distutils command that subclasses py2app.build_app.py2app (implement a run method that calls 2to3, possibly adjust the build environment, then call the py2app.run method).

It is often much nicer to not use 2to3, but convert the code to something that runs with both python 3 and python 2. That's fairly easy when you can drop support for python 2.5 (and more so when you only need to support 2.7 or later), as most of the syntax of python 3 is supported in 2.6.

BTW. plistlib.Plist.fromFile is deprecated, use plistlib.readPlist instead.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top