From 50094f14c6f7df96603971828d47727818b74fd7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 16 Feb 2012 21:49:31 -0500 Subject: [PATCH] Add Unicode long_description in setup.py post. --- .../Unicode_long_description_in_setup.py.mdwn | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 posts/Unicode_long_description_in_setup.py.mdwn 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]] -- 2.26.2