From: W. Trevor King Date: Fri, 17 Feb 2012 02:49:31 +0000 (-0500) Subject: Add Unicode long_description in setup.py post. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=50094f14c6f7df96603971828d47727818b74fd7;p=blog.git Add Unicode long_description in setup.py post. --- diff --git a/posts/Unicode_long_description_in_setup.py.mdwn b/posts/Unicode_long_description_in_setup.py.mdwn new file mode 100644 index 0000000..b05ca4c --- /dev/null +++ b/posts/Unicode_long_description_in_setup.py.mdwn @@ -0,0 +1,35 @@ +[[!meta title="Unicode `long_description` in `setup.py`"]] + +I've been trying to figure out how to setup Unicode long descriptions +in `setup.py`. I often use Unicode in my `README` files and then use +the contents of the `README` to set the long description with +something like: + + … + _this_dir = os.path.dirname(__file__) + … + setup( + … + long_description=codecs.open( + os.path.join(_this_dir, 'README'), 'r', encoding='utf-8').read(), + ) + +This crashed in Python 2.7 with a `UnicodeDecodeError` when I tried to +register the package on PyPI. The problem is that packages are +checked before registration to avoid being registered with broken +metadata, and Unicode handling was broken in distutils ([bug +13114][bug13114]). Unfortunately, there haven't yet been Python +releases containing the fixes (applied in October 2011). + +How do you work around this issue until get a more recent Python 2.7? +Just use Python 3.x, where Unicode handling is much cleaner. You may +need hide Python-3-incompatible code inside: + + if _sys.version_info < (3,0): + +blocks, but you shouldn't be pulling in huge amounts of code for +`setup.py` anyway. + +[bug13114]: http://bugs.python.org/issue13114 + +[[!tag tags/python]]