@@ -82,6 +82,54 @@ def write_pkg_info(self, egg_info):
8282 getattr (self , attr ),
8383 )))
8484
85+ def __str__ (self ):
86+ """Self-representation for inclusion in the setup.py."""
87+
88+ return '''
89+ class Metadata(object):
90+ """Metadata object class to shim the early stages of PKG-INFO writing."""
91+
92+ def __init__(self):
93+ self.metadata_version = {self.metadata_version!r}
94+ self.generator = {self.generator!r}
95+ self.name = {self.name!r}
96+ self.version = {self.version!r}
97+ self.summary = {self.summary!r}
98+ self.description = {self.description!r}
99+ self.home_page = {self.home_page!r}
100+ self.url = {self.url!r}
101+ self.author = {self.author!r}
102+ self.author_email = {self.author_email!r}
103+ self.license = {self.license!r}
104+ self.platforms = {self.platforms!r}
105+ self.platform = {self.platform!r}
106+ self.keywords = {self.keywords!r}
107+ self.source_label = {self.source_label!r}
108+ self.source_url = {self.source_url!r}
109+
110+ def write_pkg_info(self, egg_info):
111+ """Include pypackage custom metadata in PKG-INFO."""
112+
113+ if sys.version_info > (3,):
114+ UNICODE = str
115+ else:
116+ UNICODE = unicode
117+
118+ pkg_info = os.path.join(egg_info, "PKG-INFO")
119+ info_attrs = ["name", "version", "summary", "home_page",
120+ "author", "author_email", "license",
121+ "description", "platform", "source_label",
122+ "source_url"]
123+ with io.open(pkg_info, "w", encoding="utf-8") as openinfo:
124+ openinfo.write(UNICODE("Metadata-Version: 1.0\\ n"))
125+ for attr in info_attrs:
126+ openinfo.write(UNICODE("{{}}{{}}: {{}}\\ n".format(
127+ attr[0].upper(),
128+ "".join(attr[1:]).replace("_", "-"),
129+ getattr(self, attr),
130+ )))
131+ ''' .format (self = self )
132+
85133
86134class Config (object ):
87135 """Config object. Attributes are passed as kwargs."""
@@ -127,7 +175,6 @@ class Config(object):
127175 ("convert_2to3_doctests" , list ),
128176 ("use_2to3_fixtures" , list ),
129177 ("extensions" , {str : list }),
130- ("metadata" , object ),
131178 ])
132179 # our distinct keys, these do not get passed to setuptools/distutils
133180 _PYPACKAGE_KEYS = OrderedDict ([
@@ -241,14 +288,21 @@ def __str__(self):
241288 cmdclass = self ._cmdclass_string ()
242289 long_descr_str = self ._long_description_string ()
243290
244- altered_keys = ( "packages" , "long_description" , "cmdclass" )
245- altered_strs = ( packages_str , long_descr_str , cmdclass )
291+ altered_keys = [ "packages" , "long_description" , "cmdclass" ]
292+ altered_strs = [ packages_str , long_descr_str , cmdclass ]
246293
247294 imports = ["from setuptools import setup" ]
248295 if find_needed :
249296 imports .append ("from setuptools import find_packages" )
250297 if self ._long_read_in_setup :
251298 imports .insert (0 , "import io" )
299+ if hasattr (self , "metadata" ):
300+ if "import io" not in imports :
301+ imports .insert (0 , "import io" )
302+ imports .insert (1 , "import sys" )
303+ imports .insert (1 , "import os" )
304+ altered_keys .append ("metadata" )
305+ altered_strs .append ("metadata=Metadata()" )
252306
253307 return "\n " .join ([
254308 '"""{}\' s setup.py.\n ' .format (
@@ -258,7 +312,8 @@ def __str__(self):
258312 "should edit the {} rather than this setup.py." .format (META_NAME ),
259313 '"""\n \n ' ,
260314 "\n " .join (imports ),
261- self ._test_runner_string () or "\n " ,
315+ self ._test_runner_string () or "" ,
316+ str (self .metadata ) if hasattr (self , "metadata" ) else "" ,
262317 "{}setup(" .format (self ._long_read_in_setup ),
263318 "\n " .join ([
264319 " {}={}," .format (key , _multiline (val )) for key , val in
0 commit comments