Skip to content

Commit

Permalink
Merge pull request #72 from enthought/fix_unicode_description
Browse files Browse the repository at this point in the history
BUG: fix unicode handling in PKG-INFO and metadata summary.
  • Loading branch information
cournape committed Jun 30, 2015
2 parents c2c9655 + e1ab211 commit 17a9197
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion okonomiyaki/file_formats/_egg_info.py
Expand Up @@ -619,7 +619,7 @@ def _read_summary(fp):
# the summary file may not exist for eggs built with
# endist/repack
summary = b""
return summary.decode()
return summary.decode("utf8")

if isinstance(path_or_file, six.string_types):
spec_depend = LegacySpecDepend.from_egg(path_or_file)
Expand Down
8 changes: 5 additions & 3 deletions okonomiyaki/file_formats/egg.py
Expand Up @@ -93,14 +93,16 @@ def commit(self):

def _write_spec_depend(self):
spec_depend_string = self._egg_metadata.spec_depend_string
self._fp.writestr(_SPEC_DEPEND_LOCATION, spec_depend_string)
self._fp.writestr(_SPEC_DEPEND_LOCATION,
spec_depend_string.encode("ascii"))

def _write_spec_summary(self):
self._fp.writestr(_SPEC_SUMMARY_LOCATION, self._egg_metadata.summary)
self._fp.writestr(_SPEC_SUMMARY_LOCATION,
self._egg_metadata.summary.encode("utf8"))

def _write_pkg_info(self):
data = self._egg_metadata.pkg_info.to_string()
self._fp.writestr(_PKG_INFO_LOCATION, data)
self._fp.writestr(_PKG_INFO_LOCATION, data.encode("utf8"))


class EggBuilder(_EggBuilderNoPkgInfo):
Expand Down
44 changes: 44 additions & 0 deletions okonomiyaki/file_formats/tests/test_egg_file_format.py
@@ -1,3 +1,4 @@
# coding=utf-8
import os
import os.path
import shutil
Expand Down Expand Up @@ -70,6 +71,49 @@ def test_simple(self):
self.assertMultiLineEqual(fp.read("EGG-INFO/spec/depend").decode(),
r_spec_depend)

def test_unicode_pkg_info(self):
r_files = [
"EGG-INFO/PKG-INFO",
"EGG-INFO/spec/depend",
"EGG-INFO/spec/summary",
]
r_spec_depend = """\
metadata_version = '1.1'
name = 'Qt_debug'
version = '4.8.5'
build = 2
arch = 'x86'
platform = 'linux2'
osdist = 'RedHat_5'
python = '2.7'
packages = []
"""
r_description = r_summary = u"Un petit peu de français"

spec_depend = LegacySpecDepend.from_string(r_spec_depend)
pkg_info = PackageInfo("1.1", "Qt_debug", "4.8.5",
description=r_description)
metadata = EggMetadata._from_spec_depend(spec_depend, pkg_info,
r_summary)

with EggBuilder(metadata, cwd=self.d) as fp:
pass

egg_path = op.join(self.d, "Qt_debug-4.8.5-2.egg")
self.assertTrue(op.exists(egg_path))

with zipfile2.ZipFile(egg_path, "r") as fp:
self.assertEqual(set(fp.namelist()), set(r_files))
self.assertMultiLineEqual(fp.read("EGG-INFO/spec/depend").decode(),
r_spec_depend)

metadata = EggMetadata.from_egg(egg_path)
self.assertMultiLineEqual(metadata.summary, r_summary)

pkg_info = PackageInfo.from_egg(egg_path)
self.assertMultiLineEqual(pkg_info.description.rstrip(), r_description)

def _create_fake_metadata(self):
pkg_info = PackageInfo.from_string(PIP_PKG_INFO)
pkg_info.version = "4.8.6"
Expand Down

0 comments on commit 17a9197

Please sign in to comment.