mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / Unicode_long_description_in_setup.py.mdwn
1 [[!meta  title="Unicode `long_description` in `setup.py`"]]
2
3 I've been trying to figure out how to setup Unicode long descriptions
4 in `setup.py`.  I often use Unicode in my `README` files and then use
5 the contents of the `README` to set the long description with
6 something like:
7
8     …
9     _this_dir = os.path.dirname(__file__)
10     …
11     setup(
12         …
13         long_description=codecs.open(
14             os.path.join(_this_dir, 'README'), 'r', encoding='utf-8').read(),
15         )
16
17 This crashed in Python 2.7 with a `UnicodeDecodeError` when I tried to
18 register the package on PyPI.  The problem is that packages are
19 checked before registration to avoid being registered with broken
20 metadata, and Unicode handling was broken in distutils ([bug
21 13114][bug13114]).  Unfortunately, there haven't yet been Python
22 releases containing the fixes (applied in October 2011).
23
24 How do you work around this issue until get a more recent Python 2.7?
25 Just use Python 3.x, where Unicode handling is much cleaner.  You may
26 need hide Python-3-incompatible code inside:
27
28     if _sys.version_info < (3,0):
29
30 blocks, but you shouldn't be pulling in huge amounts of code for
31 `setup.py` anyway.
32
33 [bug13114]: http://bugs.python.org/issue13114
34
35 [[!tag tags/python]]