Enable PYDISTUTILS_SETUP to deal with different encodings in a setup.py file
Marcus von Appen
mva at FreeBSD.org
Thu May 29 10:12:45 UTC 2014
Dear all,
when trying to update graphics/py-PyX I stumbled across a unicode decode error
on reading the setup.py file for PyX version 0.13.
Our current approach is to read setup.py into a string buffer, to replace the
line endings and pass the result to compile() and exec().
This works great as long as
* the execution environment is configured to deal with matching encodings
properly (so that locale.getpreferredencoding() returns a file-compatible
encoding)
* the setup.py file features a proper encoding so that the execution
environment can deal with it (see above)
The majority of ports uses setup.py files, which use ASCII only. PyX 0.13
however contains some UTF-8 codepoints (umlauts), which causes the error
above, if the execution environment does not use some UTF-8 locale.
To work around that issue, we just need to read the file contents into a byte
buffer instead of converting the file contents to a string buffer:
-PYDISTUTILS_SETUP?= -c "import setuptools; __file__='${PYSETUP}'; exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))"
+PYDISTUTILS_SETUP?= -c "import setuptools; __file__='${PYSETUP}'; exec(compile(open(__file__, 'rb').read().replace(b'\\r\\n', b'\\n'), __file__, 'exec'))"
If there are no concerns, I'll commit the change this weekend.
Cheers
Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-python/attachments/20140529/e80c83e8/attachment.sig>
More information about the freebsd-python
mailing list