|
15 | 15 | from distutils.errors import * |
16 | 16 | from distutils import sysconfig |
17 | 17 | 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 |
19 | 19 |
|
20 | 20 |
|
21 | 21 | # Regex to define acceptable Distutils command names. This is not *quite* |
@@ -85,6 +85,10 @@ class Distribution: |
85 | 85 | "print the package description"), |
86 | 86 | ('long-description', None, |
87 | 87 | "print the long package description"), |
| 88 | + ('platforms', None, |
| 89 | + "print the list of platforms"), |
| 90 | + ('keywords', None, |
| 91 | + "print the list of keywords"), |
88 | 92 | ] |
89 | 93 | display_option_names = map(lambda x: translate_longopt(x[0]), |
90 | 94 | display_options) |
@@ -206,9 +210,7 @@ def __init__ (self, attrs=None): |
206 | 210 | raise DistutilsSetupError, \ |
207 | 211 | "invalid distribution option '%s'" % key |
208 | 212 |
|
209 | | - if self.metadata.version is None: |
210 | | - raise DistutilsSetupError, \ |
211 | | - "No version number specified for distribution" |
| 213 | + self.finalize_options() |
212 | 214 |
|
213 | 215 | # __init__ () |
214 | 216 |
|
@@ -526,6 +528,28 @@ def _parse_command_opts (self, parser, args): |
526 | 528 | # _parse_command_opts () |
527 | 529 |
|
528 | 530 |
|
| 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 | + |
529 | 553 | def _show_help (self, |
530 | 554 | parser, |
531 | 555 | global_options=1, |
@@ -607,7 +631,11 @@ def handle_display_options (self, option_order): |
607 | 631 | for (opt, val) in option_order: |
608 | 632 | if val and is_display_option.get(opt): |
609 | 633 | 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 |
611 | 639 | any_display_options = 1 |
612 | 640 |
|
613 | 641 | return any_display_options |
@@ -950,7 +978,38 @@ def __init__ (self): |
950 | 978 | self.licence = None |
951 | 979 | self.description = None |
952 | 980 | self.long_description = None |
| 981 | + self.keywords = None |
| 982 | + self.platforms = None |
953 | 983 |
|
| 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 | + |
954 | 1013 | # -- Metadata query methods ---------------------------------------- |
955 | 1014 |
|
956 | 1015 | def get_name (self): |
@@ -996,6 +1055,12 @@ def get_description(self): |
996 | 1055 | def get_long_description(self): |
997 | 1056 | return self.long_description or "UNKNOWN" |
998 | 1057 |
|
| 1058 | + def get_keywords(self): |
| 1059 | + return self.keywords or [] |
| 1060 | + |
| 1061 | + def get_platforms(self): |
| 1062 | + return self.platforms or ["UNKNOWN"] |
| 1063 | + |
999 | 1064 | # class DistributionMetadata |
1000 | 1065 |
|
1001 | 1066 |
|
|
0 commit comments