| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Python
Revision: 66181
Author: marc-andre.lemburg
Date: 03 Sep 2008 07:13:56
Changes:Issue #2562: Fix distutils PKG-INFO writing logic to allow having
non-ascii characters and Unicode in setup.py meta-data.
| ... | ...@@ -23,6 +23,9 @@ | |
| 23 | 23 | from distutils import log |
| 24 | 24 | from distutils.debug import DEBUG |
| 25 | 25 | |
| 26 | # Encoding used for the PKG-INFO files | |
| 27 | PKG_INFO_ENCODING = 'utf-8' | |
| 28 | ||
| 26 | 29 | # Regex to define acceptable Distutils command names. This is not *quite* |
| 27 | 30 | # the same as a Python NAME -- I don't allow leading underscores. The fact |
| 28 | 31 | # that they're very similar is no coincidence; the default naming scheme is |
| ... | ...@@ -1084,23 +1087,23 @@ | |
| 1084 | 1087 | if self.provides or self.requires or self.obsoletes: |
| 1085 | 1088 | version = '1.1' |
| 1086 | 1089 | |
| 1087 | file.write('Metadata-Version: %s\n' % version) | |
| 1088 | file.write('Name: %s\n' % self.get_name() ) | |
| 1089 | file.write('Version: %s\n' % self.get_version() ) | |
| 1090 | file.write('Summary: %s\n' % self.get_description() ) | |
| 1091 | file.write('Home-page: %s\n' % self.get_url() ) | |
| 1092 | file.write('Author: %s\n' % self.get_contact() ) | |
| 1093 | file.write('Author-email: %s\n' % self.get_contact_email() ) | |
| 1094 | file.write('License: %s\n' % self.get_license() ) | |
| 1090 | self._write_field(file, 'Metadata-Version', version) | |
| 1091 | self._write_field(file, 'Name', self.get_name()) | |
| 1092 | self._write_field(file, 'Version', self.get_version()) | |
| 1093 | self._write_field(file, 'Summary', self.get_description()) | |
| 1094 | self._write_field(file, 'Home-page', self.get_url()) | |
| 1095 | self._write_field(file, 'Author', self.get_contact()) | |
| 1096 | self._write_field(file, 'Author-email', self.get_contact_email()) | |
| 1097 | self._write_field(file, 'License', self.get_license()) | |
| 1095 | 1098 | if self.download_url: |
| 1096 | file.write('Download-URL: %s\n' % self.download_url) | |
| 1099 | self._write_field(file, 'Download-URL', self.download_url) | |
| 1097 | 1100 | |
| 1098 | long_desc = rfc822_escape( self.get_long_description() ) | |
| 1099 | file.write('Description: %s\n' % long_desc) | |
| 1101 | long_desc = rfc822_escape( self.get_long_description()) | |
| 1102 | self._write_field(file, 'Description', long_desc) | |
| 1100 | 1103 | |
| 1101 | 1104 | keywords = string.join( self.get_keywords(), ',') |
| 1102 | 1105 | if keywords: |
| 1103 | file.write('Keywords: %s\n' % keywords ) | |
| 1106 | self._write_field(file, 'Keywords', keywords) | |
| 1104 | 1107 | |
| 1105 | 1108 | self._write_list(file, 'Platform', self.get_platforms()) |
| 1106 | 1109 | self._write_list(file, 'Classifier', self.get_classifiers()) |
| ... | ...@@ -1110,9 +1113,18 @@ | |
| 1110 | 1113 | self._write_list(file, 'Provides', self.get_provides()) |
| 1111 | 1114 | self._write_list(file, 'Obsoletes', self.get_obsoletes()) |
| 1112 | 1115 | |
| 1116 | def _write_field(self, file, name, value): | |
| 1117 | ||
| 1118 | if isinstance(value, unicode): | |
| 1119 | value = value.encode(PKG_INFO_ENCODING) | |
| 1120 | else: | |
| 1121 | value = str(value) | |
| 1122 | file.write('%s: %s\n' % (name, value)) | |
| 1123 | ||
| 1113 | 1124 | def _write_list (self, file, name, values): |
| 1125 | ||
| 1114 | 1126 | for value in values: |
| 1115 | file.write('%s: %s\n' % (name, value)) | |
| 1127 | self._write_field(file, name, value) | |
| 1116 | 1128 | |
| 1117 | 1129 | # -- Metadata query methods ---------------------------------------- |
| 1118 | 1130 |
| ... | ...@@ -1,3 +1,5 @@ | |
| 1 | # -*- coding: latin-1 -*- | |
| 2 | ||
| 1 | 3 | """Tests for distutils.dist.""" |
| 2 | 4 | |
| 3 | 5 | import distutils.cmd |
| ... | ...@@ -95,6 +97,39 @@ | |
| 95 | 97 | finally: |
| 96 | 98 | os.unlink(TESTFN) |
| 97 | 99 | |
| 100 | def test_write_pkg_file(self): | |
| 101 | # Check DistributionMetadata handling of Unicode fields | |
| 102 | my_file = os.path.join(os.path.dirname(__file__), 'f') | |
| 103 | klass = distutils.dist.Distribution | |
| 104 | ||
| 105 | dist = klass(attrs={'author': u'Mister Caf |
| ... | ...@@ -56,7 +56,10 @@ | |
| 56 | 56 | Library |
| 57 | 57 | ------- |
| 58 | 58 | |
| 59 | - Issue #3726: Allowed spaces in separators in logging configuration files. | |
| 59 | - Issue #2562: Fix distutils PKG-INFO writing logic to allow having | |
| 60 | non-ascii characters and Unicode in setup.py meta-data. | |
| 61 | ||
| 62 | - Issue #3726: Allow spaces in separators in logging configuration files. | |
| 60 | 63 | |
| 61 | 64 | - Issue #3719: platform.architecture() fails if there are spaces in the |
| 62 | 65 | path to the Python binary. |