bastienleonard / pysfml-cython

A Python 2/3 binding for SFML 2, written with Cython
http://pysfml2-cython.readthedocs.org/
Other
68 stars 8 forks source link

Update/fix the build system for Python 3, remove some old/broken/useless code #57

Open K900 opened 11 years ago

K900 commented 11 years ago

1) Strongly depend on Cython. Cython.Distutils confirmed present on win32/linux2 python2.7/python3.3 with cython 0.18. 2) Remove setup3k.py, setup.py is python2/python3 compatible now. 3) Hack around the patch.py step by defining DL_IMPORT at runtime. TODO: find out when exactly DL_IMPORT was removed and update version checks accordingly

shizmob commented 11 years ago

I'd just like to say that Cython (and by extension Cython.Distutils) is not installed by default, which is the whole reason for the weak dependency on Cython.

K900 commented 11 years ago

I'm pretty sure it is now. Edit: it is installed if you have distribute before installing Cython.

shizmob commented 11 years ago

Yes, but the point is that @bastienleonard doesn't want to force people to install Cython in the first place.

K900 commented 11 years ago

I'm not too sure it's that much of an issue, because Cython can be installed pretty much everywhere now without any issues. Even if Cython should stay a weak dependency, it needs to be done in a different way, e.g. by trying to import Cython.Distutils and only falling back to Cython-less builds if it's not present.

K900 commented 11 years ago

Also, shipping pregenerated files with the package might break the build, especially on older Python versions. That's just a theory for now, but there can be API mismatches.

shizmob commented 11 years ago

Oh, I'm not saying I disagree; I'm just stating the reasoning for the weak dependency in the first place. Personally I'd much prefer just relying on Cython.

K900 commented 11 years ago

I'm just stating my reasoning for relying on Cython. Also, it seems the (old) Arch package was already broken because the pregenerated stuff in there was for Python 2.7. Oops.

bastienleonard commented 11 years ago

I don't provide Cython-generated .cpp files anymore, but I'm going to wait a bit before removing that feature. Also, I don't really want to use “Leonard” instead of “Léonard”, as pedant as it seems. Is there really no way to do that in a Python-independant way? Thanks for the macro trick, I think it was one of the biggest annoyances for users. Sorry but it's too late here to test and push those changes now, I'll have to do that later.

I'm just stating my reasoning for relying on Cython. Also, it seems the (old) Arch package was already broken because the pregenerated stuff in there was for Python 2.7. Oops.

Code generated by Cython should work with Python 2 and Python 3, as far as I know.

K900 commented 11 years ago

Well, we can keep “Léonard” with some Unicode escape magic, but I'm not really sure it's worth it, it'll be like 10 lines of code just to replace one character... Also, Cython uses some version-specific hacks, especially for the older ones like 2.4 or 2.5.

shizmob commented 11 years ago

10 lines?

author=u'Bastien Léonard' if sys.version_tuple.major < 3 else 'Bastien Léonard'

K900 commented 11 years ago

That won't work, it needs to parse the whole thing.

shizmob commented 11 years ago
% python3 -c "print(u'foo')"
foo
K900 commented 11 years ago

Fixed.

K900 commented 11 years ago

@Shizmob: Python 3.3 has unicode literals, previous 3.x versions don't. http://www.python.org/dev/peps/pep-0414/

shizmob commented 11 years ago

What about 'Bastién Leonard'.decode('utf-8') if sys.version_tuple < 3 else 'Bastién Leonard'?

K900 commented 11 years ago

Works on 2.7/3.3, but I'm not sure about some of the earlier versions.

jstasiak commented 11 years ago

I'd say 'Bastién Leonard'.decode('utf-8') if str is bytes else 'Bastién Leonard'

or even

author = 'Bastién Leonardi'
if bytes is str:
    author = author.decode('utf-8')

Works in Python 2.6, 2.7 and 3.3, should work in any 3.x version.

K900 commented 11 years ago

Can anyone test with 2.5?

jstasiak commented 11 years ago

It doesn't work in 2.5: http://codepad.org/cNMHLTxU

However 'Bastién Leonard'.decode('utf-8') if int(sys.version_info[0]) < 3 else 'Bastién Leonard' seems to be working: http://codepad.org/YIfIhijN

K900 commented 11 years ago

Then I guess the latter is safe to use. Updating now.

jstasiak commented 11 years ago

:+1: