Date: Thu, 29 May 2014 12:10:18 +0200 From: Marcus von Appen <mva@FreeBSD.org> To: freebsd-python@freebsd.org Subject: Enable PYDISTUTILS_SETUP to deal with different encodings in a setup.py file Message-ID: <20140529101018.GA847@medusa.sysfault.org>
index | next in thread | raw e-mail
[-- Attachment #1 --]
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
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (FreeBSD)
iEYEARECAAYFAlOHB4oACgkQi68/ErJnpkcmOQCeLJEMJNCRLvPZBe7oWIJyfkeE
2wwAn2UldMCjgUIgxkdGX1wX5XnoZA9e
=9pe6
-----END PGP SIGNATURE-----
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140529101018.GA847>
