अगर आप कुछ बारीकियाँ चाहते हैं, तो मैं @ modocache के उत्तर से सिर्फ गुल्लक की तरह हूँ।
इस उत्तर के दौरान, मैं FOO-PYTHON-ENV\Lib\distutils\dist.py
फ़ाइल के एक python3.6 संस्करण का उल्लेख करूंगा
दोहराना करने के लिए, आप author
क्षेत्र में एक सूची का उपयोग नहीं कर सकते । यहाँ पर क्यों:
स्पॉयलर: DistributionMetadata
कक्षा से संबंधित दो विधियाँ इसका कारण हैं -
def _read_field(name):
value = msg[name]
if value == 'UNKNOWN':
return None
return value
def _read_list(name):
values = msg.get_all(name, None)
if values == []:
return None
return values
यदि आप author
फ़ील्ड में सूची बनाने की कोशिश करते हैं तो यहां एक त्रुटि होगी :
class DistributionMetadata:
def read_pkg_file(self, file):
"""Reads the metadata values from a file object."""
self.name = _read_field('name')
self.version = _read_field('version')
self.description = _read_field('summary')
self.author = _read_field('author')
self.maintainer = None
self.author_email = _read_field('author-email')
self.maintainer_email = None
self.url = _read_field('home-page')
self.license = _read_field('license')
self.platforms = _read_list('platform')
self.classifiers = _read_list('classifier')
यहाँ पूरी बात है:
class DistributionMetadata:
"""Dummy class to hold the distribution meta-data: name, version,
author, and so forth.
"""
_METHOD_BASENAMES = ("name", "version", "author", "author_email",
"maintainer", "maintainer_email", "url",
"license", "description", "long_description",
"keywords", "platforms", "fullname", "contact",
"contact_email", "classifiers", "download_url",
"provides", "requires", "obsoletes",
)
def __init__(self, path=None):
if path is not None:
self.read_pkg_file(open(path))
else:
self.name = None
self.version = None
self.author = None
self.author_email = None
self.maintainer = None
self.maintainer_email = None
self.url = None
self.license = None
self.description = None
self.long_description = None
self.keywords = None
self.platforms = None
self.classifiers = None
self.download_url = None
self.provides = None
self.requires = None
self.obsoletes = None
def read_pkg_file(self, file):
"""Reads the metadata values from a file object."""
msg = message_from_file(file)
def _read_field(name):
value = msg[name]
if value == 'UNKNOWN':
return None
return value
def _read_list(name):
values = msg.get_all(name, None)
if values == []:
return None
return values
metadata_version = msg['metadata-version']
self.name = _read_field('name')
self.version = _read_field('version')
self.description = _read_field('summary')
self.author = _read_field('author')
self.maintainer = None
self.author_email = _read_field('author-email')
self.maintainer_email = None
self.url = _read_field('home-page')
self.license = _read_field('license')
if 'download-url' in msg:
self.download_url = _read_field('download-url')
else:
self.download_url = None
self.long_description = _read_field('description')
self.description = _read_field('summary')
if 'keywords' in msg:
self.keywords = _read_field('keywords').split(',')
self.platforms = _read_list('platform')
self.classifiers = _read_list('classifier')
if metadata_version == '1.1':
self.requires = _read_list('requires')
self.provides = _read_list('provides')
self.obsoletes = _read_list('obsoletes')
else:
self.requires = None
self.provides = None
self.obsoletes = None