[Distutils] Unicode in the "long_description" – is this possible now?

Piotr Dobrogost p at 2015.forums.dobrogost.net
Thu Oct 1 16:41:22 CEST 2015


Hi!

I'd like to know if anything changed since 2011 with regard to using
unicode as a value of "long_description" argument to
setuptools/distutils setup function?

The problem was described by Carl Meyer in 2011 here
https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690 –

"The initial error is on reading from the file containing non-ASCII
(docs/news.txt in our case). This part is easily fixable by switching
from open(...) to codecs.open(..., encoding="UTF-8").

But then you get an encoding error on the output side. The usual way
to fix this would be to explicitly encode the string to bytes in the
desired encoding before output, e.g. long_description =
long_description.encode("UTF-8"). We can't do that for
long-description in setup.py, though, because distutils rfc822-escapes
it internally, and that requires string-only methods (split). So
long-description must be a string (unicode), it can't be encoded
bytes.

Attempts to change the default encoding of sys.stdout are pointless,
as in the installation case long-description isn't written to stdout,
it's written to a file."

Btw, in what situation does long_description get written to sys.stdout?


Regards,
Piotr Dobrogost


More information about the Distutils-SIG mailing list