Esempio n. 1
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = "1.0"
        if self.provides or self.requires or self.obsoletes or self.classifiers or self.download_url:
            version = "1.1"

        file.write("Metadata-Version: %s\n" % version)
        file.write("Name: %s\n" % self.get_name())
        file.write("Version: %s\n" % self.get_version())
        file.write("Summary: %s\n" % self.get_description())
        file.write("Home-page: %s\n" % self.get_url())
        file.write("Author: %s\n" % self.get_contact())
        file.write("Author-email: %s\n" % self.get_contact_email())
        file.write("License: %s\n" % self.get_license())
        if self.download_url:
            file.write("Download-URL: %s\n" % self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        file.write("Description: %s\n" % long_desc)

        keywords = ",".join(self.get_keywords())
        if keywords:
            file.write("Keywords: %s\n" % keywords)

        self._write_list(file, "Platform", self.get_platforms())
        self._write_list(file, "Classifier", self.get_classifiers())

        # PEP 314
        self._write_list(file, "Requires", self.get_requires())
        self._write_list(file, "Provides", self.get_provides())
        self._write_list(file, "Obsoletes", self.get_obsoletes())
Esempio n. 2
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = '1.0'
        if self.provides or self.requires or self.obsoletes:
            version = '1.1'

        self._write_field(file, 'Metadata-Version', version)
        self._write_field(file, 'Name', self.get_name())
        self._write_field(file, 'Version', self.get_version())
        self._write_field(file, 'Summary', self.get_description())
        self._write_field(file, 'Home-page', self.get_url())
        self._write_field(file, 'Author', self.get_contact())
        self._write_field(file, 'Author-email', self.get_contact_email())
        self._write_field(file, 'License', self.get_license())
        if self.download_url:
            self._write_field(file, 'Download-URL', self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        self._write_field(file, 'Description', long_desc)

        keywords = ','.join(self.get_keywords())
        if keywords:
            self._write_field(file, 'Keywords', keywords)

        self._write_list(file, 'Platform', self.get_platforms())
        self._write_list(file, 'Classifier', self.get_classifiers())

        # PEP 314
        self._write_list(file, 'Requires', self.get_requires())
        self._write_list(file, 'Provides', self.get_provides())
        self._write_list(file, 'Obsoletes', self.get_obsoletes())
Esempio n. 3
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = '1.0'
        if self.provides or self.requires or self.obsoletes:
            version = '1.1'

        self._write_field(file, 'Metadata-Version', version)
        self._write_field(file, 'Name', self.get_name())
        self._write_field(file, 'Version', self.get_version())
        self._write_field(file, 'Summary', self.get_description())
        self._write_field(file, 'Home-page', self.get_url())
        self._write_field(file, 'Author', self.get_contact())
        self._write_field(file, 'Author-email', self.get_contact_email())
        self._write_field(file, 'License', self.get_license())
        if self.download_url:
            self._write_field(file, 'Download-URL', self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        self._write_field(file, 'Description', long_desc)

        keywords = ','.join(self.get_keywords())
        if keywords:
            self._write_field(file, 'Keywords', keywords)

        self._write_list(file, 'Platform', self.get_platforms())
        self._write_list(file, 'Classifier', self.get_classifiers())

        # PEP 314
        self._write_list(file, 'Requires', self.get_requires())
        self._write_list(file, 'Provides', self.get_provides())
        self._write_list(file, 'Obsoletes', self.get_obsoletes())
Esempio n. 4
0
def write_pkg_file(self, file):  # noqa: C901  # is too complex (14)  # FIXME
    """Write the PKG-INFO format data to a file object."""
    version = self.get_metadata_version()

    def write_field(key, value):
        file.write("%s: %s\n" % (key, value))

    write_field('Metadata-Version', str(version))
    write_field('Name', self.get_name())
    write_field('Version', self.get_version())
    write_field('Summary', single_line(self.get_description()))
    write_field('Home-page', self.get_url())

    optional_fields = (
        ('Author', 'author'),
        ('Author-email', 'author_email'),
        ('Maintainer', 'maintainer'),
        ('Maintainer-email', 'maintainer_email'),
    )

    for field, attr in optional_fields:
        attr_val = getattr(self, attr, None)
        if attr_val is not None:
            write_field(field, attr_val)

    license = rfc822_escape(self.get_license())
    write_field('License', license)
    if self.download_url:
        write_field('Download-URL', self.download_url)
    for project_url in self.project_urls.items():
        write_field('Project-URL', '%s, %s' % project_url)

    keywords = ','.join(self.get_keywords())
    if keywords:
        write_field('Keywords', keywords)

    for platform in self.get_platforms():
        write_field('Platform', platform)

    self._write_list(file, 'Classifier', self.get_classifiers())

    # PEP 314
    self._write_list(file, 'Requires', self.get_requires())
    self._write_list(file, 'Provides', self.get_provides())
    self._write_list(file, 'Obsoletes', self.get_obsoletes())

    # Setuptools specific for PEP 345
    if hasattr(self, 'python_requires'):
        write_field('Requires-Python', self.python_requires)

    # PEP 566
    if self.long_description_content_type:
        write_field('Description-Content-Type', self.long_description_content_type)
    if self.provides_extras:
        for extra in self.provides_extras:
            write_field('Provides-Extra', extra)

    self._write_list(file, 'License-File', self.license_files or [])

    file.write("\n%s\n\n" % self.get_long_description())
Esempio n. 5
0
    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_contact())
        pkg_info.write('Author-email: %s\n' % self.get_contact_email())
        pkg_info.write('License: %s\n' % self.get_license())

        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()
Esempio n. 6
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = '1.0'
        if (self.provides or self.requires or self.obsoletes or
            self.classifiers or self.download_url):
            version = '1.1'

        file.write('Metadata-Version: %s\n' % version)
        file.write('Name: %s\n' % self.get_name() )
        file.write('Version: %s\n' % self.get_version() )
        file.write('Summary: %s\n' % self.get_description() )
        file.write('Home-page: %s\n' % self.get_url() )
        file.write('Author: %s\n' % self.get_contact() )
        file.write('Author-email: %s\n' % self.get_contact_email() )
        file.write('License: %s\n' % self.get_license() )
        if self.download_url:
            file.write('Download-URL: %s\n' % self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        file.write('Description: %s\n' % long_desc)

        keywords = ','.join(self.get_keywords())
        if keywords:
            file.write('Keywords: %s\n' % keywords )

        self._write_list(file, 'Platform', self.get_platforms())
        self._write_list(file, 'Classifier', self.get_classifiers())

        # PEP 314
        self._write_list(file, 'Requires', self.get_requires())
        self._write_list(file, 'Provides', self.get_provides())
        self._write_list(file, 'Obsoletes', self.get_obsoletes())
Esempio n. 7
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = "1.0"
        if (self.provides or self.requires or self.obsoletes
                or self.classifiers or self.download_url):
            version = "1.1"

        file.write("Metadata-Version: %s\n" % version)
        file.write("Name: %s\n" % self.get_name())
        file.write("Version: %s\n" % self.get_version())
        file.write("Summary: %s\n" % self.get_description())
        file.write("Home-page: %s\n" % self.get_url())
        file.write("Author: %s\n" % self.get_contact())
        file.write("Author-email: %s\n" % self.get_contact_email())
        file.write("License: %s\n" % self.get_license())
        if self.download_url:
            file.write("Download-URL: %s\n" % self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        file.write("Description: %s\n" % long_desc)

        keywords = ",".join(self.get_keywords())
        if keywords:
            file.write("Keywords: %s\n" % keywords)

        self._write_list(file, "Platform", self.get_platforms())
        self._write_list(file, "Classifier", self.get_classifiers())

        # PEP 314
        self._write_list(file, "Requires", self.get_requires())
        self._write_list(file, "Provides", self.get_provides())
        self._write_list(file, "Obsoletes", self.get_obsoletes())
Esempio n. 8
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object."""
        version = '1.0'
        if (self.provides or self.requires or self.obsoletes
                or self.classifiers or self.download_url):
            version = '1.1'

        # required fields
        file.write('Metadata-Version: %s\n' % version)
        file.write('Name: %s\n' % self.get_name())
        file.write('Version: %s\n' % self.get_version())

        def maybe_write(header, val):
            if val:
                file.write(f"{header}: {val}\n")

        # optional fields
        maybe_write("Summary", self.get_description())
        maybe_write("Home-page", self.get_url())
        maybe_write("Author", self.get_contact())
        maybe_write("Author-email", self.get_contact_email())
        maybe_write("License", self.get_license())
        maybe_write("Download-URL", self.download_url)
        maybe_write("Description",
                    rfc822_escape(self.get_long_description() or ""))
        maybe_write("Keywords", ",".join(self.get_keywords()))

        self._write_list(file, 'Platform', self.get_platforms())
        self._write_list(file, 'Classifier', self.get_classifiers())

        # PEP 314
        self._write_list(file, 'Requires', self.get_requires())
        self._write_list(file, 'Provides', self.get_provides())
        self._write_list(file, 'Obsoletes', self.get_obsoletes())
Esempio n. 9
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = '1.0'
        if (self.provides or self.requires or self.obsoletes or
                self.classifiers or self.download_url):
            version = '1.1'

        file.write('Metadata-Version: %s\n' % version)
        file.write('Name: %s\n' % self.get_name())
        file.write('Version: %s\n' % self.get_version())
        file.write('Summary: %s\n' % self.get_description())
        file.write('Home-page: %s\n' % self.get_url())
        file.write('Author: %s\n' % self.get_contact())
        file.write('Author-email: %s\n' % self.get_contact_email())
        file.write('License: %s\n' % self.get_license())
        if self.download_url:
            file.write('Download-URL: %s\n' % self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        file.write('Description: %s\n' % long_desc)

        keywords = ','.join(self.get_keywords())
        if keywords:
            file.write('Keywords: %s\n' % keywords)

        self._write_list(file, 'Platform', self.get_platforms())
        self._write_list(file, 'Classifier', self.get_classifiers())

        # PEP 314
        self._write_list(file, 'Requires', self.get_requires())
        self._write_list(file, 'Provides', self.get_provides())
        self._write_list(file, 'Obsoletes', self.get_obsoletes())
Esempio n. 10
0
    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_contact() )
        pkg_info.write('Author-email: %s\n' % self.get_contact_email() )
        pkg_info.write('License: %s\n' % self.get_license() )
        if self.download_url:
            pkg_info.write('Download-URL: %s\n' % self.download_url)

        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 )

        for classifier in self.get_classifiers():
            pkg_info.write('Classifier: %s\n' % classifier )

        pkg_info.close()
Esempio n. 11
0
    def write_pkg_file(self, file):
        """Write the PKG-INFO format data to a file object.
        """
        version = "1.0"
        if self.provides or self.requires or self.obsoletes or self.classifiers or self.download_url:
            version = "1.1"

        self._write_field(file, "Metadata-Version", version)
        self._write_field(file, "Name", self.get_name())
        self._write_field(file, "Version", self.get_version())
        self._write_field(file, "Summary", self.get_description())
        self._write_field(file, "Home-page", self.get_url())
        self._write_field(file, "Author", self.get_contact())
        self._write_field(file, "Author-email", self.get_contact_email())
        self._write_field(file, "License", self.get_license())
        if self.download_url:
            self._write_field(file, "Download-URL", self.download_url)

        long_desc = rfc822_escape(self.get_long_description())
        self._write_field(file, "Description", long_desc)

        keywords = string.join(self.get_keywords(), ",")
        if keywords:
            self._write_field(file, "Keywords", keywords)

        self._write_list(file, "Platform", self.get_platforms())
        self._write_list(file, "Classifier", self.get_classifiers())

        # PEP 314
        self._write_list(file, "Requires", self.get_requires())
        self._write_list(file, "Provides", self.get_provides())
        self._write_list(file, "Obsoletes", self.get_obsoletes())
Esempio n. 12
0
 def test_rfc822_escape(self):
     header = 'I am a\npoor\nlonesome\nheader\n'
     res = rfc822_escape(header)
     wanted = 'I am a%(8s)spoor%(8s)slonesome%(8s)sheader%(8s)s' % {
         '8s': '\n' + 8 * ' '
     }
     self.assertEqual(res, wanted)
Esempio n. 13
0
def write_pkg_file(self, file):
    """Write the PKG-INFO format data to a file object.
    """
    version = '1.0'
    if (self.provides or self.requires or self.obsoletes or self.classifiers
            or self.download_url):
        version = '1.1'
    # Setuptools specific for PEP 345
    if hasattr(self, 'python_requires') or self.project_urls:
        version = '1.2'
    if self.long_description_content_type or self.provides_extras:
        version = '2.1'

    file.write('Metadata-Version: %s\n' % version)
    file.write('Name: %s\n' % self.get_name())
    file.write('Version: %s\n' % self.get_version())
    file.write('Summary: %s\n' % self.get_description())
    file.write('Home-page: %s\n' % self.get_url())
    file.write('Author: %s\n' % self.get_contact())
    file.write('Author-email: %s\n' % self.get_contact_email())
    file.write('License: %s\n' % self.get_license())
    if self.download_url:
        file.write('Download-URL: %s\n' % self.download_url)
    for project_url in self.project_urls.items():
        file.write('Project-URL: %s, %s\n' % project_url)

    long_desc = rfc822_escape(self.get_long_description())
    file.write('Description: %s\n' % long_desc)

    keywords = ','.join(self.get_keywords())
    if keywords:
        file.write('Keywords: %s\n' % keywords)

    self._write_list(file, 'Platform', self.get_platforms())
    self._write_list(file, 'Classifier', self.get_classifiers())

    # PEP 314
    self._write_list(file, 'Requires', self.get_requires())
    self._write_list(file, 'Provides', self.get_provides())
    self._write_list(file, 'Obsoletes', self.get_obsoletes())

    # Setuptools specific for PEP 345
    if hasattr(self, 'python_requires'):
        file.write('Requires-Python: %s\n' % self.python_requires)

    # PEP 566
    if self.long_description_content_type:
        file.write('Description-Content-Type: %s\n' %
                   self.long_description_content_type)
    if self.provides_extras:
        for extra in self.provides_extras:
            file.write('Provides-Extra: %s\n' % extra)
Esempio n. 14
0
def write_pkg_file(self, file):
    """Write the PKG-INFO format data to a file object.
    """
    version = '1.0'
    if (self.provides or self.requires or self.obsoletes or
            self.classifiers or self.download_url):
        version = '1.1'
    # Setuptools specific for PEP 345
    if hasattr(self, 'python_requires'):
        version = '1.2'

    file.write('Metadata-Version: %s\n' % version)
    file.write('Name: %s\n' % self.get_name())
    file.write('Version: %s\n' % self.get_version())
    file.write('Summary: %s\n' % self.get_description())
    file.write('Home-page: %s\n' % self.get_url())
    file.write('Author: %s\n' % self.get_contact())
    file.write('Author-email: %s\n' % self.get_contact_email())
    file.write('License: %s\n' % self.get_license())
    if self.download_url:
        file.write('Download-URL: %s\n' % self.download_url)

    long_desc_content_type = getattr(
        self,
        'long_description_content_type',
        None
    ) or 'UNKNOWN'
    file.write('Description-Content-Type: %s\n' % long_desc_content_type)

    long_desc = rfc822_escape(self.get_long_description())
    file.write('Description: %s\n' % long_desc)

    keywords = ','.join(self.get_keywords())
    if keywords:
        file.write('Keywords: %s\n' % keywords)

    self._write_list(file, 'Platform', self.get_platforms())
    self._write_list(file, 'Classifier', self.get_classifiers())

    # PEP 314
    self._write_list(file, 'Requires', self.get_requires())
    self._write_list(file, 'Provides', self.get_provides())
    self._write_list(file, 'Obsoletes', self.get_obsoletes())

    # Setuptools specific for PEP 345
    if hasattr(self, 'python_requires'):
        file.write('Requires-Python: %s\n' % self.python_requires)
Esempio n. 15
0
"""distutils.dist
Esempio n. 16
0
    def write_pkg_file(self, file):
        """
        Write the PKG-INFO format data to a file object.

        Supports metadata version 1.2 (PEP 345), 1.1 (PEP 314) and
        1.0 (PEP 241) in a lowest common denominator fashion.
        """
        # Use lowest possible version for metadata version
        if self.requires_python or self.requires_external:
            # PEP 345 fields
            version = '1.2'
        elif (self.download_url or self.classifiers or
              self.provides or self.requires or self.obsoletes):
            # PEP 314 fields
            version = '1.1'
        else:
            # PEP 241 fields
            version = '1.0'
        file.write('Metadata-Version: %s\n' % version)

        # PEP 241 (http://python.org/dev/peps/pep-0241.html) fields:
        #   Name
        #   Version
        #   Platform (multiple use)     [obsolete]
        #   Summary
        #   Description (optional)
        #   Keywords (comma-separated list, optional)
        #   Home-page (optional)
        #   Author (optional)
        #   Author-email
        #   License                     [obsolete]
        file.write('Name: %s\n' % self.get_name() )
        file.write('Version: %s\n' % self.get_version() )
        file.write('Summary: %s\n' % self.get_description() )
        file.write('Home-page: %s\n' % self.get_url() )
        file.write('Author: %s\n' % self.get_contact() )
        file.write('Author-email: %s\n' % self.get_contact_email() )

        if self.long_description:
            description = rfc822_escape(self.long_description)
            file.write('Description: %s\n' % description)

        if self.keywords:
            keywords = ','.join(self.keywords)
            file.write('Keywords: %s\n' % keywords)

        # Per PEP 314, only use License and Platform if they can't be
        # handled by an appropriate classifier. Or, in our case, aren't
        # being handled by a classifier entry.
        has_platform = has_license = False
        for classifier in self.get_classifiers():
            category = classifier.split('::', 1)[0]
            category = category.strip().title()
            if category == 'Operating System':
                has_platform = True
            elif category == 'License':
                has_license = True

        if self.license:
            if has_license:
                raise DistutilsSetupError("license keyword conflicts with"
                                          " classifiers list")
            file.write('License: %s\n' % self.license)

        if self.platforms:
            if has_platform:
                raise DistutilsSetupError("platforms keyword conflicts with"
                                          " classifiers list")
            for platform in self.platforms:
                file.write('Platform: %s\n' % platform)

        # PEP 314 (http://python.org/dev/peps/pep-0314.html) fields:
        #   Supported-Platform (multiple use) [binary dists only; unused]
        #   Download-URL
        #   Classifier (multiple use)
        #   Requires (multiple use)
        #   Provides (multiple use)
        #   Obsoletes (multiple use)
        if self.download_url:
            file.write('Download-URL: %s\n' % self.get_download_url())
        for value in self.get_classifiers():
            file.write('Classifier: %s\n' % value)
        for value in self.get_requires():
            file.write('Requires: %s\n' % value)
        for value in self.get_provides():
            file.write('Provides: %s\n' % value)
        for value in self.get_obsoletes():
            file.write('Obsoletes: %s\n' % value)

        # PEP 345 (http://python.org/dev/peps/pep-0345.html) fields:
        #   Requires-Python (comma separated list)
        #   Requires-External (multiple use)
        #   Copyright
        if self.requires_python:
            value = ','.join(self.get_requires_python())
            file.write('Requires-Python: %s\n' % value)
        for value in self.get_requires_external():
            file.write('Requires-External: %s\n' % value)
        if self.copyright:
            file.write('Copyright: %s\n' % self.copyright)
        return
Esempio n. 17
0
def write_pkg_file(self, file):
    """Write the PKG-INFO format data to a file object.
    """
    version = get_metadata_version(self)

    file.write("Metadata-Version: %s\n" % version)
    file.write("Name: %s\n" % self.get_name())
    file.write("Version: %s\n" % self.get_version())
    file.write("Summary: %s\n" % self.get_description())
    file.write("Home-page: %s\n" % self.get_url())

    if version < StrictVersion("1.2"):
        file.write("Author: %s\n" % self.get_contact())
        file.write("Author-email: %s\n" % self.get_contact_email())
    else:
        optional_fields = (
            ("Author", "author"),
            ("Author-email", "author_email"),
            ("Maintainer", "maintainer"),
            ("Maintainer-email", "maintainer_email"),
        )

        for field, attr in optional_fields:
            attr_val = getattr(self, attr)
            if six.PY2:
                attr_val = self._encode_field(attr_val)

            if attr_val is not None:
                file.write("%s: %s\n" % (field, attr_val))

    file.write("License: %s\n" % self.get_license())
    if self.download_url:
        file.write("Download-URL: %s\n" % self.download_url)
    for project_url in self.project_urls.items():
        file.write("Project-URL: %s, %s\n" % project_url)

    long_desc = rfc822_escape(self.get_long_description())
    file.write("Description: %s\n" % long_desc)

    keywords = ",".join(self.get_keywords())
    if keywords:
        file.write("Keywords: %s\n" % keywords)

    if version >= StrictVersion("1.2"):
        for platform in self.get_platforms():
            file.write("Platform: %s\n" % platform)
    else:
        self._write_list(file, "Platform", self.get_platforms())

    self._write_list(file, "Classifier", self.get_classifiers())

    # PEP 314
    self._write_list(file, "Requires", self.get_requires())
    self._write_list(file, "Provides", self.get_provides())
    self._write_list(file, "Obsoletes", self.get_obsoletes())

    # Setuptools specific for PEP 345
    if hasattr(self, "python_requires"):
        file.write("Requires-Python: %s\n" % self.python_requires)

    # PEP 566
    if self.long_description_content_type:
        file.write("Description-Content-Type: %s\n" %
                   self.long_description_content_type)
    if self.provides_extras:
        for extra in sorted(self.provides_extras):
            file.write("Provides-Extra: %s\n" % extra)
Esempio n. 18
0
 def test_rfc822_escape(self):
     header = 'I am a\npoor\nlonesome\nheader\n'
     res = rfc822_escape(header)
     wanted = ('I am a%(8s)spoor%(8s)slonesome%(8s)s'
               'header%(8s)s') % {'8s': '\n'+8*' '}
     self.assertEquals(res, wanted)
Esempio n. 19
0
 def test_rfc822_escape(self):
     header = "I am a\npoor\nlonesome\nheader\n"
     res = rfc822_escape(header)
     wanted = ("I am a%(8s)spoor%(8s)slonesome%(8s)s" "header%(8s)s") % {"8s": "\n" + 8 * " "}
     self.assertEqual(res, wanted)
Esempio n. 20
0
    def write_pkg_file(self, file):
        """
        Write the PKG-INFO format data to a file object.

        Supports metadata version 1.2 (PEP 345), 1.1 (PEP 314) and
        1.0 (PEP 241) in a lowest common denominator fashion.
        """
        # Use lowest possible version for metadata version
        if self.requires_python or self.requires_external:
            # PEP 345 fields
            version = '1.2'
        elif (self.download_url or self.classifiers or self.provides
              or self.requires or self.obsoletes):
            # PEP 314 fields
            version = '1.1'
        else:
            # PEP 241 fields
            version = '1.0'
        file.write('Metadata-Version: %s\n' % version)

        # PEP 241 (http://python.org/dev/peps/pep-0241.html) fields:
        #   Name
        #   Version
        #   Platform (multiple use)     [obsolete]
        #   Summary
        #   Description (optional)
        #   Keywords (comma-separated list, optional)
        #   Home-page (optional)
        #   Author (optional)
        #   Author-email
        #   License                     [obsolete]
        file.write('Name: %s\n' % self.get_name())
        file.write('Version: %s\n' % self.get_version())
        file.write('Summary: %s\n' % self.get_description())
        file.write('Home-page: %s\n' % self.get_url())
        file.write('Author: %s\n' % self.get_contact())
        file.write('Author-email: %s\n' % self.get_contact_email())

        if self.long_description:
            description = rfc822_escape(self.long_description)
            file.write('Description: %s\n' % description)

        if self.keywords:
            keywords = ','.join(self.keywords)
            file.write('Keywords: %s\n' % keywords)

        # Per PEP 314, only use License and Platform if they can't be
        # handled by an appropriate classifier. Or, in our case, aren't
        # being handled by a classifier entry.
        has_platform = has_license = False
        for classifier in self.get_classifiers():
            category = classifier.split('::', 1)[0]
            category = category.strip().title()
            if category == 'Operating System':
                has_platform = True
            elif category == 'License':
                has_license = True

        if self.license:
            if has_license:
                raise DistutilsSetupError("license keyword conflicts with"
                                          " classifiers list")
            file.write('License: %s\n' % self.license)

        if self.platforms:
            if has_platform:
                raise DistutilsSetupError("platforms keyword conflicts with"
                                          " classifiers list")
            for platform in self.platforms:
                file.write('Platform: %s\n' % platform)

        # PEP 314 (http://python.org/dev/peps/pep-0314.html) fields:
        #   Supported-Platform (multiple use) [binary dists only; unused]
        #   Download-URL
        #   Classifier (multiple use)
        #   Requires (multiple use)
        #   Provides (multiple use)
        #   Obsoletes (multiple use)
        if self.download_url:
            file.write('Download-URL: %s\n' % self.get_download_url())
        for value in self.get_classifiers():
            file.write('Classifier: %s\n' % value)
        for value in self.get_requires():
            file.write('Requires: %s\n' % value)
        for value in self.get_provides():
            file.write('Provides: %s\n' % value)
        for value in self.get_obsoletes():
            file.write('Obsoletes: %s\n' % value)

        # PEP 345 (http://python.org/dev/peps/pep-0345.html) fields:
        #   Requires-Python (comma separated list)
        #   Requires-External (multiple use)
        #   Copyright
        if self.requires_python:
            value = ','.join(self.get_requires_python())
            file.write('Requires-Python: %s\n' % value)
        for value in self.get_requires_external():
            file.write('Requires-External: %s\n' % value)
        if self.copyright:
            file.write('Copyright: %s\n' % self.copyright)
        return
Esempio n. 21
0
def write_pkg_file(self, file):
    """Write the PKG-INFO format data to a file object.
    """
    version = get_metadata_version(self)

    file.write('Metadata-Version: %s\n' % version)
    file.write('Name: %s\n' % self.get_name())
    file.write('Version: %s\n' % self.get_version())
    file.write('Summary: %s\n' % self.get_description())
    file.write('Home-page: %s\n' % self.get_url())

    if version < StrictVersion('1.2'):
        file.write('Author: %s\n' % self.get_contact())
        file.write('Author-email: %s\n' % self.get_contact_email())
    else:
        optional_fields = (
            ('Author', 'author'),
            ('Author-email', 'author_email'),
            ('Maintainer', 'maintainer'),
            ('Maintainer-email', 'maintainer_email'),
        )

        for field, attr in optional_fields:
            attr_val = getattr(self, attr)
            if six.PY2:
                attr_val = self._encode_field(attr_val)

            if attr_val is not None:
                file.write('%s: %s\n' % (field, attr_val))

    file.write('License: %s\n' % self.get_license())
    if self.download_url:
        file.write('Download-URL: %s\n' % self.download_url)
    for project_url in self.project_urls.items():
        file.write('Project-URL: %s, %s\n' % project_url)

    long_desc = rfc822_escape(self.get_long_description())
    file.write('Description: %s\n' % long_desc)

    keywords = ','.join(self.get_keywords())
    if keywords:
        file.write('Keywords: %s\n' % keywords)

    if version >= StrictVersion('1.2'):
        for platform in self.get_platforms():
            file.write('Platform: %s\n' % platform)
    else:
        self._write_list(file, 'Platform', self.get_platforms())

    self._write_list(file, 'Classifier', self.get_classifiers())

    # PEP 314
    self._write_list(file, 'Requires', self.get_requires())
    self._write_list(file, 'Provides', self.get_provides())
    self._write_list(file, 'Obsoletes', self.get_obsoletes())

    # Setuptools specific for PEP 345
    if hasattr(self, 'python_requires'):
        file.write('Requires-Python: %s\n' % self.python_requires)

    # PEP 566
    if self.long_description_content_type:
        file.write(
            'Description-Content-Type: %s\n' %
            self.long_description_content_type
        )
    if self.provides_extras:
        for extra in self.provides_extras:
            file.write('Provides-Extra: %s\n' % extra)
    for project_url in self.project_urls.items():
        file.write('Project-URL: %s, %s\n' % project_url)

    long_desc_content_type = \
        self.long_description_content_type or 'UNKNOWN'
=======

    long_desc_content_type = getattr(
        self,
        'long_description_content_type',
        None
    ) or 'UNKNOWN'
>>>>>>> 78fd1182ea3d7aa4d4e2e74025f0d9df075fc991
    file.write('Description-Content-Type: %s\n' % long_desc_content_type)

    long_desc = rfc822_escape(self.get_long_description())
    file.write('Description: %s\n' % long_desc)

    keywords = ','.join(self.get_keywords())
    if keywords:
        file.write('Keywords: %s\n' % keywords)

    self._write_list(file, 'Platform', self.get_platforms())
    self._write_list(file, 'Classifier', self.get_classifiers())

    # PEP 314
    self._write_list(file, 'Requires', self.get_requires())
    self._write_list(file, 'Provides', self.get_provides())
    self._write_list(file, 'Obsoletes', self.get_obsoletes())

    # Setuptools specific for PEP 345