Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metadata 2.1 #319

Merged
merged 5 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Jens Diemer <github@jensdiemer.de> (http://jensdiemer.de/)
Andrew Watts <andrewwatts@gmail.com>
Anna Martelli Ravenscroft <annaraven@gmail.com>
Sumana Harihareswara <sh@changeset.nyc>
Dustin Ingram <di@di.codes> (https://di.codes)
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Changelog
=========

* :feature:`319` Support Metadata 2.1 (`PEP 566
<https://www.python.org/dev/peps/pep-0566/>`_).
* :support:`318` `Update PyPI URLs
<https://packaging.python.org/guides/migrating-to-pypi-org/>`_.
* :release:`1.10.0 <2018-03-07>`
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires-dist =
tqdm >= 4.14
requests >= 2.5.0, != 2.15, != 2.16
requests-toolbelt >= 0.8.0
pkginfo >= 1.0
pkginfo >= 1.4.2
setuptools >= 0.7.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here as with setup.py about setuptools versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer as above.

argparse; python_version == '2.6'
pyblake2; extra == 'with-blake2' and python_version < '3.6'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

install_requires = [
"tqdm >= 4.14",
"pkginfo >= 1.0",
"pkginfo >= 1.4.2",
"requests >= 2.5.0, != 2.15, != 2.16",
"requests-toolbelt >= 0.8.0",
"setuptools >= 0.7.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to increase our required setuptools version to something like setuptools > v38.5.2 (the current version as far as I can tell) to ensure we capture the update in pypa/setuptools#1286 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or rather, even if we don't need to since the new additional metadata is optional, should we take this opportunity to do some kind of required version increase regardless?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason we have setuptools listed in the requirements is so that we can reliably get it's version when running twine --version.

Users with older versions of setuptools will still be able to upload their distributions with twine, they just won't be able to create distributions with Metadata 2.1 fields. If they want to do that, they should upgrade their setuptools (it's not twine's responsibility to make that decision for them).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally understand. Thanks. So, if we choose to do any user-facing messaging about this feature &, for instance, Markdown support, we should indicate that such-and-such setuptools is a requirement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

Expand Down
93 changes: 93 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from twine import package

import pretend
import pytest


def test_sign_file(monkeypatch):
Expand Down Expand Up @@ -70,3 +71,95 @@ def test_package_signed_name_is_correct():

assert pkg.signed_basefilename == "deprecated-pypirc.asc"
assert pkg.signed_filename == (filename + '.asc')


@pytest.mark.parametrize('gpg_signature', [
(None),
(pretend.stub()),
])
def test_metadata_dictionary(gpg_signature):
meta = pretend.stub(
name='whatever',
version=pretend.stub(),
metadata_version=pretend.stub(),
summary=pretend.stub(),
home_page=pretend.stub(),
author=pretend.stub(),
author_email=pretend.stub(),
maintainer=pretend.stub(),
maintainer_email=pretend.stub(),
license=pretend.stub(),
description=pretend.stub(),
keywords=pretend.stub(),
platforms=pretend.stub(),
classifiers=pretend.stub(),
download_url=pretend.stub(),
supported_platforms=pretend.stub(),
provides=pretend.stub(),
requires=pretend.stub(),
obsoletes=pretend.stub(),
project_urls=pretend.stub(),
provides_dist=pretend.stub(),
obsoletes_dist=pretend.stub(),
requires_dist=pretend.stub(),
requires_external=pretend.stub(),
requires_python=pretend.stub(),
provides_extras=pretend.stub(),
description_content_type=pretend.stub(),
)

pkg = package.PackageFile(
filename='tests/fixtures/twine-1.5.0-py2.py3-none-any.whl',
comment=pretend.stub(),
metadata=meta,
python_version=pretend.stub(),
filetype=pretend.stub(),
)
pkg.gpg_signature = gpg_signature

result = pkg.metadata_dictionary()

# identify release
assert result['name'] == pkg.safe_name
assert result['version'] == meta.version

# file content
assert result['filetype'] == pkg.filetype
assert result['pyversion'] == pkg.python_version

# additional meta-data
assert result['metadata_version'] == meta.metadata_version
assert result['summary'] == meta.summary
assert result['home_page'] == meta.home_page
assert result['author'] == meta.author
assert result['author_email'] == meta.author_email
assert result['maintainer'] == meta.maintainer
assert result['maintainer_email'] == meta.maintainer_email
assert result['license'] == meta.license
assert result['description'] == meta.description
assert result['keywords'] == meta.keywords
assert result['platform'] == meta.platforms
assert result['classifiers'] == meta.classifiers
assert result['download_url'] == meta.download_url
assert result['supported_platform'] == meta.supported_platforms
assert result['comment'] == pkg.comment

# PEP 314
assert result['provides'] == meta.provides
assert result['requires'] == meta.requires
assert result['obsoletes'] == meta.obsoletes

# Metadata 1.2
assert result['project_urls'] == meta.project_urls
assert result['provides_dist'] == meta.provides_dist
assert result['obsoletes_dist'] == meta.obsoletes_dist
assert result['requires_dist'] == meta.requires_dist
assert result['requires_external'] == meta.requires_external
assert result['requires_python'] == meta.requires_python

# Metadata 2.1
assert result['provides_extras'] == meta.provides_extras
assert result['description_content_type'] == meta.description_content_type

# GPG signature
assert result.get('gpg_signature') == gpg_signature
4 changes: 4 additions & 0 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def metadata_dictionary(self):
"requires_dist": meta.requires_dist,
"requires_external": meta.requires_external,
"requires_python": meta.requires_python,

# Metadata 2.1
"provides_extras": meta.provides_extras,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right to me per the names for these attributes as provided by the class from pkginfo.

Let me make sure I've got this right: even though the field defined in the PEP is Provides-Extra, we use the "s" at the end to indicate that it might be multiple strings, as with project_urls. Right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that seems to be the status quo (really, to indicate that this is a list).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks.

"description_content_type": meta.description_content_type,
}

if self.gpg_signature is not None:
Expand Down