Skip to content

Commit 8800b8c

Browse files
committed
Tests for setup.cfg.
1 parent 1d4750e commit 8800b8c

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

metadata_please/source_checkout.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,41 @@ def from_poetry_checkout(path: Path) -> bytes:
247247
if name:
248248
buf.append(f"Name: {name}\n")
249249

250+
# Version
251+
version = doc.get("tool", {}).get("poetry", {}).get("version")
252+
if version:
253+
buf.append(f"Version: {version}\n")
254+
255+
# Requires-Python
256+
requires_python = doc.get("tool", {}).get("poetry", {}).get("requires-python")
257+
if requires_python:
258+
buf.append(f"Requires-Python: {requires_python}\n")
259+
260+
# Project-URL
261+
url = doc.get("tool", {}).get("poetry", {}).get("homepage")
262+
if url:
263+
buf.append(f"Home-Page: {url}\n")
264+
265+
# Author
266+
authors = doc.get("tool", {}).get("poetry", {}).get("authors")
267+
if authors:
268+
buf.append(f"Author: {authors}\n")
269+
270+
# Summary
271+
summary = doc.get("tool", {}).get("poetry", {}).get("description")
272+
if summary:
273+
buf.append(f"Summary: {summary}\n")
274+
275+
# Description
276+
description = doc.get("tool", {}).get("poetry", {}).get("readme")
277+
if description:
278+
buf.append(f"Description: {description}\n")
279+
280+
# Keywords
281+
keywords = doc.get("tool", {}).get("poetry", {}).get("keywords")
282+
if keywords:
283+
buf.append(f"Keywords: {keywords}\n")
284+
250285
return "".join(buf).encode("utf-8")
251286

252287

@@ -265,6 +300,50 @@ def from_setup_cfg_checkout(path: Path) -> bytes:
265300
except (NoOptionError, NoSectionError):
266301
pass
267302

303+
# Requires-Python
304+
try:
305+
buf.append(f"Requires-Python: {rc.get('options', 'python_requires')}\n")
306+
except (NoOptionError, NoSectionError):
307+
pass
308+
309+
# Home-Page
310+
try:
311+
buf.append(f"Home-Page: {rc.get('metadata', 'url')}\n")
312+
except (NoOptionError, NoSectionError):
313+
pass
314+
315+
# Author
316+
try:
317+
buf.append(f"Author: {rc.get('metadata', 'author')}\n")
318+
except (NoOptionError, NoSectionError):
319+
pass
320+
321+
# Author-Email
322+
try:
323+
buf.append(f"Author-Email: {rc.get('metadata', 'author_email')}\n")
324+
except (NoOptionError, NoSectionError):
325+
pass
326+
327+
# Summary
328+
try:
329+
buf.append(f"Summary: {rc.get('metadata', 'description')}\n")
330+
except (NoOptionError, NoSectionError):
331+
pass
332+
333+
# Description
334+
try:
335+
buf.append(f"Description: {rc.get('metadata', 'long_description')}\n")
336+
except (NoOptionError, NoSectionError):
337+
pass
338+
339+
# Description-Content-Type
340+
try:
341+
buf.append(
342+
f"Description-Content-Type: {rc.get('metadata', 'long_description_content_type')}\n"
343+
)
344+
except (NoOptionError, NoSectionError):
345+
pass
346+
268347
try:
269348
for dep in rc.get("options", "install_requires").splitlines():
270349
dep = dep.strip()

metadata_please/tests/source_checkout.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_pep621_fields(self) -> None:
4242
self.assertEqual("['farm', 'animals']", rv.keywords)
4343
self.assertEqual(None, rv.long_description_content_type)
4444
self.assertEqual("README.md", rv.description)
45+
self.assertEqual(">=3.7", rv.requires_python)
4546

4647
def test_pep621_extras(self) -> None:
4748
with tempfile.TemporaryDirectory() as d:
@@ -68,6 +69,32 @@ def test_pep621_extras(self) -> None:
6869
)
6970
self.assertEqual(frozenset({"dev", "marker"}), rv.provides_extra)
7071

72+
def test_poetry_fields(self) -> None:
73+
with tempfile.TemporaryDirectory() as d:
74+
Path(d, "pyproject.toml").write_text(
75+
"""\
76+
[tool.poetry]
77+
name = "somepkg"
78+
version = "1.2.30"
79+
description = "Example Summary"
80+
authors = ["chicken <[email protected]>"]
81+
readme = "README.md"
82+
keywords = ["farm", "animals"]
83+
homepage = "https://example.com"
84+
"""
85+
)
86+
rv = basic_metadata_from_source_checkout(Path(d))
87+
self.assertEqual("somepkg", rv.name)
88+
self.assertEqual("1.2.30", rv.version)
89+
self.assertEqual("Example Summary", rv.summary)
90+
self.assertEqual("https://example.com", rv.url)
91+
self.assertEqual({}, rv.project_urls)
92+
self.assertEqual("['chicken <[email protected]>']", rv.author)
93+
self.assertEqual("['farm', 'animals']", rv.keywords)
94+
self.assertEqual(None, rv.long_description_content_type)
95+
self.assertEqual("README.md", rv.description)
96+
self.assertEqual(None, rv.requires_python)
97+
7198
def test_poetry_full(self) -> None:
7299
with tempfile.TemporaryDirectory() as d:
73100
Path(d, "pyproject.toml").write_text(
@@ -190,3 +217,33 @@ def test_setuptools_extras(self) -> None:
190217
frozenset({"dev", "marker"}),
191218
rv.provides_extra,
192219
)
220+
221+
def test_setuptools_cfg_fields(self) -> None:
222+
with tempfile.TemporaryDirectory() as d:
223+
Path(d, "setup.cfg").write_text(
224+
"""\
225+
[metadata]
226+
name = somepkg
227+
description = Example Summary
228+
long_description = file: README.md
229+
long_description_content_type = text/markdown
230+
license = MIT
231+
url = https://example.com
232+
author = chicken
233+
author_email = [email protected]
234+
235+
[options]
236+
python_requires = >=3.7
237+
"""
238+
)
239+
rv = basic_metadata_from_source_checkout(Path(d))
240+
self.assertEqual("somepkg", rv.name)
241+
self.assertEqual(None, rv.version)
242+
self.assertEqual("Example Summary", rv.summary)
243+
self.assertEqual("https://example.com", rv.url)
244+
self.assertEqual("chicken", rv.author)
245+
self.assertEqual("[email protected]", rv.author_email)
246+
self.assertEqual(None, rv.keywords)
247+
self.assertEqual("file: README.md", rv.description)
248+
self.assertEqual(">=3.7", rv.requires_python)
249+
self.assertEqual("text/markdown", rv.long_description_content_type)

0 commit comments

Comments
 (0)