-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from python-packaging/homepage-project-urls
Parse metadata fields from sdist artifacts
- Loading branch information
Showing
4 changed files
with
97 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
METADATA_CONTENTS = b"""\ | ||
Requires-Dist: foo | ||
Version: 1.2.58 | ||
Summary: Some Summary | ||
Home-page: http://example.com | ||
Author: Chicken | ||
Author-email: [email protected] | ||
Keywords: farm,animals | ||
Requires-Python: >=3.6 | ||
Description-Content-Type: text/markdown | ||
# Foo | ||
A very important package. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,15 @@ | |
) | ||
from ._tar import MemoryTarFile | ||
from ._zip import MemoryZipFile | ||
from .metadata_contents import METADATA_CONTENTS | ||
|
||
|
||
class ZipSdistTest(unittest.TestCase): | ||
def test_requires_as_expected(self) -> None: | ||
z = MemoryZipFile( | ||
{ | ||
"foo/__init__.py": b"", | ||
"foo.egg-info/PKG-INFO": b"\n", | ||
"foo.egg-info/requires.txt": b"""\ | ||
a | ||
[e] | ||
|
@@ -36,6 +38,7 @@ def test_basic_metadata(self) -> None: | |
z = MemoryZipFile( | ||
{ | ||
"foo/__init__.py": b"", | ||
"foo.egg-info/PKG-INFO": b"\n", | ||
"foo.egg-info/requires.txt": b"""\ | ||
a | ||
[e] | ||
|
@@ -68,6 +71,7 @@ def test_basic_metadata_absl_py_09(self) -> None: | |
z = MemoryZipFile( | ||
{ | ||
"foo/__init__.py": b"", | ||
"foo.egg-info/PKG-INFO": b"\n", | ||
"foo.egg-info/requires.txt": b"""\ | ||
six | ||
|
@@ -90,11 +94,32 @@ def test_basic_metadata_absl_py_09(self) -> None: | |
) | ||
self.assertEqual({"test"}, bm.provides_extra) | ||
|
||
def test_basic_metadata_fields(self) -> None: | ||
""" | ||
Modern setuptools will drop a PKG-INFO file in a sdist that is very similar to the METADATA file in a wheel. | ||
""" | ||
z = MemoryZipFile( | ||
{ | ||
"foo/__init__.py": b"", | ||
"PKG-INFO": METADATA_CONTENTS, | ||
} | ||
) | ||
bm = basic_metadata_from_zip_sdist(z) # type: ignore | ||
self.assertEqual(["foo"], bm.reqs) | ||
self.assertEqual("1.2.58", bm.version) | ||
self.assertEqual("Some Summary", bm.summary) | ||
self.assertEqual("http://example.com", bm.url) | ||
self.assertEqual("Chicken", bm.author) | ||
self.assertEqual("[email protected]", bm.author_email) | ||
self.assertEqual("farm,animals", bm.keywords) | ||
self.assertEqual("text/markdown", bm.long_description_content_type) | ||
self.assertEqual("# Foo\n\nA very important package.\n", bm.description) | ||
|
||
|
||
class TarSdistTest(unittest.TestCase): | ||
def test_requires_as_expected(self) -> None: | ||
t = MemoryTarFile( | ||
["foo.egg-info/requires.txt", "foo/__init__.py"], | ||
["foo.egg-info/PKG-INFO", "foo.egg-info/requires.txt", "foo/__init__.py"], | ||
read_value=b"""\ | ||
a | ||
[e] | ||
|
@@ -113,7 +138,7 @@ def test_requires_as_expected(self) -> None: | |
|
||
def test_basic_metadata(self) -> None: | ||
t = MemoryTarFile( | ||
["foo.egg-info/requires.txt", "foo/__init__.py"], | ||
["foo.egg-info/PKG-INFO", "foo.egg-info/requires.txt", "foo/__init__.py"], | ||
read_value=b"""\ | ||
a | ||
[e] | ||
|
@@ -126,3 +151,18 @@ def test_basic_metadata(self) -> None: | |
bm.reqs, | ||
) | ||
self.assertEqual({"e"}, bm.provides_extra) | ||
|
||
def test_metadata_fields_from_tar_sdist(self) -> None: | ||
t = MemoryTarFile( | ||
["PKG-INFO", "foo/__init__.py"], | ||
read_value=METADATA_CONTENTS, | ||
) | ||
bm = basic_metadata_from_tar_sdist(t) # type: ignore | ||
self.assertEqual("1.2.58", bm.version) | ||
self.assertEqual("Some Summary", bm.summary) | ||
self.assertEqual("http://example.com", bm.url) | ||
self.assertEqual("Chicken", bm.author) | ||
self.assertEqual("[email protected]", bm.author_email) | ||
self.assertEqual("farm,animals", bm.keywords) | ||
self.assertEqual("text/markdown", bm.long_description_content_type) | ||
self.assertEqual("# Foo\n\nA very important package.\n", bm.description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
from ..wheel import basic_metadata_from_wheel, from_wheel, InvalidWheel | ||
from ._zip import MemoryZipFile | ||
from .metadata_contents import METADATA_CONTENTS | ||
|
||
|
||
class WheelTest(unittest.TestCase): | ||
|
@@ -58,7 +59,7 @@ def test_basic_metadata(self) -> None: | |
def test_basic_metadata_more_fields(self) -> None: | ||
z = MemoryZipFile( | ||
{ | ||
"foo.dist-info/METADATA": b"Requires-Dist: foo\nVersion: 1.2.58\nSummary: Some Summary\nHome-page: http://example.com\nAuthor: Chicken\nAuthor-email: [email protected]\nKeywords: farm,animals\nRequires-Python: >=3.6\nDescription-Content-Type: text/markdown", | ||
"foo.dist-info/METADATA": METADATA_CONTENTS, | ||
"foo/__init__.py": b"", | ||
} | ||
) | ||
|
@@ -71,4 +72,4 @@ def test_basic_metadata_more_fields(self) -> None: | |
self.assertEqual("[email protected]", bm.author_email) | ||
self.assertEqual("farm,animals", bm.keywords) | ||
self.assertEqual("text/markdown", bm.long_description_content_type) | ||
self.assertEqual(None, bm.description) | ||
self.assertEqual("# Foo\n\nA very important package.\n", bm.description) |