Commit f78c4893 authored by Paul Ganssle's avatar Paul Ganssle

Fix issue with unicode author/maintainer on PY2

parent 2005e53e
# -*- coding: utf-8 -*-
__all__ = ['Distribution'] __all__ = ['Distribution']
import re import re
...@@ -38,7 +39,9 @@ def _get_unpatched(cls): ...@@ -38,7 +39,9 @@ def _get_unpatched(cls):
def get_metadata_version(dist_md): def get_metadata_version(dist_md):
if dist_md.long_description_content_type or dist_md.provides_extras: if dist_md.long_description_content_type or dist_md.provides_extras:
return StrictVersion('2.1') return StrictVersion('2.1')
elif getattr(dist_md, 'python_requires', None) is not None: elif (dist_md.maintainer is not None or
dist_md.maintainer_email is not None or
getattr(dist_md, 'python_requires', None) is not None):
return StrictVersion('1.2') return StrictVersion('1.2')
elif (dist_md.provides or dist_md.requires or dist_md.obsoletes or elif (dist_md.provides or dist_md.requires or dist_md.obsoletes or
dist_md.classifiers or dist_md.download_url): dist_md.classifiers or dist_md.download_url):
...@@ -48,7 +51,7 @@ def get_metadata_version(dist_md): ...@@ -48,7 +51,7 @@ def get_metadata_version(dist_md):
# Based on Python 3.5 version # Based on Python 3.5 version
def write_pkg_file(self, file): def write_pkg_file(self, file, is_test=False):
"""Write the PKG-INFO format data to a file object. """Write the PKG-INFO format data to a file object.
""" """
version = get_metadata_version(self) version = get_metadata_version(self)
...@@ -59,7 +62,7 @@ def write_pkg_file(self, file): ...@@ -59,7 +62,7 @@ def write_pkg_file(self, file):
file.write('Summary: %s\n' % self.get_description()) file.write('Summary: %s\n' % self.get_description())
file.write('Home-page: %s\n' % self.get_url()) file.write('Home-page: %s\n' % self.get_url())
if version == '1.2': if version < StrictVersion('1.2'):
file.write('Author: %s\n' % self.get_contact()) file.write('Author: %s\n' % self.get_contact())
file.write('Author-email: %s\n' % self.get_contact_email()) file.write('Author-email: %s\n' % self.get_contact_email())
else: else:
...@@ -72,6 +75,9 @@ def write_pkg_file(self, file): ...@@ -72,6 +75,9 @@ def write_pkg_file(self, file):
for field, attr in optional_fields: for field, attr in optional_fields:
attr_val = getattr(self, attr) attr_val = getattr(self, attr)
if six.PY2:
attr_val = self._encode_field(attr_val)
if attr_val is not None: if attr_val is not None:
file.write('%s: %s\n' % (field, attr_val)) file.write('%s: %s\n' % (field, attr_val))
...@@ -88,7 +94,7 @@ def write_pkg_file(self, file): ...@@ -88,7 +94,7 @@ def write_pkg_file(self, file):
if keywords: if keywords:
file.write('Keywords: %s\n' % keywords) file.write('Keywords: %s\n' % keywords)
if version == '1.2': if version >= StrictVersion('1.2'):
for platform in self.get_platforms(): for platform in self.get_platforms():
file.write('Platform: %s\n' % platform) file.write('Platform: %s\n' % platform)
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment