私はsetuptoolsのを使ってPythonパッケージのsetup.pyを書き込み、LONG_DESCRIPTIONフィールドに非ASCII文字を含めるたかった:Unicodeメタデータをsetup.pyで使用する正しい方法は何ですか?
残念ながら#!/usr/bin/env python
from setuptools import setup
setup(...
long_description=u"...", # in real code this value is read from a text file
...)
、セットアップにUnicodeオブジェクトを渡すことは、()のいずれかを破ります私はLONG_DESCRIPTIONフィールドの生のUTF-8文字列を使用している場合UnicodeEncodeErrorを
python setup.py --long-description | rst2html python setup.py upload
と2つのコマンドを以下、UnicodeDecodeErrorで次のコマンドブレーク:
python setup.py register
私は一般に、 'python setup.py sdist register upload'を実行することでソフトウェアをリリースします。これは、sys.argvを調べ、適切なオブジェクトタイプを渡すという醜いハッキングを意味します。
最後に、私はあきらめ、別の醜いハックを実装:
class UltraMagicString(object):
# Catch-22:
# - if I return Unicode, python setup.py --long-description as well
# as python setup.py upload fail with a UnicodeEncodeError
# - if I return UTF-8 string, python setup.py sdist register
# fails with an UnicodeDecodeError
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
def __unicode__(self):
return self.value.decode('UTF-8')
def __add__(self, other):
return UltraMagicString(self.value + str(other))
def split(self, *args, **kw):
return self.value.split(*args, **kw)
...
setup(...
long_description=UltraMagicString("..."),
...)
がより良い方法ではないですか?私は上記のコードでテストしてい
完全なトレースバックをコメントに貼り付けることはできません。トレースバックは/usr/lib/python2.6/distutils/command/register.py行264(post_to_server内)で終了します。これは、value = unicode(value).encode( "utf-8")です。ご覧のとおり、私はPython 2.6を使用しています。 distutilsのそれ以降のバージョンは、本当に最先端のものを出す必要があります。 –
あなたは実際にフィールドに少なくとも1つの非ASCII文字が必要であることに注意してください。 –
私は 'python setup'を再現できます。私がここにあるPythonの3つのバージョン(2.4,2.5、および2.6)すべてで、「pyレジスタ」エラーが発生します。 –