From cdb47008b609e30bb58a5cadf3de8a4a11eb4226 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sat, 30 Jul 2016 08:15:53 -0700 Subject: [PATCH 1/2] WIP: Add new long_description_content_type kwarg This is used to populate the newly proposed `Description-Content-Type` field, that is proposed in https://github.com/pypa/python-packaging-user-guide/pull/258. --- setup.py | 1 + setuptools/command/egg_info.py | 4 ++++ setuptools/dist.py | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/setup.py b/setup.py index 1b18ab9296..51670f1e9d 100755 --- a/setup.py +++ b/setup.py @@ -94,6 +94,7 @@ def pypi_link(pkg_filename): author="Python Packaging Authority", author_email="distutils-sig@python.org", long_description=long_description, + long_description_content_type='text/x-rst; charset=UTF-8', keywords="CPAN PyPI distutils eggs package management", url="https://github.com/pypa/setuptools", src_root=None, diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 5183eedc8e..b01620968a 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -397,6 +397,10 @@ def write_pkg_info(cmd, basename, filename): metadata = cmd.distribution.metadata metadata.version, oldver = cmd.egg_version, metadata.version metadata.name, oldname = cmd.egg_name, metadata.name + metadata.long_description_content_type = getattr( + cmd.distribution, + 'long_description_content_type' + ) try: # write unescaped data to PKG-INFO, so older pkg_resources # can still parse it diff --git a/setuptools/dist.py b/setuptools/dist.py index 820df6d5d6..78f6d1d82a 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -67,6 +67,13 @@ def write_pkg_file(self, file): 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) @@ -340,6 +347,9 @@ def __init__(self, attrs=None): self.dist_files = [] self.src_root = attrs and attrs.pop("src_root", None) self.patch_missing_pkg_info(attrs) + self.long_description_content_type = _attrs_dict.get( + 'long_description_content_type' + ) # Make sure we have any eggs needed to interpret 'attrs' if attrs is not None: self.dependency_links = attrs.pop('dependency_links', []) From ebcdac83af58a3d5ed7f262f0791001800f23cb4 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sun, 31 Jul 2016 15:17:12 -0700 Subject: [PATCH 2/2] Add test_long_description_content_type Test that specifying a `long_description_content_type` keyword arg to the `setup` function results in writing a `Description-Content-Type` line to the `PKG-INFO` file in the `.egg-info` directory. `Description-Content-Type` is described at https://github.com/pypa/python-packaging-user-guide/pull/258 --- setuptools/tests/test_egg_info.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index dff2a8c8ec..e37610e67d 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -210,6 +210,31 @@ def test_extra_requires_with_markers(self, tmpdir_cwd, env): self._run_install_command(tmpdir_cwd, env) assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == [] + def test_long_description_content_type(self, tmpdir_cwd, env): + # Test that specifying a `long_description_content_type` keyword arg to + # the `setup` function results in writing a `Description-Content-Type` + # line to the `PKG-INFO` file in the `.egg-info` + # directory. + # `Description-Content-Type` is described at + # https://github.com/pypa/python-packaging-user-guide/pull/258 + + self._setup_script_with_requires( + "long_description_content_type='text/markdown',") + environ = os.environ.copy().update( + HOME=env.paths['home'], + ) + code, data = environment.run_setup_py( + cmd=['egg_info'], + pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), + data_stream=1, + env=environ, + ) + egg_info_dir = os.path.join('.', 'foo.egg-info') + with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file: + pkg_info_lines = pkginfo_file.read().split('\n') + expected_line = 'Description-Content-Type: text/markdown' + assert expected_line in pkg_info_lines + def test_python_requires_egg_info(self, tmpdir_cwd, env): self._setup_script_with_requires( """python_requires='>=2.7.12',""")