Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7210ed

Browse files
committed
Add 'platforms' and 'keywords' attributes to the DistributionMetadata class,
along with options to print them. Add a finalize_options() method to Distribution to do final processing on the platform and keyword attributes Add DistributionMetadata.write_pkg_info() method to write a PKG-INFO file into the release tree.
1 parent df66df0 commit a7210ed

1 file changed

Lines changed: 70 additions & 5 deletions

File tree

Lib/distutils/dist.py

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from distutils.errors import *
1616
from distutils import sysconfig
1717
from distutils.fancy_getopt import FancyGetopt, translate_longopt
18-
from distutils.util import check_environ, strtobool
18+
from distutils.util import check_environ, strtobool, rfc822_escape
1919

2020

2121
# Regex to define acceptable Distutils command names. This is not *quite*
@@ -85,6 +85,10 @@ class Distribution:
8585
"print the package description"),
8686
('long-description', None,
8787
"print the long package description"),
88+
('platforms', None,
89+
"print the list of platforms"),
90+
('keywords', None,
91+
"print the list of keywords"),
8892
]
8993
display_option_names = map(lambda x: translate_longopt(x[0]),
9094
display_options)
@@ -206,9 +210,7 @@ def __init__ (self, attrs=None):
206210
raise DistutilsSetupError, \
207211
"invalid distribution option '%s'" % key
208212

209-
if self.metadata.version is None:
210-
raise DistutilsSetupError, \
211-
"No version number specified for distribution"
213+
self.finalize_options()
212214

213215
# __init__ ()
214216

@@ -526,6 +528,28 @@ def _parse_command_opts (self, parser, args):
526528
# _parse_command_opts ()
527529

528530

531+
def finalize_options (self):
532+
"""Set final values for all the options on the Distribution
533+
instance, analogous to the .finalize_options() method of Command
534+
objects.
535+
"""
536+
537+
if self.metadata.version is None:
538+
raise DistutilsSetupError, \
539+
"No version number specified for distribution"
540+
541+
keywords = self.metadata.keywords
542+
if keywords is not None:
543+
if type(keywords) is StringType:
544+
keywordlist = string.split(keywords, ',')
545+
self.metadata.keywords = map(string.strip, keywordlist)
546+
547+
platforms = self.metadata.platforms
548+
if platforms is not None:
549+
if type(platforms) is StringType:
550+
platformlist = string.split(platforms, ',')
551+
self.metadata.platforms = map(string.strip, platformlist)
552+
529553
def _show_help (self,
530554
parser,
531555
global_options=1,
@@ -607,7 +631,11 @@ def handle_display_options (self, option_order):
607631
for (opt, val) in option_order:
608632
if val and is_display_option.get(opt):
609633
opt = translate_longopt(opt)
610-
print getattr(self.metadata, "get_"+opt)()
634+
value = getattr(self.metadata, "get_"+opt)()
635+
if opt in ['keywords', 'platforms']:
636+
print string.join(value, ',')
637+
else:
638+
print value
611639
any_display_options = 1
612640

613641
return any_display_options
@@ -950,7 +978,38 @@ def __init__ (self):
950978
self.licence = None
951979
self.description = None
952980
self.long_description = None
981+
self.keywords = None
982+
self.platforms = None
953983

984+
def write_pkg_info (self, base_dir):
985+
"""Write the PKG-INFO file into the release tree.
986+
"""
987+
988+
pkg_info = open( os.path.join(base_dir, 'PKG-INFO'), 'w')
989+
990+
pkg_info.write('Metadata-Version: 1.0\n')
991+
pkg_info.write('Name: %s\n' % self.get_name() )
992+
pkg_info.write('Version: %s\n' % self.get_version() )
993+
pkg_info.write('Summary: %s\n' % self.get_description() )
994+
pkg_info.write('Home-page: %s\n' % self.get_url() )
995+
pkg_info.write('Author: %s\n' % self.get_maintainer() )
996+
pkg_info.write('Author-email: %s\n' % self.get_maintainer_email() )
997+
pkg_info.write('License: %s\n' % self.get_licence() )
998+
999+
long_desc = rfc822_escape( self.get_long_description() )
1000+
pkg_info.write('Description: %s\n' % long_desc)
1001+
1002+
keywords = string.join( self.get_keywords(), ',')
1003+
if keywords:
1004+
pkg_info.write('Keywords: %s\n' % keywords )
1005+
1006+
for platform in self.get_platforms():
1007+
pkg_info.write('Platform: %s\n' % platform )
1008+
1009+
pkg_info.close()
1010+
1011+
# write_pkg_info ()
1012+
9541013
# -- Metadata query methods ----------------------------------------
9551014

9561015
def get_name (self):
@@ -996,6 +1055,12 @@ def get_description(self):
9961055
def get_long_description(self):
9971056
return self.long_description or "UNKNOWN"
9981057

1058+
def get_keywords(self):
1059+
return self.keywords or []
1060+
1061+
def get_platforms(self):
1062+
return self.platforms or ["UNKNOWN"]
1063+
9991064
# class DistributionMetadata
10001065

10011066

0 commit comments

Comments
 (0)