mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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.
This commit is contained in:
parent
df66df0a28
commit
a7210ed272
1 changed files with 70 additions and 5 deletions
|
|
@ -15,7 +15,7 @@ from copy import copy
|
||||||
from distutils.errors import *
|
from distutils.errors import *
|
||||||
from distutils import sysconfig
|
from distutils import sysconfig
|
||||||
from distutils.fancy_getopt import FancyGetopt, translate_longopt
|
from distutils.fancy_getopt import FancyGetopt, translate_longopt
|
||||||
from distutils.util import check_environ, strtobool
|
from distutils.util import check_environ, strtobool, rfc822_escape
|
||||||
|
|
||||||
|
|
||||||
# Regex to define acceptable Distutils command names. This is not *quite*
|
# Regex to define acceptable Distutils command names. This is not *quite*
|
||||||
|
|
@ -85,6 +85,10 @@ class Distribution:
|
||||||
"print the package description"),
|
"print the package description"),
|
||||||
('long-description', None,
|
('long-description', None,
|
||||||
"print the long package description"),
|
"print the long package description"),
|
||||||
|
('platforms', None,
|
||||||
|
"print the list of platforms"),
|
||||||
|
('keywords', None,
|
||||||
|
"print the list of keywords"),
|
||||||
]
|
]
|
||||||
display_option_names = map(lambda x: translate_longopt(x[0]),
|
display_option_names = map(lambda x: translate_longopt(x[0]),
|
||||||
display_options)
|
display_options)
|
||||||
|
|
@ -206,9 +210,7 @@ class Distribution:
|
||||||
raise DistutilsSetupError, \
|
raise DistutilsSetupError, \
|
||||||
"invalid distribution option '%s'" % key
|
"invalid distribution option '%s'" % key
|
||||||
|
|
||||||
if self.metadata.version is None:
|
self.finalize_options()
|
||||||
raise DistutilsSetupError, \
|
|
||||||
"No version number specified for distribution"
|
|
||||||
|
|
||||||
# __init__ ()
|
# __init__ ()
|
||||||
|
|
||||||
|
|
@ -526,6 +528,28 @@ class Distribution:
|
||||||
# _parse_command_opts ()
|
# _parse_command_opts ()
|
||||||
|
|
||||||
|
|
||||||
|
def finalize_options (self):
|
||||||
|
"""Set final values for all the options on the Distribution
|
||||||
|
instance, analogous to the .finalize_options() method of Command
|
||||||
|
objects.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.metadata.version is None:
|
||||||
|
raise DistutilsSetupError, \
|
||||||
|
"No version number specified for distribution"
|
||||||
|
|
||||||
|
keywords = self.metadata.keywords
|
||||||
|
if keywords is not None:
|
||||||
|
if type(keywords) is StringType:
|
||||||
|
keywordlist = string.split(keywords, ',')
|
||||||
|
self.metadata.keywords = map(string.strip, keywordlist)
|
||||||
|
|
||||||
|
platforms = self.metadata.platforms
|
||||||
|
if platforms is not None:
|
||||||
|
if type(platforms) is StringType:
|
||||||
|
platformlist = string.split(platforms, ',')
|
||||||
|
self.metadata.platforms = map(string.strip, platformlist)
|
||||||
|
|
||||||
def _show_help (self,
|
def _show_help (self,
|
||||||
parser,
|
parser,
|
||||||
global_options=1,
|
global_options=1,
|
||||||
|
|
@ -607,7 +631,11 @@ class Distribution:
|
||||||
for (opt, val) in option_order:
|
for (opt, val) in option_order:
|
||||||
if val and is_display_option.get(opt):
|
if val and is_display_option.get(opt):
|
||||||
opt = translate_longopt(opt)
|
opt = translate_longopt(opt)
|
||||||
print getattr(self.metadata, "get_"+opt)()
|
value = getattr(self.metadata, "get_"+opt)()
|
||||||
|
if opt in ['keywords', 'platforms']:
|
||||||
|
print string.join(value, ',')
|
||||||
|
else:
|
||||||
|
print value
|
||||||
any_display_options = 1
|
any_display_options = 1
|
||||||
|
|
||||||
return any_display_options
|
return any_display_options
|
||||||
|
|
@ -950,7 +978,38 @@ class DistributionMetadata:
|
||||||
self.licence = None
|
self.licence = None
|
||||||
self.description = None
|
self.description = None
|
||||||
self.long_description = None
|
self.long_description = None
|
||||||
|
self.keywords = None
|
||||||
|
self.platforms = None
|
||||||
|
|
||||||
|
def write_pkg_info (self, base_dir):
|
||||||
|
"""Write the PKG-INFO file into the release tree.
|
||||||
|
"""
|
||||||
|
|
||||||
|
pkg_info = open( os.path.join(base_dir, 'PKG-INFO'), 'w')
|
||||||
|
|
||||||
|
pkg_info.write('Metadata-Version: 1.0\n')
|
||||||
|
pkg_info.write('Name: %s\n' % self.get_name() )
|
||||||
|
pkg_info.write('Version: %s\n' % self.get_version() )
|
||||||
|
pkg_info.write('Summary: %s\n' % self.get_description() )
|
||||||
|
pkg_info.write('Home-page: %s\n' % self.get_url() )
|
||||||
|
pkg_info.write('Author: %s\n' % self.get_maintainer() )
|
||||||
|
pkg_info.write('Author-email: %s\n' % self.get_maintainer_email() )
|
||||||
|
pkg_info.write('License: %s\n' % self.get_licence() )
|
||||||
|
|
||||||
|
long_desc = rfc822_escape( self.get_long_description() )
|
||||||
|
pkg_info.write('Description: %s\n' % long_desc)
|
||||||
|
|
||||||
|
keywords = string.join( self.get_keywords(), ',')
|
||||||
|
if keywords:
|
||||||
|
pkg_info.write('Keywords: %s\n' % keywords )
|
||||||
|
|
||||||
|
for platform in self.get_platforms():
|
||||||
|
pkg_info.write('Platform: %s\n' % platform )
|
||||||
|
|
||||||
|
pkg_info.close()
|
||||||
|
|
||||||
|
# write_pkg_info ()
|
||||||
|
|
||||||
# -- Metadata query methods ----------------------------------------
|
# -- Metadata query methods ----------------------------------------
|
||||||
|
|
||||||
def get_name (self):
|
def get_name (self):
|
||||||
|
|
@ -996,6 +1055,12 @@ class DistributionMetadata:
|
||||||
def get_long_description(self):
|
def get_long_description(self):
|
||||||
return self.long_description or "UNKNOWN"
|
return self.long_description or "UNKNOWN"
|
||||||
|
|
||||||
|
def get_keywords(self):
|
||||||
|
return self.keywords or []
|
||||||
|
|
||||||
|
def get_platforms(self):
|
||||||
|
return self.platforms or ["UNKNOWN"]
|
||||||
|
|
||||||
# class DistributionMetadata
|
# class DistributionMetadata
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue